1 /*
2 * Copyright 2012-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15 package com.amazonaws.auth;
16
17 import com.amazonaws.auth.profile.ProfileCredentialsProvider;
18
19 /**
20 * AWS credentials provider chain that looks for credentials in this order:
21 * <ul>
22 * <li>Environment Variables -
23 * <code>AWS_ACCESS_KEY_ID</code> and <code>AWS_SECRET_ACCESS_KEY</code>
24 * (RECOMMENDED since they are recognized by all the AWS SDKs and CLI except for .NET),
25 * or <code>AWS_ACCESS_KEY</code> and <code>AWS_SECRET_KEY</code> (only recognized by Java SDK)
26 * </li>
27 * <li>Java System Properties - aws.accessKeyId and aws.secretKey</li>
28 * <li>Credential profiles file at the default location (~/.aws/credentials) shared by all AWS SDKs and the AWS CLI</li>
29 * <li>Credentials delivered through the Amazon EC2 container service if AWS_CONTAINER_CREDENTIALS_RELATIVE_URI" environment variable is set
30 * and security manager has permission to access the variable,</li>
31 * <li>Instance profile credentials delivered through the Amazon EC2 metadata service</li>
32 * <li>Web Identity Token credentials from the environment or container.</li>
33 * </ul>
34 *
35 * @see EnvironmentVariableCredentialsProvider
36 * @see SystemPropertiesCredentialsProvider
37 * @see ProfileCredentialsProvider
38 * @see EC2ContainerCredentialsProviderWrapper
39 */
40 public class DefaultAWSCredentialsProviderChain extends AWSCredentialsProviderChain {
41
42 private static final DefaultAWSCredentialsProviderChain INSTANCE
43 = new DefaultAWSCredentialsProviderChain();
44
45 public DefaultAWSCredentialsProviderChain() {
46 super(new EnvironmentVariableCredentialsProvider(),
47 new SystemPropertiesCredentialsProvider(),
48 WebIdentityTokenCredentialsProvider.create(),
49 new ProfileCredentialsProvider(),
50 new EC2ContainerCredentialsProviderWrapper());
51 }
52
53 public static DefaultAWSCredentialsProviderChain getInstance() {
54 return INSTANCE;
55 }
56 }
57