AwsClientHelpers { static AWSCredentialsProvider getCredentialsProvider( final String accessKey, final String secretKey, final String sessionToken ) { AWSCredentialsProvider credProvider; if ((null != accessKey) && (null != secretKey)) { AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); if (sessionToken != null) { credentials = new BasicSessionCredentials(accessKey, secretKey, sessionToken); } AWSCredentials finalCredentials = credentials; credProvider = new AWSCredentialsProviderChain( new AWSCredentialsProvider() { public AWSCredentials getCredentials() { return finalCredentials; } public void refresh() { } }, new DefaultAWSCredentialsProviderChain() ); } else { credProvider = new DefaultAWSCredentialsProviderChain(); } return credProvider; }  static AmazonS3 buildClient(
        String accessKey, String secretKey, String sessionToken,
        Region region,
        String serviceEndpoint, String signingRegion
    );  }
@Test public void testGetCredentialsProvider() { AWSCredentialsProvider accessProvider = AwsClientHelpers.getCredentialsProvider( "accessKey", "secretKey", null ); AWSCredentials credentials = accessProvider.getCredentials(); assertEquals(BasicAWSCredentials.class, credentials.getClass()); }
@Test public void testGetCredentialsProviderWithSessionToken() { AWSCredentialsProvider accessProvider = AwsClientHelpers.getCredentialsProvider( "accessKey", "secretKey", "sessionToken" ); AWSCredentials credentials = accessProvider.getCredentials(); assertEquals(BasicSessionCredentials.class, credentials.getClass()); BasicSessionCredentials bsc = (BasicSessionCredentials)credentials; assertEquals("sessionToken", bsc.getSessionToken()); }