Unassign a role from a user with the Java SDK
permit.api.users.unassignRole() removes a role that a user has in one tenant. Role assignments of the same user in other tenants stay in place. This reference is for Java developers who manage role-based access control (RBAC) assignments from code. The examples assume an initialized Permit client named permit, as set up in Check permissions with the Java SDK.
Signature
void unassignRole(String userKey, String roleKey, String tenantKey) throws IOException, PermitApiError, PermitContextError
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userKey | String | Yes | The key or ID of the user who loses the role. |
roleKey | String | Yes | The key or ID of the role to remove. |
tenantKey | String | Yes | The key or ID of the tenant in which the role is assigned. |
Example
The example removes the admin role from a user in a tenant. The parameters are positional: user, role, then tenant.
permit.api.users.unassignRole("john@permit.io", "admin", "acme-corp");
Return value
unassignRole() returns nothing (void).
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. If the user does not have the role in the tenant, the API returns HTTP status 404. 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. |