-
Notifications
You must be signed in to change notification settings - Fork 916
Add main auth scheme interfaces #3999
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
Merged
gosar
merged 3 commits into
feature/master/sra-identity-auth
from
gosar/sra-ia-scheme-interfaces
May 16, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/HttpAuthOption.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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.http.auth.spi; | ||
|
||
import software.amazon.awssdk.annotations.SdkProtectedApi; | ||
import software.amazon.awssdk.http.auth.spi.internal.DefaultHttpAuthOption; | ||
import software.amazon.awssdk.identity.spi.IdentityProperty; | ||
import software.amazon.awssdk.utils.builder.SdkBuilder; | ||
|
||
/** | ||
* An authentication scheme option, composed of the scheme ID and properties for use when resolving the identity and signing | ||
* the request. | ||
* <p> | ||
* This is used in the output from the auth scheme resolver. The resolver returns a list of these, in the order the auth scheme | ||
* resolver wishes to use them. | ||
* | ||
* @see HttpAuthScheme | ||
*/ | ||
@SdkProtectedApi | ||
public interface HttpAuthOption { | ||
|
||
/** | ||
* Get a new builder for creating a {@link HttpAuthOption}. | ||
*/ | ||
static Builder builder() { | ||
return new DefaultHttpAuthOption.BuilderImpl(); | ||
} | ||
|
||
/** | ||
* Retrieve the scheme ID, a unique identifier for the authentication scheme (aws.auth#sigv4, smithy.api#httpBearerAuth). | ||
*/ | ||
String schemeId(); | ||
|
||
/** | ||
* Retrieve the value of an {@link IdentityProperty}. | ||
*/ | ||
<T> T identityProperty(IdentityProperty<T> property); | ||
|
||
/** | ||
* Retrieve the value of an {@link SignerProperty}. | ||
*/ | ||
<T> T signerProperty(SignerProperty<T> property); | ||
|
||
/** | ||
* A method to operate on all {@link IdentityProperty} values of this HttpAuthOption. | ||
*/ | ||
<T> void forEachIdentityProperty(IdentityPropertyConsumer consumer); | ||
|
||
/** | ||
* A method to operate on all {@link SignerProperty} values of this HttpAuthOption. | ||
*/ | ||
<T> void forEachSignerProperty(SignerPropertyConsumer consumer); | ||
|
||
/** | ||
* Interface for operating on an {@link IdentityProperty} value. | ||
*/ | ||
@FunctionalInterface | ||
interface IdentityPropertyConsumer { | ||
<T> void accept(IdentityProperty<T> propertyKey, T propertyValue); | ||
} | ||
|
||
/** | ||
* Interface for operating on an {@link SignerProperty} value. | ||
*/ | ||
@FunctionalInterface | ||
interface SignerPropertyConsumer { | ||
<T> void accept(SignerProperty<T> propertyKey, T propertyValue); | ||
} | ||
|
||
interface Builder extends SdkBuilder<Builder, HttpAuthOption> { | ||
cenedhryn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<T> Builder schemeId(String schemeId); | ||
|
||
<T> Builder putIdentityProperty(IdentityProperty<T> key, T value); | ||
|
||
<T> Builder putSignerProperty(SignerProperty<T> key, T value); | ||
gosar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/HttpAuthScheme.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.http.auth.spi; | ||
|
||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; | ||
import software.amazon.awssdk.identity.spi.Identity; | ||
import software.amazon.awssdk.identity.spi.IdentityProvider; | ||
import software.amazon.awssdk.identity.spi.TokenIdentity; | ||
|
||
/** | ||
* An authentication scheme, composed of: | ||
* <ol> | ||
* <li>A scheme ID - A unique identifier for the authentication scheme.</li> | ||
* <li>An identity provider - An API that can be queried to acquire the customer's identity.</li> | ||
* <li>A signer - An API that can be used to sign HTTP requests.</li> | ||
* </ol> | ||
* | ||
* @see IdentityProvider | ||
* @see HttpSigner | ||
* | ||
* @param <T> The type of the {@link Identity} used by this authentication scheme. | ||
*/ | ||
@SdkPublicApi | ||
public interface HttpAuthScheme<T extends Identity> { | ||
|
||
/** | ||
* Retrieve the scheme ID, a unique identifier for the authentication scheme (aws.auth#sigv4, smithy.api#httpBearerAuth). | ||
*/ | ||
String schemeId(); | ||
|
||
/** | ||
* Retrieve the identity provider associated with this authentication scheme. The identity generated by this provider is | ||
* guaranteed to be supported by the signer in this authentication scheme. | ||
* <p> | ||
* For example, if the scheme ID is aws.auth#sigv4, the provider returns an {@link AwsCredentialsIdentity}, if the scheme | ||
* ID is httpBearerAuth, the provider returns a {@link TokenIdentity}. | ||
* <p> | ||
* Note, the returned identity provider may differ from the type of identity provider retrieved from the provided identity | ||
* provider configuration. | ||
*/ | ||
IdentityProvider<T> identityProvider(IdentityProviderConfiguration providers); | ||
|
||
/** | ||
* Retrieve the signer associated with this authentication scheme. This signer is guaranteed to support the identity | ||
* generated by the identity provider in this authentication scheme. | ||
*/ | ||
HttpSigner signer(); | ||
} |
36 changes: 36 additions & 0 deletions
36
...spi/src/main/java/software/amazon/awssdk/http/auth/spi/IdentityProviderConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.http.auth.spi; | ||
|
||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.identity.spi.Identity; | ||
import software.amazon.awssdk.identity.spi.IdentityProvider; | ||
|
||
/** | ||
* The identity providers configured in the SDK. | ||
* <p> | ||
* Used by the {@link HttpAuthScheme} implementation to load any @{@link IdentityProvider}s it needs from the set that are | ||
* configured on the SDK. | ||
*/ | ||
@SdkPublicApi | ||
@FunctionalInterface | ||
public interface IdentityProviderConfiguration { | ||
cenedhryn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Retrieve an identity provider for the provided identity type. | ||
*/ | ||
<T extends Identity> IdentityProvider<T> identityProvider(Class<T> identityType); | ||
} |
108 changes: 108 additions & 0 deletions
108
...pi/src/main/java/software/amazon/awssdk/http/auth/spi/internal/DefaultHttpAuthOption.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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.http.auth.spi.internal; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
import software.amazon.awssdk.http.auth.spi.HttpAuthOption; | ||
import software.amazon.awssdk.http.auth.spi.SignerProperty; | ||
import software.amazon.awssdk.identity.spi.IdentityProperty; | ||
import software.amazon.awssdk.utils.ToString; | ||
import software.amazon.awssdk.utils.Validate; | ||
|
||
@SdkInternalApi | ||
public final class DefaultHttpAuthOption implements HttpAuthOption { | ||
|
||
private final String schemeId; | ||
private final Map<IdentityProperty<?>, Object> identityProperties; | ||
private final Map<SignerProperty<?>, Object> signerProperties; | ||
|
||
DefaultHttpAuthOption(BuilderImpl builder) { | ||
this.schemeId = Validate.paramNotBlank(builder.schemeId, "schemeId"); | ||
this.identityProperties = new HashMap<>(builder.identityProperties); | ||
this.signerProperties = new HashMap<>(builder.signerProperties); | ||
} | ||
|
||
@Override | ||
public String schemeId() { | ||
return schemeId; | ||
} | ||
|
||
@Override | ||
public <T> T identityProperty(IdentityProperty<T> property) { | ||
return (T) identityProperties.get(property); | ||
} | ||
|
||
@Override | ||
public <T> T signerProperty(SignerProperty<T> property) { | ||
return (T) signerProperties.get(property); | ||
} | ||
|
||
@Override | ||
public <T> void forEachIdentityProperty(IdentityPropertyConsumer consumer) { | ||
for (IdentityProperty<?> p : identityProperties.keySet()) { | ||
IdentityProperty<T> property = (IdentityProperty<T>) p; | ||
consumer.accept(property, this.identityProperty(property)); | ||
} | ||
} | ||
|
||
@Override | ||
public <T> void forEachSignerProperty(SignerPropertyConsumer consumer) { | ||
for (SignerProperty<?> p : signerProperties.keySet()) { | ||
SignerProperty<T> property = (SignerProperty<T>) p; | ||
consumer.accept(property, this.signerProperty(property)); | ||
} | ||
Comment on lines
+65
to
+68
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. Maybe there is a better way to do this. |
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToString.builder("HttpAuthOption") | ||
.add("identityProperties", identityProperties) | ||
.add("signerProperties", signerProperties) | ||
gosar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.build(); | ||
} | ||
|
||
|
||
public static final class BuilderImpl implements Builder { | ||
private String schemeId; | ||
private final Map<IdentityProperty<?>, Object> identityProperties = new HashMap<>(); | ||
private final Map<SignerProperty<?>, Object> signerProperties = new HashMap<>(); | ||
|
||
@Override | ||
public <T> Builder schemeId(String schemeId) { | ||
this.schemeId = schemeId; | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> Builder putIdentityProperty(IdentityProperty<T> key, T value) { | ||
this.identityProperties.put(key, value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> Builder putSignerProperty(SignerProperty<T> key, T value) { | ||
this.signerProperties.put(key, value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public HttpAuthOption build() { | ||
return new DefaultHttpAuthOption(this); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.