private AWSCredentialsProvider fromAssumeRole() { if (StringUtils.isNullOrEmpty(profile.getRoleSourceProfile())) { throw new SdkClientException(String.format( "Unable to load credentials from profile [%s]: Source profile name is not specified", profile.getProfileName())); } final BasicProfile sourceProfile = allProfiles .getProfile(this.profile.getRoleSourceProfile()); if (sourceProfile == null) { throw new SdkClientException(String.format( "Unable to load source profile [%s]: Source profile was not found [%s]", profile.getProfileName(), profile.getRoleSourceProfile())); } AWSCredentials sourceCredentials = new ProfileStaticCredentialsProvider(sourceProfile) .getCredentials(); final String roleSessionName = (this.profile.getRoleSessionName() == null) ? "aws-sdk-java-" + System.currentTimeMillis() : this.profile.getRoleSessionName(); RoleInfo roleInfo = new RoleInfo().withRoleArn(this.profile.getRoleArn()) .withRoleSessionName(roleSessionName) .withExternalId(this.profile.getRoleExternalId()) .withLongLivedCredentials(sourceCredentials); return profileCredentialsService.getAssumeRoleCredentialsProvider(roleInfo); } }
private AWSCredentialsProvider fromAssumeRole() { if (StringUtils.isNullOrEmpty(profile.getRoleSourceProfile())) { throw new SdkClientException(String.format( "Unable to load credentials from profile [%s]: Source profile name is not specified", profile.getProfileName())); } final BasicProfile sourceProfile = allProfiles .getProfile(this.profile.getRoleSourceProfile()); if (sourceProfile == null) { throw new SdkClientException(String.format( "Unable to load source profile [%s]: Source profile was not found [%s]", profile.getProfileName(), profile.getRoleSourceProfile())); } AWSCredentials sourceCredentials = new ProfileStaticCredentialsProvider(sourceProfile) .getCredentials(); final String roleSessionName = (this.profile.getRoleSessionName() == null) ? "aws-sdk-java-" + System.currentTimeMillis() : this.profile.getRoleSessionName(); RoleInfo roleInfo = new RoleInfo().withRoleArn(this.profile.getRoleArn()) .withRoleSessionName(roleSessionName) .withExternalId(this.profile.getRoleExternalId()) .withLongLivedCredentials(sourceCredentials); return profileCredentialsService.getAssumeRoleCredentialsProvider(roleInfo); } }
private AWSCredentialsProvider fromAssumeRole() { if (StringUtils.isNullOrEmpty(profile.getRoleSourceProfile())) { throw new SdkClientException(String.format( "Unable to load credentials from profile [%s]: Source profile name is not specified", profile.getProfileName())); } final BasicProfile sourceProfile = allProfiles .getProfile(this.profile.getRoleSourceProfile()); if (sourceProfile == null) { throw new SdkClientException(String.format( "Unable to load source profile [%s]: Source profile was not found [%s]", profile.getProfileName(), profile.getRoleSourceProfile())); } AWSCredentials sourceCredentials = new ProfileStaticCredentialsProvider(sourceProfile) .getCredentials(); final String roleSessionName = (this.profile.getRoleSessionName() == null) ? "aws-sdk-java-" + System.currentTimeMillis() : this.profile.getRoleSessionName(); RoleInfo roleInfo = new RoleInfo().withRoleArn(this.profile.getRoleArn()) .withRoleSessionName(roleSessionName) .withExternalId(this.profile.getRoleExternalId()) .withLongLivedCredentials(sourceCredentials); return profileCredentialsService.getAssumeRoleCredentialsProvider(roleInfo); } }