-
Notifications
You must be signed in to change notification settings - Fork 916
Add new Identity interfaces #3773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
7a8f551
04fd713
b2a44e8
444848d
f03400a
acbd8bf
c6f4a58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.identity.spi; | ||
|
||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
|
||
/** | ||
* Provides access to the AWS credentials used for accessing services: AWS access key ID and secret access key. These | ||
* credentials are used to securely sign requests to services (e.g., AWS services) that use them for authentication. | ||
* | ||
* <p>For more details on AWS access keys, see: | ||
* <a href="https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys"> | ||
* https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys</a></p> | ||
*/ | ||
@SdkPublicApi | ||
public interface AwsCredentialsIdentity extends Identity { | ||
|
||
static AwsCredentialsIdentity create(String accessKeyId, | ||
String secretAccessKey) { | ||
return new AwsCredentialsIdentityImpl(accessKeyId, secretAccessKey); | ||
gosar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
static AwsSessionCredentialsIdentity create(String accessKeyId, | ||
String secretAccessKey, | ||
String sessionToken) { | ||
return new AwsSessionCredentialsIdentityImpl(accessKeyId, secretAccessKey, sessionToken); | ||
} | ||
|
||
/** | ||
* Retrieve the AWS access key, used to identify the user interacting with services. | ||
*/ | ||
String accessKeyId(); | ||
|
||
/** | ||
* Retrieve the AWS secret access key, used to authenticate the user interacting with services. | ||
*/ | ||
String secretAccessKey(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.identity.spi; | ||
|
||
import java.util.Objects; | ||
import software.amazon.awssdk.annotations.Immutable; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
import software.amazon.awssdk.utils.ToString; | ||
import software.amazon.awssdk.utils.Validate; | ||
|
||
@Immutable | ||
@SdkInternalApi | ||
final class AwsCredentialsIdentityImpl implements AwsCredentialsIdentity { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen any mention in the design doc of a direct implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to support the static create methods in AwsCredentialsIdentity which are called out in the design doc. Cannot use the existing AwsBasicCredentials as that would be a circular dependency, so defined copies of them here as @SdkInternalApi and package-private. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're also discussing offline, but if we do decide to keep them they should be in an internal subpackage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd vote for removing those classes. They are implementation details and we'd need to maintain two copies of the same implementations. We could consider creating a factory class in auth module that makes it easier for people to create static credentials. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 removed for now. |
||
|
||
private final String accessKeyId; | ||
private final String secretAccessKey; | ||
|
||
AwsCredentialsIdentityImpl(String accessKeyId, String secretAccessKey) { | ||
this.accessKeyId = Validate.paramNotNull(accessKeyId, "accessKeyId"); | ||
this.secretAccessKey = Validate.paramNotNull(secretAccessKey, "secretAccessKey"); | ||
} | ||
|
||
@Override | ||
public String accessKeyId() { | ||
return accessKeyId; | ||
} | ||
|
||
@Override | ||
public String secretAccessKey() { | ||
return secretAccessKey; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToString.builder("AwsCredentialsIdentityImpl") | ||
.add("accessKeyId", accessKeyId) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AwsCredentialsIdentityImpl that = (AwsCredentialsIdentityImpl) o; | ||
return Objects.equals(accessKeyId, that.accessKeyId) && | ||
Objects.equals(secretAccessKey, that.secretAccessKey); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hashCode = 1; | ||
hashCode = 31 * hashCode + Objects.hashCode(accessKeyId()); | ||
hashCode = 31 * hashCode + Objects.hashCode(secretAccessKey()); | ||
return hashCode; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.identity.spi; | ||
|
||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
|
||
/** | ||
* A special type of {@link AwsCredentialsIdentity} that provides a session token to be used in service authentication. Session | ||
* tokens are typically provided by a token broker service, like AWS Security Token Service, and provide temporary access to an | ||
* AWS service. | ||
*/ | ||
@SdkPublicApi | ||
public interface AwsSessionCredentialsIdentity extends AwsCredentialsIdentity { | ||
|
||
/** | ||
* Retrieve the AWS session token. This token is retrieved from an AWS token service, and is used for authenticating that this | ||
* user has received temporary permission to access some resource. | ||
*/ | ||
String sessionToken(); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.