
com.aliyun.credentials.provider.EnvironmentVariableCredentialsProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of credentials-java Show documentation
Show all versions of credentials-java Show documentation
Alibaba Cloud Credentials for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
https://www.aliyun.com
package com.aliyun.credentials.provider;
import com.aliyun.credentials.exception.CredentialException;
import com.aliyun.credentials.models.CredentialModel;
import com.aliyun.credentials.utils.AuthConstant;
import com.aliyun.credentials.utils.AuthUtils;
import com.aliyun.credentials.utils.StringUtils;
public class EnvironmentVariableCredentialsProvider implements AlibabaCloudCredentialsProvider {
@Override
public CredentialModel getCredentials() {
String accessKeyId = AuthUtils.getEnvironmentAccessKeyId();
String accessKeySecret = AuthUtils.getEnvironmentAccessKeySecret();
String securityToken = AuthUtils.getEnvironmentSecurityToken();
if (StringUtils.isEmpty(accessKeyId)) {
throw new CredentialException("Environment variable accessKeyId cannot be empty.");
}
if (StringUtils.isEmpty(accessKeySecret)) {
throw new CredentialException("Environment variable accessKeySecret cannot be empty.");
}
if (!StringUtils.isEmpty(securityToken)) {
return CredentialModel.builder()
.accessKeyId(accessKeyId)
.accessKeySecret(accessKeySecret)
.securityToken(securityToken)
.type(AuthConstant.STS)
.build();
}
return CredentialModel.builder()
.accessKeyId(accessKeyId)
.accessKeySecret(accessKeySecret)
.type(AuthConstant.ACCESS_KEY)
.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy