com.aliyuncs.auth.EnvironmentVariableCredentialsProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aliyun-java-sdk-core Show documentation
Show all versions of aliyun-java-sdk-core Show documentation
Aliyun Open API SDK for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
The newest version!
package com.aliyuncs.auth;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.utils.AuthUtils;
import com.aliyuncs.utils.StringUtils;
public class EnvironmentVariableCredentialsProvider implements AlibabaCloudCredentialsProvider {
@Override
public AlibabaCloudCredentials getCredentials() throws ClientException {
if (!"default".equals(AuthUtils.getClientType())) {
return null;
}
String accessKeyId = AuthUtils.getEnvironmentAccessKeyId();
String accessKeySecret = AuthUtils.getEnvironmentAccessKeySecret();
String securityToken = AuthUtils.getEnvironmentSecurityToken();
if (StringUtils.isEmpty(accessKeyId)) {
throw new ClientException("Environment variable accessKeyId cannot be empty.");
}
if (StringUtils.isEmpty(accessKeySecret)) {
throw new ClientException("Environment variable accessKeySecret cannot be empty.");
}
if (!StringUtils.isEmpty(securityToken)) {
return new BasicSessionCredentials(accessKeyId, accessKeySecret, securityToken);
}
return new BasicCredentials(accessKeyId, accessKeySecret);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy