use of com.aliyun.oss.common.auth.PublicKey in project aliyun-oss-java-sdk by aliyun.
the class RamUtilsTest method testListPublicKey.
@Test
public void testListPublicKey() {
try {
// upload
String pubKey = AuthUtils.loadPublicKeyFromFile(TestConfig.PUBLIC_KEY_PATH);
PublicKey publicKey = AuthUtils.uploadPublicKey(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET, pubKey);
// check
List<PublicKey> publicKeys = AuthUtils.listPublicKeys(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET);
Assert.assertEquals(1, publicKeys.size());
Assert.assertEquals(publicKeys.get(0).getPublicKeyId().length(), "LTRSA.2Qcjm****XW7M0NO".length());
Assert.assertEquals(publicKeys.get(0).getCreateDate().length(), "2017-11-01T08:00:00Z".length());
Assert.assertEquals(publicKeys.get(0).getStatus(), "Active");
Assert.assertEquals(publicKeys.get(0).getPublicKeySpec(), null);
// delete
AuthUtils.deletePublicKey(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET, publicKey.getPublicKeyId());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.PublicKey in project aliyun-oss-java-sdk by aliyun.
the class RamUtilsTest method testUploadPublicKey.
@Test
public void testUploadPublicKey() {
try {
// upload
String pubKey = AuthUtils.loadPublicKeyFromFile(TestConfig.PUBLIC_KEY_PATH);
PublicKey publicKey = AuthUtils.uploadPublicKey(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET, pubKey);
Assert.assertNotNull(publicKey);
Assert.assertEquals(publicKey.getPublicKeyId().length(), "LTRSA.2Qcjm****XW7M0NO".length());
// check
List<PublicKey> publicKeys = AuthUtils.listPublicKeys(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET);
Assert.assertEquals(1, publicKeys.size());
// delete
AuthUtils.deletePublicKey(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET, publicKey.getPublicKeyId());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.PublicKey in project aliyun-oss-java-sdk by aliyun.
the class STSKeyPairSessionCredentialsProviderTest method testStsKeyPairCredentialsProviderInOss.
@Test
public void testStsKeyPairCredentialsProviderInOss() {
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));
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()));
ossClient.shutdown();
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.PublicKey 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());
}
}
Aggregations