Skip to content

Commit 4ff4710

Browse files
committed
Merge branch 'feature/master/sra-identity-auth' into haydenbaker/sra-ia-signer-interfaces
2 parents 158c894 + 28ddc60 commit 4ff4710

29 files changed

+1508
-270
lines changed

core/http-auth-spi/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
<artifactId>reactive-streams</artifactId>
5555
<version>${reactive-streams.version}</version>
5656
</dependency>
57+
<dependency>
58+
<groupId>software.amazon.awssdk</groupId>
59+
<artifactId>identity-spi</artifactId>
60+
<version>${awsjavasdk.version}</version>
61+
</dependency>
5762

5863
<dependency>
5964
<groupId>org.junit.jupiter</groupId>
@@ -65,6 +70,11 @@
6570
<artifactId>equalsverifier</artifactId>
6671
<scope>test</scope>
6772
</dependency>
73+
<dependency>
74+
<groupId>org.mockito</groupId>
75+
<artifactId>mockito-core</artifactId>
76+
<scope>test</scope>
77+
</dependency>
6878
</dependencies>
6979

7080
<build>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.http.auth.spi;
17+
18+
import java.nio.ByteBuffer;
19+
import org.reactivestreams.Publisher;
20+
import software.amazon.awssdk.annotations.Immutable;
21+
import software.amazon.awssdk.annotations.SdkPublicApi;
22+
import software.amazon.awssdk.annotations.ThreadSafe;
23+
import software.amazon.awssdk.http.auth.spi.internal.DefaultAsyncHttpSignRequest;
24+
import software.amazon.awssdk.identity.spi.Identity;
25+
import software.amazon.awssdk.utils.builder.SdkBuilder;
26+
27+
/**
28+
* Input parameters to sign a request with async payload, using {@link HttpSigner}.
29+
*
30+
* @param <IdentityT> The type of the identity.
31+
*/
32+
@SdkPublicApi
33+
@Immutable
34+
@ThreadSafe
35+
public interface AsyncHttpSignRequest<IdentityT extends Identity> extends HttpSignRequest<Publisher<ByteBuffer>, IdentityT> {
36+
/**
37+
* Get a new builder for creating a {@link AsyncHttpSignRequest}.
38+
*/
39+
static <IdentityT extends Identity> Builder<IdentityT> builder(IdentityT identity) {
40+
return new DefaultAsyncHttpSignRequest.BuilderImpl<>(identity);
41+
}
42+
43+
/**
44+
* A builder for a {@link AsyncHttpSignRequest}.
45+
*/
46+
interface Builder<IdentityT extends Identity>
47+
extends HttpSignRequest.Builder<Builder<IdentityT>, Publisher<ByteBuffer>, IdentityT>,
48+
SdkBuilder<Builder<IdentityT>, AsyncHttpSignRequest<IdentityT>> {
49+
}
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.http.auth.spi;
17+
18+
import java.nio.ByteBuffer;
19+
import org.reactivestreams.Publisher;
20+
import software.amazon.awssdk.annotations.Immutable;
21+
import software.amazon.awssdk.annotations.SdkPublicApi;
22+
import software.amazon.awssdk.annotations.ThreadSafe;
23+
import software.amazon.awssdk.http.auth.spi.internal.DefaultAsyncSignedHttpRequest;
24+
import software.amazon.awssdk.utils.builder.SdkBuilder;
25+
26+
/**
27+
* Represents a request with async payload that has been signed by {@link HttpSigner}.
28+
*/
29+
@SdkPublicApi
30+
@Immutable
31+
@ThreadSafe
32+
public interface AsyncSignedHttpRequest extends SignedHttpRequest<Publisher<ByteBuffer>> {
33+
34+
/**
35+
* Get a new builder for creating a {@link AsyncSignedHttpRequest}.
36+
*/
37+
static Builder builder() {
38+
return new DefaultAsyncSignedHttpRequest.BuilderImpl();
39+
}
40+
41+
/**
42+
* A builder for a {@link AsyncSignedHttpRequest}.
43+
*/
44+
interface Builder extends SignedHttpRequest.Builder<Builder, Publisher<ByteBuffer>>,
45+
SdkBuilder<Builder, AsyncSignedHttpRequest> {
46+
}
47+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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.http.auth.spi;
17+
18+
import software.amazon.awssdk.annotations.SdkProtectedApi;
19+
import software.amazon.awssdk.http.auth.spi.internal.DefaultHttpAuthOption;
20+
import software.amazon.awssdk.identity.spi.IdentityProperty;
21+
import software.amazon.awssdk.utils.builder.SdkBuilder;
22+
23+
/**
24+
* An authentication scheme option, composed of the scheme ID and properties for use when resolving the identity and signing
25+
* the request.
26+
* <p>
27+
* This is used in the output from the auth scheme resolver. The resolver returns a list of these, in the order the auth scheme
28+
* resolver wishes to use them.
29+
*
30+
* @see HttpAuthScheme
31+
*/
32+
@SdkProtectedApi
33+
public interface HttpAuthOption {
34+
35+
/**
36+
* Get a new builder for creating a {@link HttpAuthOption}.
37+
*/
38+
static Builder builder() {
39+
return new DefaultHttpAuthOption.BuilderImpl();
40+
}
41+
42+
/**
43+
* Retrieve the scheme ID, a unique identifier for the authentication scheme (aws.auth#sigv4, smithy.api#httpBearerAuth).
44+
*/
45+
String schemeId();
46+
47+
/**
48+
* Retrieve the value of an {@link IdentityProperty}.
49+
*/
50+
<T> T identityProperty(IdentityProperty<T> property);
51+
52+
/**
53+
* Retrieve the value of an {@link SignerProperty}.
54+
*/
55+
<T> T signerProperty(SignerProperty<T> property);
56+
57+
/**
58+
* A method to operate on all {@link IdentityProperty} values of this HttpAuthOption.
59+
*/
60+
<T> void forEachIdentityProperty(IdentityPropertyConsumer consumer);
61+
62+
/**
63+
* A method to operate on all {@link SignerProperty} values of this HttpAuthOption.
64+
*/
65+
<T> void forEachSignerProperty(SignerPropertyConsumer consumer);
66+
67+
/**
68+
* Interface for operating on an {@link IdentityProperty} value.
69+
*/
70+
@FunctionalInterface
71+
interface IdentityPropertyConsumer {
72+
<T> void accept(IdentityProperty<T> propertyKey, T propertyValue);
73+
}
74+
75+
/**
76+
* Interface for operating on an {@link SignerProperty} value.
77+
*/
78+
@FunctionalInterface
79+
interface SignerPropertyConsumer {
80+
<T> void accept(SignerProperty<T> propertyKey, T propertyValue);
81+
}
82+
83+
interface Builder extends SdkBuilder<Builder, HttpAuthOption> {
84+
Builder schemeId(String schemeId);
85+
86+
<T> Builder putIdentityProperty(IdentityProperty<T> key, T value);
87+
88+
<T> Builder putSignerProperty(SignerProperty<T> key, T value);
89+
}
90+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.http.auth.spi;
17+
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
20+
import software.amazon.awssdk.identity.spi.Identity;
21+
import software.amazon.awssdk.identity.spi.IdentityProvider;
22+
import software.amazon.awssdk.identity.spi.TokenIdentity;
23+
24+
/**
25+
* An authentication scheme, composed of:
26+
* <ol>
27+
* <li>A scheme ID - A unique identifier for the authentication scheme.</li>
28+
* <li>An identity provider - An API that can be queried to acquire the customer's identity.</li>
29+
* <li>A signer - An API that can be used to sign HTTP requests.</li>
30+
* </ol>
31+
*
32+
* @see IdentityProvider
33+
* @see HttpSigner
34+
*
35+
* @param <T> The type of the {@link Identity} used by this authentication scheme.
36+
*/
37+
@SdkPublicApi
38+
public interface HttpAuthScheme<T extends Identity> {
39+
40+
/**
41+
* Retrieve the scheme ID, a unique identifier for the authentication scheme (aws.auth#sigv4, smithy.api#httpBearerAuth).
42+
*/
43+
String schemeId();
44+
45+
/**
46+
* Retrieve the identity provider associated with this authentication scheme. The identity generated by this provider is
47+
* guaranteed to be supported by the signer in this authentication scheme.
48+
* <p>
49+
* For example, if the scheme ID is aws.auth#sigv4, the provider returns an {@link AwsCredentialsIdentity}, if the scheme
50+
* ID is httpBearerAuth, the provider returns a {@link TokenIdentity}.
51+
* <p>
52+
* Note, the returned identity provider may differ from the type of identity provider retrieved from the provided identity
53+
* provider configuration.
54+
*/
55+
IdentityProvider<T> identityProvider(IdentityProviderConfiguration providers);
56+
57+
/**
58+
* Retrieve the signer associated with this authentication scheme. This signer is guaranteed to support the identity
59+
* generated by the identity provider in this authentication scheme.
60+
*/
61+
HttpSigner<T> signer();
62+
}

core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/HttpSignRequest.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,18 @@
2020
import software.amazon.awssdk.annotations.SdkPublicApi;
2121
import software.amazon.awssdk.annotations.ThreadSafe;
2222
import software.amazon.awssdk.http.SdkHttpRequest;
23-
import software.amazon.awssdk.http.auth.spi.internal.DefaultHttpSignRequest;
24-
import software.amazon.awssdk.utils.builder.SdkBuilder;
23+
import software.amazon.awssdk.identity.spi.Identity;
2524

2625
/**
27-
* Represents a request to be signed by {@link HttpSigner}.
26+
* Input parameters to sign a request using {@link HttpSigner}.
2827
*
29-
* @param <PayloadT> The type of payload of this request.
28+
* @param <PayloadT> The type of payload of the request.
29+
* @param <IdentityT> The type of the identity.
3030
*/
3131
@SdkPublicApi
3232
@Immutable
3333
@ThreadSafe
34-
public interface HttpSignRequest<PayloadT> {
35-
36-
/**
37-
* Get a new builder for creating a {@link HttpSignRequest}.
38-
*/
39-
static <PayloadT> Builder<PayloadT> builder(Class<PayloadT> payloadType) {
40-
return new DefaultHttpSignRequest.BuilderImpl<>(payloadType);
41-
}
42-
43-
/**
44-
* Returns the type of the payload.
45-
*/
46-
Class<PayloadT> payloadType();
34+
public interface HttpSignRequest<PayloadT, IdentityT extends Identity> {
4735

4836
/**
4937
* Returns the HTTP request object, without the request body payload.
@@ -56,29 +44,38 @@ static <PayloadT> Builder<PayloadT> builder(Class<PayloadT> payloadType) {
5644
Optional<PayloadT> payload();
5745

5846
/**
59-
* Returns the property that the {@link HttpSigner} can use during signing.
47+
* Returns the identity.
48+
*/
49+
IdentityT identity();
50+
51+
/**
52+
* Returns the value of a property that the {@link HttpSigner} can use during signing.
6053
*/
6154
<T> T property(SignerProperty<T> property);
6255

6356
/**
6457
* A builder for a {@link HttpSignRequest}.
6558
*/
66-
interface Builder<PayloadT> extends SdkBuilder<Builder<PayloadT>,
67-
HttpSignRequest<PayloadT>> {
59+
interface Builder<B extends Builder<B, PayloadT, IdentityT>, PayloadT, IdentityT extends Identity> {
6860

6961
/**
7062
* Set the HTTP request object, without the request body payload.
7163
*/
72-
Builder<PayloadT> request(SdkHttpRequest request);
64+
B request(SdkHttpRequest request);
7365

7466
/**
7567
* Set the body payload of the request. A payload is optional. By default, the payload will be empty.
7668
*/
77-
Builder<PayloadT> payload(PayloadT payload);
69+
B payload(PayloadT payload);
70+
71+
/**
72+
* Set the identity of the request.
73+
*/
74+
B identity(IdentityT identity);
7875

7976
/**
8077
* Set a property that the {@link HttpSigner} can use during signing.
8178
*/
82-
<T> Builder<PayloadT> putProperty(SignerProperty<T> key, T value);
79+
<T> B putProperty(SignerProperty<T> key, T value);
8380
}
8481
}

0 commit comments

Comments
 (0)