Skip to main content

Update a resource with the Java SDK

permit.api.resources.update() changes the fields you set on an existing resource type in your Permit environment and leaves the other fields unchanged. This reference is for Java developers who manage their authorization schema from code. The examples assume an initialized Permit client named permit, as set up in Check permissions with the Java SDK.

Signature

ResourceRead update(String resourceKey, ResourceUpdate resourceData) throws IOException, PermitApiError, PermitContextError

Parameters

ParameterTypeRequiredDescription
resourceKeyStringYesThe key or the ID (UUID) of the resource. The Permit API accepts either value.
resourceDataResourceUpdateYesThe fields to change. The fields are listed in ResourceUpdate fields.

ResourceUpdate fields

Create a ResourceUpdate with the no-argument constructor and set only the fields you want to change. Every field is optional. The SDK sends the update as an HTTP PATCH request.

FieldBuilder methodTypeDescription
namewithName()StringThe display name of the resource.
urnwithUrn()StringThe URN (Uniform Resource Name) of the resource.
descriptionwithDescription()StringA longer description of what the resource represents in your system.
actionswithActions()HashMap<String, ActionBlockEditable>The actions a user can perform on the resource, keyed by action key.
attributeswithAttributes()HashMap<String, AttributeBlockEditable>Attributes that each resource of this type defines, for use in attribute-based access control (ABAC) policies.
roleswithRoles()HashMap<String, RoleBlockEditable>Resource roles, keyed by role key.
relationswithRelations()HashMap<String, String>Relations to other resources, keyed by relation key.

Example

The example changes the description of the document resource.

import io.permit.sdk.openapi.models.ResourceUpdate;

permit.api.resources.update("document", new ResourceUpdate().withDescription("new description"));

Return value

update() returns a ResourceRead object (io.permit.sdk.openapi.models.ResourceRead) with the updated resource.

Exceptions

All exception classes except IOException are in the io.permit.sdk.api package.

ExceptionThrown when
IOExceptionThe HTTP request to the Permit API fails, for example because of a network error.
PermitApiErrorThe Permit API returns an error status code. getResponseCode() returns the HTTP status code and getRawResponse() returns the response body.
PermitContextErrorThe SDK context does not include an environment, for example because the API key is scoped to an organization or project.