Search in sources :

Example 1 with SystemPropertiesCredentialsProvider

use of com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider in project aliyun-oss-java-sdk by aliyun.

the class SystemPropertiesCredentialsProviderTest method testSystemPropertiesCredentialsProviderInOss.

@Test
public void testSystemPropertiesCredentialsProviderInOss() {
    try {
        System.setProperty(AuthUtils.ACCESS_KEY_SYSTEM_PROPERTY, TestConfig.ROOT_ACCESS_KEY_ID);
        System.setProperty(AuthUtils.SECRET_KEY_SYSTEM_PROPERTY, TestConfig.ROOT_ACCESS_KEY_SECRET);
        System.setProperty(AuthUtils.SESSION_TOKEN_SYSTEM_PROPERTY, "");
        SystemPropertiesCredentialsProvider credentialsProvider = CredentialsProviderFactory.newSystemPropertiesCredentialsProvider();
        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());
    }
}
Also used : SystemPropertiesCredentialsProvider(com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) OSS(com.aliyun.oss.OSS) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) Test(org.junit.Test)

Example 2 with SystemPropertiesCredentialsProvider

use of com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider in project aliyun-oss-java-sdk by aliyun.

the class SystemPropertiesCredentialsProviderTest method testSystemPropertiesCredentialsProvider.

@Test
public void testSystemPropertiesCredentialsProvider() {
    try {
        System.setProperty(AuthUtils.ACCESS_KEY_SYSTEM_PROPERTY, TestConfig.ROOT_ACCESS_KEY_ID);
        System.setProperty(AuthUtils.SECRET_KEY_SYSTEM_PROPERTY, TestConfig.ROOT_ACCESS_KEY_SECRET);
        SystemPropertiesCredentialsProvider credentialsProvider = new SystemPropertiesCredentialsProvider();
        Credentials credentials = credentialsProvider.getCredentials();
        Assert.assertEquals(credentials.getAccessKeyId(), TestConfig.ROOT_ACCESS_KEY_ID);
        Assert.assertEquals(credentials.getSecretAccessKey(), TestConfig.ROOT_ACCESS_KEY_SECRET);
        Assert.assertFalse(credentials.useSecurityToken());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : SystemPropertiesCredentialsProvider(com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider) Credentials(com.aliyun.oss.common.auth.Credentials) Test(org.junit.Test)

Example 3 with SystemPropertiesCredentialsProvider

use of com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider in project aliyun-oss-java-sdk by aliyun.

the class SystemPropertiesCredentialsProviderTest method testSystemPropertiesStsCredentialsProvider.

@Test
public void testSystemPropertiesStsCredentialsProvider() {
    try {
        CredentialsProvider assumeRoleCredProvider = CredentialsProviderFactory.newSTSAssumeRoleSessionCredentialsProvider(TestConfig.RAM_REGION_ID, TestConfig.USER_ACCESS_KEY_ID, TestConfig.USER_ACCESS_KEY_SECRET, TestConfig.RAM_ROLE_ARN);
        Credentials assumeRoleCred = assumeRoleCredProvider.getCredentials();
        System.setProperty(AuthUtils.ACCESS_KEY_SYSTEM_PROPERTY, assumeRoleCred.getAccessKeyId());
        System.setProperty(AuthUtils.SECRET_KEY_SYSTEM_PROPERTY, assumeRoleCred.getSecretAccessKey());
        System.setProperty(AuthUtils.SESSION_TOKEN_SYSTEM_PROPERTY, assumeRoleCred.getSecurityToken());
        SystemPropertiesCredentialsProvider credentialsProvider = new SystemPropertiesCredentialsProvider();
        Credentials credentials = credentialsProvider.getCredentials();
        Assert.assertEquals(credentials.getAccessKeyId(), assumeRoleCred.getAccessKeyId());
        Assert.assertEquals(credentials.getSecretAccessKey(), assumeRoleCred.getSecretAccessKey());
        Assert.assertEquals(credentials.getSecurityToken(), assumeRoleCred.getSecurityToken());
        Assert.assertTrue(credentials.useSecurityToken());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : SystemPropertiesCredentialsProvider(com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider) SystemPropertiesCredentialsProvider(com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider) CredentialsProvider(com.aliyun.oss.common.auth.CredentialsProvider) Credentials(com.aliyun.oss.common.auth.Credentials) Test(org.junit.Test)

Example 4 with SystemPropertiesCredentialsProvider

use of com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider in project aliyun-oss-java-sdk by aliyun.

the class SystemPropertiesCredentialsProviderTest method testSystemPropertiesStsCredentialsProviderInOss.

@Test
public void testSystemPropertiesStsCredentialsProviderInOss() {
    try {
        CredentialsProvider assumeRoleCredProvider = CredentialsProviderFactory.newSTSAssumeRoleSessionCredentialsProvider(TestConfig.RAM_REGION_ID, TestConfig.USER_ACCESS_KEY_ID, TestConfig.USER_ACCESS_KEY_SECRET, TestConfig.RAM_ROLE_ARN);
        Credentials assumeRoleCred = assumeRoleCredProvider.getCredentials();
        System.setProperty(AuthUtils.ACCESS_KEY_SYSTEM_PROPERTY, assumeRoleCred.getAccessKeyId());
        System.setProperty(AuthUtils.SECRET_KEY_SYSTEM_PROPERTY, assumeRoleCred.getSecretAccessKey());
        System.setProperty(AuthUtils.SESSION_TOKEN_SYSTEM_PROPERTY, assumeRoleCred.getSecurityToken());
        SystemPropertiesCredentialsProvider credentialsProvider = CredentialsProviderFactory.newSystemPropertiesCredentialsProvider();
        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());
    }
}
Also used : SystemPropertiesCredentialsProvider(com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) SystemPropertiesCredentialsProvider(com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider) CredentialsProvider(com.aliyun.oss.common.auth.CredentialsProvider) Credentials(com.aliyun.oss.common.auth.Credentials) OSS(com.aliyun.oss.OSS) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) Test(org.junit.Test)

Aggregations

SystemPropertiesCredentialsProvider (com.aliyun.oss.common.auth.SystemPropertiesCredentialsProvider)4 Test (org.junit.Test)4 Credentials (com.aliyun.oss.common.auth.Credentials)3 OSS (com.aliyun.oss.OSS)2 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)2 CredentialsProvider (com.aliyun.oss.common.auth.CredentialsProvider)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2