當前位置: 首頁>>代碼示例>>Java>>正文


Java CreatePolicyResult類代碼示例

本文整理匯總了Java中com.amazonaws.services.identitymanagement.model.CreatePolicyResult的典型用法代碼示例。如果您正苦於以下問題:Java CreatePolicyResult類的具體用法?Java CreatePolicyResult怎麽用?Java CreatePolicyResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CreatePolicyResult類屬於com.amazonaws.services.identitymanagement.model包,在下文中一共展示了CreatePolicyResult類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCreateAdminPolicy

import com.amazonaws.services.identitymanagement.model.CreatePolicyResult; //導入依賴的package包/類
@Test
public void testCreateAdminPolicy() throws Exception {
    String policyDocument = new String(Files.readAllBytes(Paths.get(TEST_DATA_DIR, "test_admin_policy")));
    CreatePolicyRequest request = constructCreatePolicyRequest("admin", policyDocument);
    CreatePolicyResult result = new CreatePolicyResult().withPolicy(new Policy().withArn(ADMIN_POLICY_ARN));
    when(mockClient.createPolicy(request)).thenReturn(result);

    // When constructing policy statement for KMS, the KMSManager checks that the key exists with a
    // DescribeKeyRequest. So we need to mock this result as well.
    DescribeKeyRequest keyRequest = new DescribeKeyRequest().withKeyId(KMS_ALIAS_ARN);
    when(mockKMSClient.describeKey(keyRequest)).thenReturn(constructDescribeKeyResult());

    // Create the policy and verify the policy is as expected and expected calls to AWS were made.
    String policyArn = partiallyMockedPolicyManager.createAdminPolicy(group, kmsEncryptor, partiallyMockedStore);

    verify(mockClient, times(1)).createPolicy(request);
    verify(mockKMSClient, times(1)).describeKey(keyRequest);
    assertEquals(policyArn, ADMIN_POLICY_ARN);
}
 
開發者ID:schibsted,項目名稱:strongbox,代碼行數:20,代碼來源:IAMPolicyManagerTest.java

示例2: testCreateReadOnlyPolicy

import com.amazonaws.services.identitymanagement.model.CreatePolicyResult; //導入依賴的package包/類
@Test
public void testCreateReadOnlyPolicy() throws Exception {
    String policyDocument = new String(Files.readAllBytes(Paths.get(TEST_DATA_DIR, "test_readonly_policy")));
    CreatePolicyRequest request = constructCreatePolicyRequest("readonly", policyDocument);
    CreatePolicyResult result = new CreatePolicyResult().withPolicy(new Policy().withArn(READONLY_POLICY_ARN));
    when(mockClient.createPolicy(request)).thenReturn(result);

    // When constructing policy statement for KMS, the KMSManager checks that the key exists with a
    // DescribeKeyRequest. So we need to mock this result as well.
    DescribeKeyRequest keyRequest = new DescribeKeyRequest().withKeyId(KMS_ALIAS_ARN);
    when(mockKMSClient.describeKey(keyRequest)).thenReturn(constructDescribeKeyResult());

    // Create the policy and verify the policy is as expected and expected calls to AWS were made.
    String policyArn = partiallyMockedPolicyManager.createReadOnlyPolicy(group, kmsEncryptor, partiallyMockedStore);
    verify(mockClient, times(1)).createPolicy(request);
    verify(mockKMSClient, times(1)).describeKey(keyRequest);
    assertEquals(policyArn, READONLY_POLICY_ARN);
}
 
開發者ID:schibsted,項目名稱:strongbox,代碼行數:19,代碼來源:IAMPolicyManagerTest.java

示例3: main

import com.amazonaws.services.identitymanagement.model.CreatePolicyResult; //導入依賴的package包/類
public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a policy name\n" +
            "Ex: CreatePolicy <policy-name>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String policy_name = args[0];

        final AmazonIdentityManagement iam =
            AmazonIdentityManagementClientBuilder.defaultClient();

        CreatePolicyRequest request = new CreatePolicyRequest()
            .withPolicyName(policy_name)
            .withPolicyDocument(POLICY_DOCUMENT);

        CreatePolicyResult response = iam.createPolicy(request);

        System.out.println("Successfully created policy: " +
                response.getPolicy().getPolicyName());
    }
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:26,代碼來源:CreatePolicy.java


注:本文中的com.amazonaws.services.identitymanagement.model.CreatePolicyResult類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。