private static AWSCredentialsProvider getCredentialsProvider ( final Properties configProps , final String configPrefix ) { CredentialProvider credentialProviderType ; if ( ! configProps . containsKey ( configPrefix ) ) { if ( configProps . containsKey ( AWSConfigConstants . accessKeyId ( configPrefix ) ) && configProps . containsKey ( AWSConfigConstants . secretKey ( configPrefix ) ) ) { // if the credential provider type is not specified, but the Access Key ID and Secret Key are given, it will default to BASIC credentialProviderType = CredentialProvider . BASIC ; } else { // if the credential provider type is not specified, it will default to AUTO credentialProviderType = CredentialProvider . AUTO ; } } else { credentialProviderType = CredentialProvider . valueOf ( configProps . getProperty ( configPrefix ) ) ; } switch ( credentialProviderType ) { case ENV_VAR : return new EnvironmentVariableCredentialsProvider ( ) ; case SYS_PROP : return new SystemPropertiesCredentialsProvider ( ) ; case PROFILE : String profileName = configProps . getProperty ( AWSConfigConstants . profileName ( configPrefix ) , null ) ; String profileConfigPath = configProps . getProperty ( AWSConfigConstants . profilePath ( configPrefix ) , null ) ; return ( profileConfigPath == null ) ? new ProfileCredentialsProvider ( profileName ) : new ProfileCredentialsProvider ( profileConfigPath , profileName ) ; case BASIC : return new AWSCredentialsProvider ( ) { @ Override public AWSCredentials getCredentials ( ) { return new BasicAWSCredentials ( configProps . getProperty ( AWSConfigConstants . accessKeyId ( configPrefix ) ) , configProps . getProperty ( AWSConfigConstants . secretKey ( configPrefix ) ) ) ; } @ Override public void refresh ( ) { // do nothing } } ; case ASSUME_ROLE : final AWSSecurityTokenService baseCredentials = AWSSecurityTokenServiceClientBuilder . standard ( ) . withCredentials ( getCredentialsProvider ( configProps , AWSConfigConstants . roleCredentialsProvider ( configPrefix ) ) ) . withRegion ( configProps . getProperty ( AWSConfigConstants . AWS_REGION ) ) . build ( ) ; return new STSAssumeRoleSessionCredentialsProvider . Builder ( configProps . getProperty ( AWSConfigConstants . roleArn ( configPrefix ) ) , configProps . getProperty ( AWSConfigConstants . roleSessionName ( configPrefix ) ) ) . withExternalId ( configProps . getProperty ( AWSConfigConstants . externalId ( configPrefix ) ) ) . withStsClient ( baseCredentials ) . build ( ) ; default : case AUTO : return new DefaultAWSCredentialsProviderChain ( ) ; } }
If the provider is ASSUME_ROLE then the credentials for assuming this role are determined recursively .