use of com.aliyun.oss.common.auth.BasicCredentials in project aliyun-oss-java-sdk by aliyun.
the class STSKeyPairSessionCredentialsProviderTest method testStsKeyPairCredentialsProvider.
@Test
public void testStsKeyPairCredentialsProvider() {
try {
PublicKey publicKey = AuthUtils.uploadPublicKey(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET, AuthUtils.loadPublicKeyFromFile(TestConfig.PUBLIC_KEY_PATH));
CredentialsProvider credentialsProvider = CredentialsProviderFactory.newSTSKeyPairSessionCredentialsProvider(TestConfig.RAM_REGION_ID, publicKey.getPublicKeyId(), AuthUtils.loadPrivateKeyFromFile(TestConfig.PRIVATE_KEY_PATH)).withExpiredDuration(900);
Thread.sleep(2000);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertFalse(credentials.useSecurityToken());
Assert.assertFalse(credentials.willSoonExpire());
Assert.assertTrue(credentials.getAccessKeyId().startsWith("TMPSK."));
Assert.assertEquals(credentials.getAccessKeyId().length(), 130);
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.BasicCredentials in project aliyun-oss-java-sdk by aliyun.
the class STSAssumeRoleSessionCredentialsProviderTest method testStsAssumeRoleCredentialsProvider.
@Test
public void testStsAssumeRoleCredentialsProvider() {
try {
CredentialsProvider credentialsProvider = CredentialsProviderFactory.newSTSAssumeRoleSessionCredentialsProvider(TestConfig.RAM_REGION_ID, TestConfig.USER_ACCESS_KEY_ID, TestConfig.USER_ACCESS_KEY_SECRET, TestConfig.RAM_ROLE_ARN).withExpiredDuration(900);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertTrue(credentials.useSecurityToken());
Assert.assertFalse(credentials.willSoonExpire());
Assert.assertTrue(credentials.getAccessKeyId().startsWith("STS."));
Assert.assertEquals(credentials.getAccessKeyId().length(), 29);
Assert.assertTrue(credentials.getSecretAccessKey().length() > 0);
Assert.assertTrue(credentials.getSecurityToken().length() > 0);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.BasicCredentials in project aliyun-oss-java-sdk by aliyun.
the class STSAssumeRoleSessionCredentialsProviderTest method testStsAssumeRoleCredentialsProviderRefresh.
@Test
public void testStsAssumeRoleCredentialsProviderRefresh() {
try {
CredentialsProvider credentialsProvider = CredentialsProviderFactory.newSTSAssumeRoleSessionCredentialsProvider(TestConfig.RAM_REGION_ID, TestConfig.USER_ACCESS_KEY_ID, TestConfig.USER_ACCESS_KEY_SECRET, TestConfig.RAM_ROLE_ARN).withExpiredFactor(0.001).withExpiredDuration(2000);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertFalse(credentials.willSoonExpire());
Thread.sleep(3000);
Assert.assertTrue(credentials.willSoonExpire());
BasicCredentials freshCredentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertFalse(freshCredentials.willSoonExpire());
Assert.assertFalse(freshCredentials.getAccessKeyId().equals(credentials.getAccessKeyId()));
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations