Skip to content

Commit 3d24f09

Browse files
authored
Add new Signer interfaces (#3967)
1 parent 22b30ec commit 3d24f09

File tree

9 files changed

+589
-0
lines changed

9 files changed

+589
-0
lines changed

core/http-auth-spi/pom.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<parent>
23+
<groupId>software.amazon.awssdk</groupId>
24+
<artifactId>core</artifactId>
25+
<version>2.20.47-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>http-auth-spi</artifactId>
29+
<name>AWS Java SDK :: HTTP Auth SPI</name>
30+
<description>
31+
The AWS SDK for Java - HTTP Auth SPI module contains the interfaces for authentication that are used by other
32+
modules in the library.
33+
</description>
34+
<url>https://aws.amazon.com/sdkforjava</url>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>software.amazon.awssdk</groupId>
39+
<artifactId>annotations</artifactId>
40+
<version>${awsjavasdk.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>software.amazon.awssdk</groupId>
44+
<artifactId>utils</artifactId>
45+
<version>${awsjavasdk.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>software.amazon.awssdk</groupId>
49+
<artifactId>http-client-spi</artifactId>
50+
<version>${awsjavasdk.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.reactivestreams</groupId>
54+
<artifactId>reactive-streams</artifactId>
55+
<version>${reactive-streams.version}</version>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.junit.jupiter</groupId>
60+
<artifactId>junit-jupiter</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>nl.jqno.equalsverifier</groupId>
65+
<artifactId>equalsverifier</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
</dependencies>
69+
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-jar-plugin</artifactId>
75+
<configuration>
76+
<archive>
77+
<manifestEntries>
78+
<Automatic-Module-Name>software.amazon.awssdk.http.auth.spi</Automatic-Module-Name>
79+
</manifestEntries>
80+
</archive>
81+
</configuration>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
86+
</project>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.util.Optional;
19+
import software.amazon.awssdk.annotations.Immutable;
20+
import software.amazon.awssdk.annotations.SdkPublicApi;
21+
import software.amazon.awssdk.annotations.ThreadSafe;
22+
import software.amazon.awssdk.http.SdkHttpRequest;
23+
import software.amazon.awssdk.http.auth.spi.internal.DefaultHttpSignRequest;
24+
import software.amazon.awssdk.utils.builder.SdkBuilder;
25+
26+
/**
27+
* Represents a request to be signed by {@link HttpSigner}.
28+
*
29+
* @param <PayloadT> The type of payload of this request.
30+
*/
31+
@SdkPublicApi
32+
@Immutable
33+
@ThreadSafe
34+
public interface HttpSignRequest<PayloadT> {
35+
36+
/**
37+
* Get a new builder for creating a {@link HttpSignRequest}.
38+
*/
39+
static <T> Builder<T> builder(Class<T> payloadType) {
40+
return new DefaultHttpSignRequest.BuilderImpl(payloadType);
41+
}
42+
43+
/**
44+
* Returns the type of the payload.
45+
*/
46+
Class<PayloadT> payloadType();
47+
48+
/**
49+
* Returns the HTTP request object, without the request body payload.
50+
*/
51+
SdkHttpRequest request();
52+
53+
/**
54+
* Returns the body payload of the request. A payload is optional. By default, the payload will be empty.
55+
*/
56+
Optional<PayloadT> payload();
57+
58+
/**
59+
* Returns the property that the {@link HttpSigner} can use during signing.
60+
*/
61+
<T> T property(SignerProperty<T> property);
62+
63+
/**
64+
* A builder for a {@link HttpSignRequest}.
65+
*/
66+
interface Builder<PayloadT> extends SdkBuilder<Builder<PayloadT>, HttpSignRequest> {
67+
68+
/**
69+
* Set the HTTP request object, without the request body payload.
70+
*/
71+
Builder request(SdkHttpRequest request);
72+
73+
/**
74+
* Set the body payload of the request. A payload is optional. By default, the payload will be empty.
75+
*/
76+
Builder payload(PayloadT payload);
77+
78+
/**
79+
* Set a property that the {@link HttpSigner} can use during signing.
80+
*/
81+
<T> Builder putProperty(SignerProperty<T> key, T value);
82+
}
83+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.SdkPublicApi;
21+
import software.amazon.awssdk.http.ContentStreamProvider;
22+
23+
/**
24+
* Interface for the process of modifying a request destined for a service so that the service can authenticate the SDK
25+
* customer’s identity
26+
*/
27+
@SdkPublicApi
28+
public interface HttpSigner {
29+
30+
/**
31+
* Method that takes in a request and returns a signed version of the request.
32+
*
33+
* @param request The request to sign, with sync payload
34+
* @return A signed version of the input request
35+
*/
36+
SignedHttpRequest<ContentStreamProvider> sign(HttpSignRequest<? extends ContentStreamProvider> request);
37+
38+
/**
39+
* Method that takes in a request and returns a signed version of the request.
40+
*
41+
* @param request The request to sign, with async payload
42+
* @return A signed version of the input request
43+
*/
44+
SignedHttpRequest<Publisher<ByteBuffer>> signAsync(HttpSignRequest<? extends Publisher<? extends ByteBuffer>> request);
45+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.util.Optional;
19+
import software.amazon.awssdk.annotations.Immutable;
20+
import software.amazon.awssdk.annotations.SdkPublicApi;
21+
import software.amazon.awssdk.annotations.ThreadSafe;
22+
import software.amazon.awssdk.http.SdkHttpRequest;
23+
import software.amazon.awssdk.http.auth.spi.internal.DefaultSignedHttpRequest;
24+
import software.amazon.awssdk.utils.builder.SdkBuilder;
25+
26+
/**
27+
* Represents a request that has been signed by {@link HttpSigner}.
28+
*
29+
* @param <PayloadT> The type of payload of this request.
30+
*/
31+
@SdkPublicApi
32+
@Immutable
33+
@ThreadSafe
34+
public interface SignedHttpRequest<PayloadT> {
35+
36+
/**
37+
* Get a new builder for creating a {@link SignedHttpRequest}.
38+
*/
39+
static <T> Builder<T> builder(Class<T> payloadType) {
40+
return new DefaultSignedHttpRequest.BuilderImpl(payloadType);
41+
}
42+
43+
/**
44+
* Returns the type of the payload.
45+
*/
46+
Class<PayloadT> payloadType();
47+
48+
/**
49+
* Returns the HTTP request object, without the request body payload.
50+
*/
51+
SdkHttpRequest request();
52+
53+
/**
54+
* Returns the body payload of the request. A payload is optional. By default, the payload will be empty.
55+
*/
56+
Optional<PayloadT> payload();
57+
58+
/**
59+
* A builder for a {@link SignedHttpRequest}.
60+
*/
61+
interface Builder<PayloadT> extends SdkBuilder<Builder<PayloadT>, SignedHttpRequest> {
62+
63+
/**
64+
* Set the HTTP request object, without the request body payload.
65+
*/
66+
Builder request(SdkHttpRequest request);
67+
68+
/**
69+
* Set the body payload of the request. A payload is optional. By default, the payload will be empty.
70+
*/
71+
Builder payload(PayloadT payload);
72+
}
73+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.util.Objects;
19+
import software.amazon.awssdk.annotations.Immutable;
20+
import software.amazon.awssdk.annotations.SdkPublicApi;
21+
import software.amazon.awssdk.annotations.ThreadSafe;
22+
import software.amazon.awssdk.utils.ToString;
23+
import software.amazon.awssdk.utils.Validate;
24+
25+
/**
26+
* A strongly-typed property for input to an {@link HttpSigner}.
27+
* @param <T> The type of the attribute.
28+
*/
29+
@SdkPublicApi
30+
@Immutable
31+
@ThreadSafe
32+
public final class SignerProperty<T> {
33+
private final Class<T> clazz;
34+
private final String name;
35+
36+
private SignerProperty(Class<T> clazz, String name) {
37+
Validate.paramNotNull(clazz, "clazz");
38+
Validate.paramNotBlank(name, "name");
39+
40+
this.clazz = clazz;
41+
this.name = name;
42+
}
43+
44+
public static <T> SignerProperty<T> create(Class<T> clazz, String name) {
45+
return new SignerProperty<>(clazz, name);
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return ToString.builder("SignerProperty")
51+
.add("clazz", clazz)
52+
.add("name", name)
53+
.build();
54+
}
55+
56+
@Override
57+
public boolean equals(Object o) {
58+
if (this == o) {
59+
return true;
60+
}
61+
if (o == null || getClass() != o.getClass()) {
62+
return false;
63+
}
64+
65+
SignerProperty<?> that = (SignerProperty<?>) o;
66+
67+
return Objects.equals(clazz, that.clazz) &&
68+
Objects.equals(name, that.name);
69+
}
70+
71+
@Override
72+
public int hashCode() {
73+
int hashCode = 1;
74+
hashCode = 31 * hashCode + Objects.hashCode(clazz);
75+
hashCode = 31 * hashCode + Objects.hashCode(name);
76+
return hashCode;
77+
}
78+
}

0 commit comments

Comments
 (0)