use of com.aliyun.oss.common.auth.InvalidCredentialsException in project aliyun-oss-java-sdk by aliyun.
the class ProfilesConfigFileTest method testGetCredentialsNegative.
@Test
public void testGetCredentialsNegative() {
try {
Map<String, String> options = new HashMap<String, String>();
options.put(AuthUtils.OSS_ACCESS_KEY_ID, "");
options.put(AuthUtils.OSS_SECRET_ACCESS_KEY, TEST_ACCESS_KEY_SECRET);
generateProfileFile(AuthUtils.DEFAULT_PROFILE_PATH, AuthUtils.DEFAULT_SECTION_NAME, options);
ProfileConfigFile configFile = new ProfileConfigFile(AuthUtils.DEFAULT_PROFILE_PATH);
try {
configFile.getCredentials();
Assert.fail("ProfileConfigFile.getCredentials should not be successful");
} catch (InvalidCredentialsException e) {
}
options = new HashMap<String, String>();
options.put(AuthUtils.OSS_ACCESS_KEY_ID, TEST_ACCESS_KEY_ID);
options.put(AuthUtils.OSS_SECRET_ACCESS_KEY, "");
generateProfileFile(AuthUtils.DEFAULT_PROFILE_PATH, AuthUtils.DEFAULT_SECTION_NAME, options);
try {
configFile.getCredentials();
Assert.fail("ProfileConfigFile.getCredentials should not be successful");
} catch (InvalidCredentialsException e) {
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
} finally {
new File(AuthUtils.DEFAULT_PROFILE_PATH).delete();
}
}
use of com.aliyun.oss.common.auth.InvalidCredentialsException in project aliyun-oss-java-sdk by aliyun.
the class ProfileConfigFile method refresh.
/**
* Reread data from disk.
*/
public void refresh() {
if (credentials == null || profileFile.lastModified() > profileFileLastModified) {
profileFileLastModified = profileFile.lastModified();
Map<String, String> profileProperties = null;
try {
profileProperties = profileLoader.loadProfile(profileFile);
} catch (IOException e) {
LogUtils.logException("ProfilesConfigFile.refresh Exception:", e);
return;
}
String accessKeyId = StringUtils.trim(profileProperties.get(AuthUtils.OSS_ACCESS_KEY_ID));
String secretAccessKey = StringUtils.trim(profileProperties.get(AuthUtils.OSS_SECRET_ACCESS_KEY));
String sessionToken = StringUtils.trim(profileProperties.get(AuthUtils.OSS_SESSION_TOKEN));
if (StringUtils.isNullOrEmpty(accessKeyId)) {
throw new InvalidCredentialsException("Access key id should not be null or empty.");
}
if (StringUtils.isNullOrEmpty(secretAccessKey)) {
throw new InvalidCredentialsException("Secret access key should not be null or empty.");
}
credentials = new DefaultCredentials(accessKeyId, secretAccessKey, sessionToken);
}
}
use of com.aliyun.oss.common.auth.InvalidCredentialsException in project hadoop by apache.
the class TestAliyunCredentials method validateCredential.
private void validateCredential(Configuration conf) {
try {
AliyunCredentialsProvider provider = new AliyunCredentialsProvider(conf);
Credentials credentials = provider.getCredentials();
fail("Expected a CredentialInitializationException, got " + credentials);
} catch (InvalidCredentialsException expected) {
// expected
} catch (IOException e) {
fail("Unexpected exception.");
}
}
Aggregations