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
| Parameter | Type | Required | Description |
|---|---|---|---|
resourceKey | String | Yes | The key or the ID (UUID) of the resource. The Permit API accepts either value. |
resourceData | ResourceUpdate | Yes | The 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.
| Field | Builder method | Type | Description |
|---|---|---|---|
name | withName() | String | The display name of the resource. |
urn | withUrn() | String | The URN (Uniform Resource Name) of the resource. |
description | withDescription() | String | A longer description of what the resource represents in your system. |
actions | withActions() | HashMap<String, ActionBlockEditable> | The actions a user can perform on the resource, keyed by action key. |
attributes | withAttributes() | HashMap<String, AttributeBlockEditable> | Attributes that each resource of this type defines, for use in attribute-based access control (ABAC) policies. |
roles | withRoles() | HashMap<String, RoleBlockEditable> | Resource roles, keyed by role key. |
relations | withRelations() | 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.
| Exception | Thrown when |
|---|---|
IOException | The HTTP request to the Permit API fails, for example because of a network error. |
PermitApiError | The Permit API returns an error status code. getResponseCode() returns the HTTP status code and getRawResponse() returns the response body. |
PermitContextError | The SDK context does not include an environment, for example because the API key is scoped to an organization or project. |