Skip to main content
Version: 1.0.0

syncResources

To enforce permissions, you must first create resources and define actions that can be performed on those resources.

Then, you can create roles and assign them permissions for every resource/action combination. These roles can then be assigned to users.

For example: You can have the resource document and the action create for it. We can give permission to an editor role to create a document, and we can assign the editor role to a user named Bob.

This function helps you sync your resources and actions with Permit:

string resourceType = "document";
string actionName = "create";
// define the action title and description (can be empty)
ActionSpec actionSpec = new ActionSpec.Builder()
.withTitle("Create a document")
.withDescription("Ability to create document")
.build();
// define the action
HashMap<String, ActionSpec> resourceActions = new HashMap<String, ActionSpec>(actionName, actionSpec);
// define the resource with its actions
ArrayList<ResourceSpec> resourcesToSync = { new ResourceSpec(resourceType, resourceActions) };
// sync the resources to Permit
ResourceList syncedResources = permit.api.syncResources(resourcesToSync);

// SyncResources returns ResourceList type
// {
// "url": string,
// "data": [
// {
// "type": string,
// "description": string,
// "attributes": { },
// "name": string,
// "path": string,
// "id": string,
// "actions": [],
// "isBuiltIn": false
// }
// ]
// }