当前位置: 首页>>代码示例>>Java>>正文


Java AmazonIdentityManagementClient类代码示例

本文整理汇总了Java中com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient的典型用法代码示例。如果您正苦于以下问题:Java AmazonIdentityManagementClient类的具体用法?Java AmazonIdentityManagementClient怎么用?Java AmazonIdentityManagementClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AmazonIdentityManagementClient类属于com.amazonaws.services.identitymanagement包,在下文中一共展示了AmazonIdentityManagementClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkIamProfileName

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
/**
 * Validates the configured IAM profile.
 *
 * @param configuration       the configuration to be validated
 * @param accumulator         the exception condition accumulator
 * @param localizationContext the localization context
 */
@VisibleForTesting
void checkIamProfileName(Configured configuration,
    PluginExceptionConditionAccumulator accumulator,
    LocalizationContext localizationContext) {

  String iamProfileName =
      configuration.getConfigurationValue(IAM_PROFILE_NAME, localizationContext);

  if (iamProfileName != null) {
    AmazonIdentityManagementClient iamClient = provider.getIdentityManagementClient();

    try {
      iamClient.getInstanceProfile(new GetInstanceProfileRequest()
          .withInstanceProfileName(iamProfileName));

    } catch (NoSuchEntityException e) {
      addError(accumulator, IAM_PROFILE_NAME, localizationContext,
          null, INVALID_IAM_PROFILE_NAME_MSG, iamProfileName);
    }
  }
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:29,代码来源:EC2InstanceTemplateConfigurationValidator.java

示例2: getCredentialReportCSV

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
GetCredentialReportResult getCredentialReportCSV(final String accountId) {
    final AmazonIdentityManagementClient client = getIAMClient(accountId);

    GenerateCredentialReportResult generationReport;
    int i = 0;
    do {
        Assert.state(i < MAX_RETRIES, "Maximum retries to generate credentials report exceeded");
        log.debug("Poll credentials report for account {}", accountId);
        try {
            MILLISECONDS.sleep(RETRY_TIMEOUT_MILLIS * i);
        } catch (final InterruptedException e) {
            throw new RuntimeException("Could not pull credentials report", e);
        }
        generationReport = client.generateCredentialReport();
        i++;

    } while (!COMPLETE.toString().equals(generationReport.getState()));

    return client.getCredentialReport();
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:21,代码来源:IdentityManagementDataSource.java

示例3: setUp

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    this.violationSinkMock = mock(ViolationSink.class);
    this.clientProviderMock = mock(ClientProvider.class);
    this.accountIdSupplierMock = mock(AccountIdSupplier.class);
    this.jobsPropertiesMock = mock(JobsProperties.class);
    this.mockAmazonIdentityManagementClient = mock(AmazonIdentityManagementClient.class);
    this.mockAwsApplications = mock(AwsApplications.class);

    mockListRolesResult = new ListRolesResult();
    mockListRolesResult.setRoles(asList(
            createRole("aws-service-role", AWS_SERVICE_POLICY_DOCUMENT),
            createRole("cross-account-role", CROSS_ACCOUNT_POLICY_DOCUMENT),
            createRole("same-account-role", SAME_ACCOUNT_POLICY_DOCUMENT),
            createRole("deleted-role-reference-role", DELETED_ROLE_POLICY_DOCUMENT),
            createRole("management-account-role", MANAGEMENT_POLICY_DOCUMENT)));

    when(clientProviderMock.getClient(any(), any(String.class), any(Region.class))).thenReturn(mockAmazonIdentityManagementClient);
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:20,代码来源:CrossAccountPolicyForIAMJobTest.java

示例4: execute

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
/**
 * Sets the "instanceProfile" and "serviceRole" properties according to the
 * set parameters.
 */
public void execute() {
    checkParams();
    AmazonIdentityManagementClient iamClient = getOrCreateClient(AmazonIdentityManagementClient.class);
    getProject()
            .setProperty(
                    "instanceProfileArn",
                    iamClient
                            .getInstanceProfile(
                                    new GetInstanceProfileRequest()
                                            .withInstanceProfileName(instanceProfile))
                            .getInstanceProfile().getArn());
    getProject()
            .setProperty(
                    "serviceRoleArn",
                    iamClient
                            .getRole(
                                    new GetRoleRequest()
                                            .withRoleName(serviceRole))
                            .getRole().getArn());

}
 
开发者ID:awslabs,项目名称:aws-ant-tasks,代码行数:26,代码来源:SetUpOpsWorksTestsTask.java

示例5: main

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
public static void main(String... args) throws IOException {
    AWSCredentialsProvider credentials = CredentialsUtils.getAwsCredentials();

    AmazonS3 storage = new AmazonS3Client(credentials);
    storage.setRegion(Region.getRegion(Regions.EU_WEST_1));

    AmazonSQS queue = new AmazonSQSClient(credentials);
    queue.setRegion(Region.getRegion(Regions.EU_WEST_1));

    AmazonEC2 machines = new AmazonEC2Client(credentials);
    machines.setRegion(Region.getRegion(Regions.EU_WEST_1));

    AmazonIdentityManagement identityManagement = new AmazonIdentityManagementClient(credentials);
    identityManagement.setRegion(Region.getRegion(Regions.EU_WEST_1));

    if ("launch".equals(args[0])) {
        setup(storage, queue, machines, identityManagement);

        manageAnswers(queue);
    } else if ("run".equals(args[0])) {
        run(storage, queue);
    } else {
        System.out.println("Huh hoh! Don't know what you intended to do...");
    }
}
 
开发者ID:mathieubolla,项目名称:aws-sdk-first-steps,代码行数:26,代码来源:Launcher.java

示例6: getAWSAccountID

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
private static String getAWSAccountID() {
    try {
        String accessKey = AWS_ACCESS_KEY_ID;
        String secretKey = AWS_SECRET_KEY;

        if (Utilities.isEmpty(accessKey) || Utilities.isEmpty(secretKey)) {
            return null;
        }

        AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
        AmazonIdentityManagementClient iam = new AmazonIdentityManagementClient(creds);
        return iam.getUser().getUser().getArn().split(":")[4];
    } catch (AmazonClientException e) {
        throw new RuntimeException("Failed to get AWS account id", e);
    }
}
 
开发者ID:aws-samples,项目名称:reinvent2013-mobile-photo-share,代码行数:17,代码来源:Configuration.java

示例7: setUp

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
@BeforeMethod
public void setUp() {
    mockCredentials = mock(AWSCredentialsProvider.class);
    mockClient = mock(AmazonIdentityManagementClient.class);
    ClientConfiguration mockConfig = mock(ClientConfiguration.class);
    IAMPolicyManager policyManager = new IAMPolicyManager(mockClient, mockCredentials, mockConfig);

    // The mockito spy acts like original object but mocks out the getAccount() method. As the getAccount() calls
    // directly rather than via a client that we can pass in we need to mock this out using a spy.
    partiallyMockedPolicyManager = spy(policyManager);
    doReturn(ACCOUNT).when(partiallyMockedPolicyManager).getAccount();

    // Set up KMSEncryptor for testing the policy creation methods. This gets a bit complicated but we need to
    // mock all the AWS dependencies from the KMSManager before using it to create the KMSEncryptor. The getAliasArn
    // needs to be mocked out with a spy to stop the call to getAccount.
    mockKMSClient = mock(AWSKMSClient.class);
    KMSManager kmsManager = new KMSManager(mockKMSClient, mockCredentials, mockConfig, group);
    KMSManager partiallyMockedKMSManager = spy(kmsManager);
    doReturn(KMS_ALIAS_ARN).when(partiallyMockedKMSManager).getAliasArn();
    kmsEncryptor = new KMSEncryptor(partiallyMockedKMSManager, mockCredentials, mockConfig, group, mock(AwsCrypto.class), EncryptionStrength.AES_256);

    // Set up store for testing the policy creation methods. Mock out the getArn method with a spy to stop the
    // call to getAccount().
    mockDynamoDBClient = mock(AmazonDynamoDBClient.class);
    DynamoDB store = new DynamoDB(mockDynamoDBClient, mockCredentials, mockConfig, group, new ReentrantReadWriteLock());
    partiallyMockedStore = spy(store);
    doReturn(DYNAMODB_ARN).when(partiallyMockedStore).getArn();
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:29,代码来源:IAMPolicyManagerTest.java

示例8: getAccountId

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
/**
 * Method gets the aws accountId from the specified credentials.
 *
 * @param privateKeyId
 * @param privateKey
 * @return account ID
 */
private String getAccountId(String privateKeyId, String privateKey) {
    AWSCredentials awsCredentials = new BasicAWSCredentials(privateKeyId, privateKey);

    AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
            awsCredentials);

    AmazonIdentityManagementClientBuilder amazonIdentityManagementClientBuilder = AmazonIdentityManagementClientBuilder
            .standard()
            .withCredentials(awsStaticCredentialsProvider)
            .withRegion(Regions.DEFAULT_REGION);

    AmazonIdentityManagementClient iamClient = (AmazonIdentityManagementClient) amazonIdentityManagementClientBuilder
            .build();

    String userId = null;
    try {
        if ((iamClient.getUser() != null) && (iamClient.getUser().getUser() != null)
                && (iamClient.getUser().getUser().getArn() != null)) {

            String arn = iamClient.getUser().getUser().getArn();
            /*
             * arn:aws:service:region:account:resource -> so limiting the split to 6 words and
             * extracting the accountId which is 5th one in list. If the user is not authorized
             * to perform iam:GetUser on that resource,still error mesage will have accountId
             */
            userId = arn.split(":", 6)[4];
        }
    } catch (AmazonServiceException ex) {
        if (ex.getErrorCode().compareTo("AccessDenied") == 0) {
            String msg = ex.getMessage();
            userId = msg.split(":", 7)[5];
        } else {
            logSevere("Exception getting the accountId %s", ex);

        }
    }
    return userId;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:46,代码来源:AWSEndpointAdapterService.java

示例9: configure

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
/**
 * Binds all the Amazon services used.
 */
@Override
protected void configure() {
    final Region region = Region.getRegion(Regions.fromName(regionName));
    bind(AmazonEC2.class).toInstance(createAmazonClientInstance(AmazonEC2Client.class, region));
    bind(AmazonCloudFormation.class).toInstance(createAmazonClientInstance(AmazonCloudFormationClient.class, region));
    bind(AmazonIdentityManagement.class).toInstance(createAmazonClientInstance(AmazonIdentityManagementClient.class, region));
    bind(AWSKMS.class).toInstance(createAmazonClientInstance(AWSKMSClient.class, region));
    bind(AmazonS3.class).toInstance(createAmazonClientInstance(AmazonS3Client.class, region));
    bind(AmazonAutoScaling.class).toInstance(createAmazonClientInstance(AmazonAutoScalingClient.class, region));
    bind(AWSSecurityTokenService.class).toInstance(createAmazonClientInstance(AWSSecurityTokenServiceClient.class, region));
    bind(AWSLambda.class).toInstance(createAmazonClientInstance(AWSLambdaClient.class, region));
    bind(AmazonSNS.class).toInstance(createAmazonClientInstance(AmazonSNSClient.class, region));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:17,代码来源:CerberusModule.java

示例10: getRolePolicies

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
@Override
public RolePolicies getRolePolicies(String roleName, Region region, String accountId) {
    final AmazonIdentityManagementClient iamClient = clientProvider
            .getClient(AmazonIdentityManagementClient.class, accountId, region);
    final Set<String> attachedPolicyNames = fetchAttachedPolicyNames(roleName, iamClient);
    final Set<String> inlinePolicyNames = fetchInlinePolicyNames(roleName, iamClient);
    // assuming that there is an inline policy with the same name as the role itself
    final String mainPolicy = inlinePolicyNames.contains(roleName) ? fetchMainPolicy(roleName, iamClient) : EMPTY_JSON;

    return new RolePolicies(attachedPolicyNames, inlinePolicyNames, mainPolicy);
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:12,代码来源:PolicyProviderImpl.java

示例11: fetchMainPolicy

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
private String fetchMainPolicy(String roleName, AmazonIdentityManagementClient iamClient) {
    return Optional.of(new GetRolePolicyRequest().withRoleName(roleName).withPolicyName(roleName))
            .map(iamClient::getRolePolicy)
            .map(GetRolePolicyResult::getPolicyDocument)
            .map(PolicyProviderImpl::urlDecode)
            .orElse(EMPTY_JSON);
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:8,代码来源:PolicyProviderImpl.java

示例12: fetchInlinePolicyNames

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
private Set<String> fetchInlinePolicyNames(String roleName, AmazonIdentityManagementClient iamClient) {
    return Optional.of(new ListRolePoliciesRequest().withRoleName(roleName))
            .map(iamClient::listRolePolicies)
            .map(ListRolePoliciesResult::getPolicyNames)
            .map(nameList -> nameList.stream().collect(toSet()))
            .orElseGet(Collections::emptySet);
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:8,代码来源:PolicyProviderImpl.java

示例13: fetchAttachedPolicyNames

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
private Set<String> fetchAttachedPolicyNames(String roleName, AmazonIdentityManagementClient iamClient) {
    return Optional.of(new ListAttachedRolePoliciesRequest().withRoleName(roleName))
            .map(iamClient::listAttachedRolePolicies)
            .map(ListAttachedRolePoliciesResult::getAttachedPolicies)
            .map(attachedPolicies -> attachedPolicies.stream().map(AttachedPolicy::getPolicyName).collect(toSet()))
            .orElseGet(Collections::emptySet);
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:8,代码来源:PolicyProviderImpl.java

示例14: retrieveAccountIdFromAwsAPI

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
/**
 * Read AWS account ID
 */
public void retrieveAccountIdFromAwsAPI() {
	String accountId = "";

	try {
		AmazonIdentityManagementClient iamClient = new AmazonIdentityManagementClient(getCredentials());
		LOG.info("Current AWS user: " + iamClient.getUser().getUser().getUserId());
		accountId = iamClient.getUser().getUser().getArn();
	} catch (AmazonServiceException e) {
		if (e.getErrorCode().compareTo("AccessDenied") == 0) {
			String arn = null;
			String msg = e.getMessage();
			// User:
			// arn:aws:iam::123456789012:user/division_abc/subdivision_xyz/Bob
			// is not authorized to perform: iam:GetUser on
			// resource:
			// arn:aws:iam::123456789012:user/division_abc/subdivision_xyz/Bob
			// arn:aws:sts::123456789012:assumed-role/Shibboleth-PowerUser/username
			int arnIdx = msg.indexOf("arn:aws");
			if (arnIdx != -1) {
				int arnSpace = msg.indexOf(" ", arnIdx);
				arn = msg.substring(arnIdx, arnSpace);

				// Remove "arn:aws:sts::"
				arn = arn.substring(13, 13 + 12);
			}
			accountId = arn;
		}

		if ((accountId == null) || (accountId.length() == 0)) {
			LOG.warn("Cannot lookup account id: " + e.getMessage());
		}
	} catch (Exception ex) {
		LOG.error("Cannot lookup account id: " + ex.getMessage());
	}

	setAccountId(accountId);
}
 
开发者ID:janloeffler,项目名称:aws-utilization-monitor,代码行数:41,代码来源:AwsAccount.java

示例15: getAccountId

import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient; //导入依赖的package包/类
/**
 * Via the default provider chain (i.e., global keys for this Jenkins instance),  return the account ID for the
 * currently authenticated user.
 * @param proxyHost hostname of the proxy to use (if any)
 * @param proxyPort port of the proxy to use (if any)
 * @return 12-digit account id
 */
public static String getAccountId(String proxyHost, int proxyPort) {

    String arn = "";
    try {
        ClientConfiguration clientCfg = new ClientConfiguration();
        if (proxyHost != null && proxyPort > 0 ) {
            clientCfg.setProxyHost(proxyHost);
            clientCfg.setProxyPort(proxyPort);
        }
        AmazonIdentityManagementClient iam = new AmazonIdentityManagementClient(clientCfg);
        GetUserResult user = iam.getUser();
        arn = user.getUser().getArn();
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().compareTo("AccessDenied") == 0) {
            String msg = e.getMessage();
            int arnIdx = msg.indexOf("arn:aws");
            if (arnIdx != -1) {
                int arnSpace = msg.indexOf(" ", arnIdx);
                arn = msg.substring(arnIdx, arnSpace);
            }
        }
    }

    String accountId = arn.split(":")[ARN_ACCOUNT_ID_INDEX];
    return accountId;
}
 
开发者ID:awslabs,项目名称:aws-codedeploy-plugin,代码行数:34,代码来源:AWSClients.java


注:本文中的com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。