in src/main/java/com/aliyun/credentials/provider/RamRoleArnCredentialProvider.java [96:156]
private RamRoleArnCredentialProvider(BuilderImpl builder) {
super(builder);
this.roleSessionName = builder.roleSessionName == null ? !StringUtils.isEmpty(AuthUtils.getEnvironmentRoleSessionName()) ?
AuthUtils.getEnvironmentRoleSessionName() : "credentials-java-" + System.currentTimeMillis() : builder.roleSessionName;
this.durationSeconds = builder.durationSeconds == null ? 3600 : builder.durationSeconds;
if (this.durationSeconds < 900) {
throw new IllegalArgumentException("Session duration should be in the range of 900s - max session duration.");
}
this.roleArn = builder.roleArn == null ? AuthUtils.getEnvironmentRoleArn() : builder.roleArn;
if (StringUtils.isEmpty(this.roleArn)) {
throw new IllegalArgumentException("RoleArn or environment variable ALIBABA_CLOUD_ROLE_ARN cannot be empty.");
}
this.regionId = builder.regionId;
this.policy = builder.policy;
this.externalId = builder.externalId;
this.connectTimeout = builder.connectionTimeout == null ? 5000 : builder.connectionTimeout;
this.readTimeout = builder.readTimeout == null ? 10000 : builder.readTimeout;
if (!StringUtils.isEmpty(builder.STSEndpoint)) {
this.STSEndpoint = builder.STSEndpoint;
} else {
String prefix = builder.enableVpc != null ? (builder.enableVpc ? "sts-vpc" : "sts") : AuthUtils.isEnableVpcEndpoint() ? "sts-vpc" : "sts";
if (!StringUtils.isEmpty(builder.stsRegionId)) {
this.STSEndpoint = String.format("%s.%s.aliyuncs.com", prefix, builder.stsRegionId);
} else if (!StringUtils.isEmpty(AuthUtils.getEnvironmentSTSRegion())) {
this.STSEndpoint = String.format("%s.%s.aliyuncs.com", prefix, AuthUtils.getEnvironmentSTSRegion());
} else {
this.STSEndpoint = "sts.aliyuncs.com";
}
}
if (null != builder.credentialsProvider) {
this.credentialsProvider = builder.credentialsProvider;
} else if (!StringUtils.isEmpty(builder.securityToken)) {
this.credentialsProvider = StaticCredentialsProvider.builder()
.credential(CredentialModel.builder()
.accessKeyId(Validate.notNull(
builder.accessKeyId, "AccessKeyId must not be null."))
.accessKeySecret(Validate.notNull(
builder.accessKeySecret, "AccessKeySecret must not be null."))
.securityToken(Validate.notNull(
builder.securityToken, "SecurityToken must not be null."))
.type(AuthConstant.STS)
.providerName(ProviderName.STATIC_STS)
.build())
.build();
} else {
this.credentialsProvider = StaticCredentialsProvider.builder()
.credential(CredentialModel.builder()
.accessKeyId(Validate.notNull(
builder.accessKeyId, "AccessKeyId must not be null."))
.accessKeySecret(Validate.notNull(
builder.accessKeySecret, "AccessKeySecret must not be null."))
.type(AuthConstant.ACCESS_KEY)
.providerName(ProviderName.STATIC_AK)
.build())
.build();
}
}