use of com.aliyun.oss.common.auth.DefaultCredentialProvider in project aliyun-oss-java-sdk by aliyun.
the class TestBase method getOSSClient.
public static OSSClient getOSSClient() {
if (ossClient == null) {
resetTestConfig();
ClientConfiguration conf = new ClientConfiguration().setSupportCname(false);
Credentials credentials = new DefaultCredentials(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET);
ossClient = new OSSClient(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(credentials), conf);
}
return ossClient;
}
use of com.aliyun.oss.common.auth.DefaultCredentialProvider in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithCredentialProvider.
@Test
public void testClientBuilderWithCredentialProvider() {
try {
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET), null);
Assert.assertFalse(ossClient.getClientConfiguration().isSupportCname());
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(TEST_CONTENT.getBytes().length);
ossClient.putObject(bucketName, TEST_KEY, new ByteArrayInputStream(TEST_CONTENT.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, TEST_KEY);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, TEST_KEY);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.DefaultCredentialProvider in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithSTS.
@Test
public void testClientBuilderWithSTS() {
try {
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setSupportCname(true);
config.setConnectionTimeout(10000);
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET, "TOKEN"), config);
Assert.assertTrue(ossClient.getClientConfiguration().isSupportCname());
Assert.assertEquals(ossClient.getClientConfiguration().getConnectionTimeout(), 10000);
Credentials cred = ossClient.getCredentialsProvider().getCredentials();
Assert.assertEquals(cred.getAccessKeyId(), TestConfig.OSS_TEST_ACCESS_KEY_ID);
Assert.assertEquals(cred.getSecretAccessKey(), TestConfig.OSS_TEST_ACCESS_KEY_SECRET);
Assert.assertEquals(cred.getSecurityToken(), "TOKEN");
Assert.assertTrue(cred.useSecurityToken());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.DefaultCredentialProvider in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithBuilderConfiguration.
@Test
public void testClientBuilderWithBuilderConfiguration() {
try {
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET), new ClientBuilderConfiguration());
Assert.assertFalse(ossClient.getClientConfiguration().isSupportCname());
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(TEST_CONTENT.getBytes().length);
ossClient.putObject(bucketName, TEST_KEY, new ByteArrayInputStream(TEST_CONTENT.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, TEST_KEY);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, TEST_KEY);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.DefaultCredentialProvider in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithAll.
@Test
public void testClientBuilderWithAll() {
try {
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setSupportCname(true);
config.setConnectionTimeout(10000);
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET), config);
Assert.assertTrue(ossClient.getClientConfiguration().isSupportCname());
Assert.assertEquals(ossClient.getClientConfiguration().getConnectionTimeout(), 10000);
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(TEST_CONTENT.getBytes().length);
ossClient.putObject(bucketName, TEST_KEY, new ByteArrayInputStream(TEST_CONTENT.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, TEST_KEY);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, TEST_KEY);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
Aggregations