Skip to main content

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

ParameterTypeRequiredDescription
userKeyStringYesThe key or ID of the user who loses the role.
roleKeyStringYesThe key or ID of the role to remove.
tenantKeyStringYesThe 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.

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. 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.
PermitContextErrorThe SDK context does not include an environment, for example because the API key is scoped to an organization or project.