Skip to main content
Version: 2.0.0

Check in All Tenants

To validate permissions irrespective of the tenant, you can use the permit.AllTenantsCheck function. This function determines if a user has permissions for a specified action on a resource across all tenants, the response will be a list of tenants in which the user is allowed to perform the request.

Simple Usage

The permit.AllTenantsCheck function accepts an individual check requests as input. The tenant key isn't required and will be ignored if provided:

import io.permit.sdk.Permit;
import io.permit.sdk.PermitConfig;
import io.permit.sdk.enforcement.*;
import java.util.Arrays;


Permit permit = new Permit(
new PermitConfig.Builder("[YOUR_API_KEY]").build()
);

List<TenantDetails> allowedTenants = permit.checkInAllTenants(
User.fromString("john@doe.com"),
"read",
new Resource.Builder("document").build()
);

The result will be an array containing the details about the request for each allowed tenant, including the allowed tenant's attributes.

Enforce with attributes

import io.permit.sdk.Permit;
import io.permit.sdk.PermitConfig;
import io.permit.sdk.enforcement.*;
import java.util.Arrays;


Permit permit = new Permit(
new PermitConfig.Builder("[YOUR_API_KEY]").build()
);

HashMap<String,Object> resourceAttrs = new HashMap<String,Object>();
resourceAttrs.put("colors", new ArrayList<String>(Arrays.asList("red","blue")));

List<TenantDetails> allowedTenants = permit.checkInAllTenants(
User.fromString("john@doe.com"),
"read",
new Resource.Builder("document").withAttributes(resourceAttrs).build()
);
note

Currently, using relationship-based access control (ReBAC) doesn't work for the "All Tenants Check". This is because ReBAC checks are done on a specific resource that is tied to only one tenant at a time.

If the check isn't allowed for that tenant, the result will be an empty list. If it is allowed, you'll get a list with one item. To avoid this and make things run more smoothly, it's better to stick with a simpler check method.

danger

Please note that the "All Tenants Check" feature might not work correctly if you're using PDP Sharding. This is because it only runs on one PDP instance at a time, and that instance only contains data for a few tenants, not all of them in the setup.