# Manage Strategy

The core of Authing's access control and permission management model is designed around two points: Resource and Policy. A policy defines a certain operation authority(s) for a certain resource (class). By authorizing the policy to a user (or role), you can know whether the user (or role) has operation authority for a certain operation of a resource .

# Add strategy

PoliciesManagementClient().create(code, policy statement, detailed format and description, please see, description)

Add strategy

# Parameters

  • code <string> strategy unique mark
  • Policy statement, detailed format and description, please refer to<PolicyStatement[]> https://docs.authing.co/docs/access-control/index.html
  • description <string> description

# Example

ArrayList<PolicyStatementInput> statements = new ArrayList<>();
ArrayList<String> actions = new ArrayList<>();
actions.add("book:edit");
statements.add(new PolicyStatementInput("book:123", actions));
Policy policy = managementClient.policies().create("code", statements).execute();

# Delete strategy

PoliciesManagementClient().delete(code)

Delete strategy, the system built-in strategy is officially maintained by Authing and cannot be modified or deleted.

# Parameters

  • code <string> strategy unique mark

# Example

CommonMessage message = managementClient.policies().delete("PolicyCode").execute();

# Batch delete strategy

PoliciesManagementClient().deleteMany(codeList)

Batch delete policies. The built-in policies of the system are officially maintained by Authing and cannot be modified or deleted.

# Parameters

  • codeList <string> strategy unique flag list

# Example

ArrayList<String> list = new ArrayList<>();
list.add("PolicyCode");
CommonMessage result = managementClient.policies().deleteMany(list).execute();

# Modify strategy

PoliciesManagementClient().update(code, updates)

Modify the strategy. The built-in strategy of the system is officially maintained by Authing and cannot be modified or deleted.

# Parameters

  • code <string> strategy unique mark
  • updates <Object>
  • updates.description <string> description
  • updates.statements <PolicyStatement[]> policy statement, please refer to https://docs.authing.co/docs/access-control/index.html for detailed format and description
  • updates.newCode <string> The new unique flag. If it is passed in, it must be guaranteed to be unique in the user pool.

# Example

ArrayList<PolicyStatementInput> newStatements = new ArrayList<>();
ArrayList<String> newActions = new ArrayList<>();
newActions.add("book:edit");
newStatements.add(new PolicyStatementInput("book:123", newActions));
Policy policy = managementClient.policies().update(code, newStatements, "desc").execute();

# Get policy details

PoliciesManagementClient().detail(code)

Get policy details

# Parameters

  • code <string> strategy unique mark

const policy = await managementClient.policies.detail('CODE');

# Example

Policy policy = managementClient.policies().detail("PolicyCode").execute();

# Get a list of strategies

PoliciesManagementClient().list(options)

Get a list of strategies

# Parameters

  • options <Object>
  • options.page <number> The default value is: 1.
  • options.limit <number> The default value is: 10.
  • options.excludeDefault <boolean> Whether to exclude system default resources or not. The default value is true.

# Example

PaginatedPolicies roles = managementClient.policies().list().execute();

# Get policy authorization record

PoliciesManagementClient().listAssignments(code, page, limit)

Obtain policy authorization records

# Parameters

  • code <string> strategy unique mark
  • page <number> The default value is: 1.
  • limit <number> The default value is 10.

# Example

PaginatedPolicyAssignments policyAssignments = managementClient.policies().listAssignments("code").execute();

# Add policy authorization

PoliciesManagementClient().addAssignments(policies, targetType, targetIdentifiers)

Add policy authorization, the policy can be authorized to users and roles, and the policy authorized to the role will be inherited by all users under the role. This interface can perform batch operations.

# Parameters

  • policies <string[]> policy code list
  • targetType <PolicyAssignmentTargetType> Optional values ​​are USER (user) and ROLE (role)
  • targetIdentifiers <string[]> user id list and role code list

# Example

ArrayList<String> policies = new ArrayList<>();
policies.add("policy code");

ArrayList<String> targetIdentifiers = new ArrayList<>();
targetIdentifiers.add("userId");

managementClient.policies().addAssignments(policies, PolicyAssignmentTargetType.USER, targetIdentifiers).execute();

# Revoke policy authorization

PoliciesManagementClient().removeAssignments(policies, targetType, targetIdentifiers)

Revocation of policy authorization, this interface can be used for batch operations.

# Parameters

  • policies <string[]> policy code list
  • targetType <PolicyAssignmentTargetType> Optional values ​​are USER (user) and ROLE (role)
  • targetIdentifiers <string[]> user id list and role code list

# Example

ArrayList<String> policies = new ArrayList<>();
policies.add("policy code");

ArrayList<String> targetIdentifiers = new ArrayList<>();
targetIdentifiers.add("userId");

managementClient.policies().removeAssignments(policies, PolicyAssignmentTargetType.USER, targetIdentifiers).execute();