-
Notifications
You must be signed in to change notification settings - Fork 916
Add new Signer interfaces #3967
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 all commits
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,86 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>core</artifactId> | ||
<version>2.20.47-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>http-auth-spi</artifactId> | ||
<name>AWS Java SDK :: HTTP Auth SPI</name> | ||
<description> | ||
The AWS SDK for Java - HTTP Auth SPI module contains the interfaces for authentication that are used by other | ||
modules in the library. | ||
</description> | ||
<url>https://aws.amazon.com/sdkforjava</url> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>annotations</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>utils</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>http-client-spi</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.reactivestreams</groupId> | ||
<artifactId>reactive-streams</artifactId> | ||
<version>${reactive-streams.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>nl.jqno.equalsverifier</groupId> | ||
<artifactId>equalsverifier</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>software.amazon.awssdk.http.auth.spi</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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 java.util.Optional; | ||
import software.amazon.awssdk.annotations.Immutable; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.annotations.ThreadSafe; | ||
import software.amazon.awssdk.http.SdkHttpRequest; | ||
import software.amazon.awssdk.http.auth.spi.internal.DefaultHttpSignRequest; | ||
import software.amazon.awssdk.utils.builder.SdkBuilder; | ||
|
||
/** | ||
* Represents a request to be signed by {@link HttpSigner}. | ||
* | ||
* @param <PayloadT> The type of payload of this request. | ||
*/ | ||
@SdkPublicApi | ||
@Immutable | ||
@ThreadSafe | ||
public interface HttpSignRequest<PayloadT> { | ||
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. Not a blocker, should it be 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 as per design doc. cc'ing @millems. I think this is following the similar pattern for ResolveIdentityRequest used as parameter in |
||
|
||
/** | ||
* Get a new builder for creating a {@link HttpSignRequest}. | ||
*/ | ||
static <T> Builder<T> builder(Class<T> payloadType) { | ||
return new DefaultHttpSignRequest.BuilderImpl(payloadType); | ||
} | ||
|
||
/** | ||
* Returns the type of the payload. | ||
*/ | ||
Class<PayloadT> payloadType(); | ||
|
||
/** | ||
* Returns the HTTP request object, without the request body payload. | ||
*/ | ||
SdkHttpRequest request(); | ||
|
||
/** | ||
* Returns the body payload of the request. A payload is optional. By default, the payload will be empty. | ||
*/ | ||
Optional<PayloadT> payload(); | ||
|
||
/** | ||
* Returns the property that the {@link HttpSigner} can use during signing. | ||
*/ | ||
<T> T property(SignerProperty<T> property); | ||
|
||
/** | ||
* A builder for a {@link HttpSignRequest}. | ||
*/ | ||
interface Builder<PayloadT> extends SdkBuilder<Builder<PayloadT>, HttpSignRequest> { | ||
|
||
/** | ||
* Set the HTTP request object, without the request body payload. | ||
*/ | ||
Builder request(SdkHttpRequest request); | ||
|
||
/** | ||
* Set the body payload of the request. A payload is optional. By default, the payload will be empty. | ||
*/ | ||
Builder payload(PayloadT payload); | ||
|
||
/** | ||
* Set a property that the {@link HttpSigner} can use during signing. | ||
*/ | ||
<T> Builder putProperty(SignerProperty<T> key, T value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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 java.nio.ByteBuffer; | ||
import org.reactivestreams.Publisher; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.http.ContentStreamProvider; | ||
|
||
/** | ||
* Interface for the process of modifying a request destined for a service so that the service can authenticate the SDK | ||
* customer’s identity | ||
*/ | ||
@SdkPublicApi | ||
public interface HttpSigner { | ||
|
||
/** | ||
* Method that takes in a request and returns a signed version of the request. | ||
* | ||
* @param request The request to sign, with sync payload | ||
* @return A signed version of the input request | ||
*/ | ||
SignedHttpRequest<ContentStreamProvider> sign(HttpSignRequest<? extends ContentStreamProvider> request); | ||
|
||
/** | ||
* Method that takes in a request and returns a signed version of the request. | ||
* | ||
* @param request The request to sign, with async payload | ||
* @return A signed version of the input request | ||
*/ | ||
SignedHttpRequest<Publisher<ByteBuffer>> signAsync(HttpSignRequest<? extends Publisher<? extends ByteBuffer>> request); | ||
} |
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.http.auth.spi; | ||
|
||
import java.util.Optional; | ||
import software.amazon.awssdk.annotations.Immutable; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.annotations.ThreadSafe; | ||
import software.amazon.awssdk.http.SdkHttpRequest; | ||
import software.amazon.awssdk.http.auth.spi.internal.DefaultSignedHttpRequest; | ||
import software.amazon.awssdk.utils.builder.SdkBuilder; | ||
|
||
/** | ||
* Represents a request that has been signed by {@link HttpSigner}. | ||
* | ||
* @param <PayloadT> The type of payload of this request. | ||
*/ | ||
@SdkPublicApi | ||
@Immutable | ||
@ThreadSafe | ||
public interface SignedHttpRequest<PayloadT> { | ||
|
||
/** | ||
* Get a new builder for creating a {@link SignedHttpRequest}. | ||
*/ | ||
static <T> Builder<T> builder(Class<T> payloadType) { | ||
return new DefaultSignedHttpRequest.BuilderImpl(payloadType); | ||
} | ||
|
||
/** | ||
* Returns the type of the payload. | ||
*/ | ||
Class<PayloadT> payloadType(); | ||
|
||
/** | ||
* Returns the HTTP request object, without the request body payload. | ||
*/ | ||
SdkHttpRequest request(); | ||
|
||
/** | ||
* Returns the body payload of the request. A payload is optional. By default, the payload will be empty. | ||
*/ | ||
Optional<PayloadT> payload(); | ||
|
||
/** | ||
* A builder for a {@link SignedHttpRequest}. | ||
*/ | ||
interface Builder<PayloadT> extends SdkBuilder<Builder<PayloadT>, SignedHttpRequest> { | ||
|
||
/** | ||
* Set the HTTP request object, without the request body payload. | ||
*/ | ||
Builder request(SdkHttpRequest request); | ||
|
||
/** | ||
* Set the body payload of the request. A payload is optional. By default, the payload will be empty. | ||
*/ | ||
Builder payload(PayloadT payload); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 java.util.Objects; | ||
import software.amazon.awssdk.annotations.Immutable; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.annotations.ThreadSafe; | ||
import software.amazon.awssdk.utils.ToString; | ||
import software.amazon.awssdk.utils.Validate; | ||
|
||
/** | ||
* A strongly-typed property for input to an {@link HttpSigner}. | ||
* @param <T> The type of the attribute. | ||
*/ | ||
@SdkPublicApi | ||
@Immutable | ||
@ThreadSafe | ||
public final class SignerProperty<T> { | ||
private final Class<T> clazz; | ||
private final String name; | ||
|
||
private SignerProperty(Class<T> clazz, String name) { | ||
Validate.paramNotNull(clazz, "clazz"); | ||
Validate.paramNotBlank(name, "name"); | ||
|
||
this.clazz = clazz; | ||
this.name = name; | ||
} | ||
|
||
public static <T> SignerProperty<T> create(Class<T> clazz, String name) { | ||
return new SignerProperty<>(clazz, name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToString.builder("SignerProperty") | ||
.add("clazz", clazz) | ||
.add("name", name) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
SignerProperty<?> that = (SignerProperty<?>) o; | ||
|
||
return Objects.equals(clazz, that.clazz) && | ||
Objects.equals(name, that.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
gosar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int hashCode = 1; | ||
hashCode = 31 * hashCode + Objects.hashCode(clazz); | ||
hashCode = 31 * hashCode + Objects.hashCode(name); | ||
return hashCode; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.