1 /* 2 * Copyright 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 16 package software.amazon.awssdk.identity.spi; 17 18 import software.amazon.awssdk.annotations.SdkPublicApi; 19 import software.amazon.awssdk.annotations.ThreadSafe; 20 import software.amazon.awssdk.identity.spi.internal.DefaultAwsCredentialsIdentity; 21 22 /** 23 * Provides access to the AWS credentials used for accessing services: AWS access key ID and secret access key. These 24 * credentials are used to securely sign requests to services (e.g., AWS services) that use them for authentication. 25 * 26 * <p>For more details on AWS access keys, see: 27 * <a href="https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys"> 28 * https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys</a></p> 29 * 30 * @see AwsSessionCredentialsIdentity 31 */ 32 @SdkPublicApi 33 @ThreadSafe 34 public interface AwsCredentialsIdentity extends Identity { 35 /** 36 * Retrieve the AWS access key, used to identify the user interacting with services. 37 */ accessKeyId()38 String accessKeyId(); 39 40 /** 41 * Retrieve the AWS secret access key, used to authenticate the user interacting with services. 42 */ secretAccessKey()43 String secretAccessKey(); 44 builder()45 static Builder builder() { 46 return DefaultAwsCredentialsIdentity.builder(); 47 } 48 49 /** 50 * Constructs a new credentials object, with the specified AWS access key and AWS secret key. 51 * 52 * @param accessKeyId The AWS access key, used to identify the user interacting with services. 53 * @param secretAccessKey The AWS secret access key, used to authenticate the user interacting with services. 54 */ create(String accessKeyId, String secretAccessKey)55 static AwsCredentialsIdentity create(String accessKeyId, String secretAccessKey) { 56 return builder().accessKeyId(accessKeyId) 57 .secretAccessKey(secretAccessKey) 58 .build(); 59 } 60 61 interface Builder { 62 /** 63 * The AWS access key, used to identify the user interacting with services. 64 */ accessKeyId(String accessKeyId)65 Builder accessKeyId(String accessKeyId); 66 67 /** 68 * The AWS secret access key, used to authenticate the user interacting with services. 69 */ secretAccessKey(String secretAccessKey)70 Builder secretAccessKey(String secretAccessKey); 71 build()72 AwsCredentialsIdentity build(); 73 } 74 } 75