use of com.aliyun.oss.common.auth.CustomSessionCredentialsProvider in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetCredentialsFromAuthInOss.
@Test
public void testGetCredentialsFromAuthInOss() {
try {
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST);
Credentials credentials = credentialsProvider.getCredentials();
Assert.assertEquals(credentials.getAccessKeyId().length(), 29);
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
Assert.assertEquals(credentials.getSecurityToken().length(), 516);
Assert.assertTrue(credentials.useSecurityToken());
String key = "test.txt";
String content = "HelloOSS";
OSS ossClient = new OSSClientBuilder().build(TestConfig.OSS_ENDPOINT, credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSecurityToken());
ossClient.putObject(TestConfig.OSS_BUCKET, key, new ByteArrayInputStream(content.getBytes()));
ossClient.shutdown();
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.CustomSessionCredentialsProvider in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetNormalCredentials.
@Test
public void testGetNormalCredentials() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.Normal);
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST).withCredentialsFetcher(credentialsFetcher);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertEquals(credentials.getAccessKeyId().length(), 29);
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
Assert.assertEquals(credentials.getSecurityToken().length(), 536);
Assert.assertTrue(credentials.useSecurityToken());
Assert.assertFalse(credentials.willSoonExpire());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.CustomSessionCredentialsProvider in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetExceptionalCredentials.
@Test
public void testGetExceptionalCredentials() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.Exceptional);
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST).withCredentialsFetcher(credentialsFetcher);
Credentials credentials = credentialsProvider.getCredentials();
Assert.assertNull(credentials);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.CustomSessionCredentialsProvider in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testRefreshCredentials.
@Test
public void testRefreshCredentials() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.Expired);
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST).withCredentialsFetcher(credentialsFetcher);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertTrue(credentials.willSoonExpire());
credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.Normal);
credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.ECS_ROLE_NAME).withCredentialsFetcher(credentialsFetcher);
credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertFalse(credentials.willSoonExpire());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.CustomSessionCredentialsProvider in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetCredentialsUseInOss.
@Test
public void testGetCredentialsUseInOss() {
try {
CustomSessionCredentialsProvider credentialsProvider = CredentialsProviderFactory.newCustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST);
String key = "test.txt";
String content = "HelloOSS";
OSS ossClient = new OSSClientBuilder().build(TestConfig.OSS_ENDPOINT, credentialsProvider);
ossClient.putObject(TestConfig.OSS_BUCKET, key, new ByteArrayInputStream(content.getBytes()));
Thread.sleep(1000 * 10);
ossClient.putObject(TestConfig.OSS_BUCKET, key, new ByteArrayInputStream(content.getBytes()));
ossClient.shutdown();
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations