Policy management API
Create Strategy
Create a permission policy with reference to the following codes:
1public CreatePolicyResponse createPolicy(IamClient client) {
2 CreatePolicyRequest createPolicyRequest = new CreatePolicyRequest();
3 // Set policy name
4 createPolicyRequest.setName("test_policy_name");
5 // Set policy description
6 createPolicyRequest.setDescription("test_policy_description");
7 // Policy content, the string obtained after ACL format serialization
8 createPolicyRequest.setDocument("{\"accessControlList\": [{\"region\":\"bj\",\"service\":\"bcc\",\"resource\":[\"*\"]," +
9 "\"permission\":[\"*\"],\"effect\":\"Allow\"}]}");
10
11 client.createPolicy(createPolicyRequest);
12}
Query policies
Query a permission policy with reference to the following codes:
1public void getPolicy(IamClient client) {
2 // Policy name
3 String policyName = "test_policy_name";
4 // Policy type to be queried: System for system policies; Custom for custom policies
5 String policyType = "System";
6
7 client.getPolicy(policyName, policyType);
8}
Delete strategy
Delete a permission policy with reference to the following codes:
1public void deletePolicy(IamClient client) {
2 // Policy name
3 String policyName = "test_policy_name";
4 client.deletePolicy(policyName);
5}
List policies
List permission policies. When policyType is System, list built-in system policies with reference to the following codes:
1public void listPolicy(IamClient client) {
2 // Policy type to be queried: System for system policies; Custom for custom policies
3 String policyType = "System";
4
5 client.listPolicy(policyType);
6}
Associate user permissions
Associate permission policies with a user with reference to the following codes:
1public void attachPolicyToUser(IamClient client) {
2 // Username
3 String userName = "test_user_name";
4 // Policy name
5 String policyName = "test_policy_name";
6 // Policy type
7 String policyType = "System";
8
9 client.attachPolicyToUser(userName, policyName, policyType);
10}
Revoke user permissions
Revoke a permission policy associated with an IAM user with reference to the following codes:
1public void detachPolicyFromUser(IamClient client) {
2 // Username
3 String userName = "test_user_name";
4 // Policy name
5 String policyName = "test_policy_name";
6 // Policy type
7 String policyType = "System";
8
9 client.detachPolicyFromUser(userName,policyName, policyType)
10}
List user permissions
List a permission policy associated with a user with reference to the following codes:
1public void listPoliciesForUser(IamClient client) {
2 // Username
3 String userName = "test_user_name";
4
5 return client.listPoliciesForUser(userName)
6}
Associate group permissions
Associate a permission policy with a group with reference to the following codes:
1public void attachPolicyToGroup(IamClient client) {
2 // Group name
3 String groupName = "test_group_name";
4 // Policy name
5 String policyName = "test_policy_name";
6 // Policy type
7 String policyType = "System";
8
9 client.attachPolicyToGroup(userName, policyName, policyType);
10}
Revoke group permissions
Revoke a permission policy associated with a group with reference to the following codes:
1public void detachPolicyFromGroup(IamClient client) {
2 // Group name
3 String groupName = "test_group_name";
4 // Policy name
5 String policyName = "test_policy_name";
6 // Policy type
7 String policyType = "System";
8
9 client.detachPolicyFromGroup(groupName, policyName, policyType);
10}
List the permissions associated with a group
List a permission policy associated with a group with reference to the following codes:
1public void listPoliciesForGroup(IamClient client) {
2 // Group name
3 String groupName = "test_group_name";
4
5 client.listPoliciesForUser(groupName);
6}
Associate role permissions
Associate a permission policy with a role with reference to the following codes:
1public void attachPolicyToRole(IamClient client) {
2 // Role name
3 String roleName = "test_role_name";
4 // Policy name
5 String policyName = "test_policy_name";
6 // Policy type
7 String policyType = "System";
8
9 client.attachPolicyToRole(roleName, policyName, policyType);
10}
Revoke role permissions
Revoke a permission policy associated with a role with reference to the following codes:
1public void detachPolicyFromRole(IamClient client) {
2 // Role name
3 String roleName = "test_role_name";
4 // Policy name
5 String policyName = "test_policy_name";
6 // Policy type
7 String policyType = "System";
8
9 client.detachPolicyFromRole(roleName, policyName, policyType);
10}
List role permissions
List a permission policy associated with a role with reference to the following codes:
1public void listPoliciesForRole(IamClient client) {
2 // Role name
3 String roleName = "test_role_name";
4 client.listPoliciesForRole(roleName);
5}
