java.lang.Object
software.amazon.awssdk.auth.signer.internal.AbstractAwsSigner
software.amazon.awssdk.auth.signer.internal.AbstractAws4Signer<software.amazon.awssdk.auth.signer.params.Aws4SignerParams,software.amazon.awssdk.auth.signer.params.Aws4PresignerParams>
software.amazon.awssdk.auth.signer.internal.BaseAws4Signer
com.erudika.para.core.rest.Signer
- All Implemented Interfaces:
software.amazon.awssdk.core.signer.Presigner,software.amazon.awssdk.core.signer.Signer
public final class Signer
extends software.amazon.awssdk.auth.signer.internal.BaseAws4Signer
This class extends
BaseAws4Signer implementing the AWS Signature Version 4 algorithm.
Also contains a method for signature validation. The signatures that this class produces are
compatible with the original AWS SDK implementation.- Author:
- Alex Bogdanovski [alex@erudika.com]
-
Field Summary
Fields inherited from class software.amazon.awssdk.auth.signer.internal.AbstractAws4Signer
EMPTY_STRING_SHA256_HEX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DateparseAWSDate(String date) Returns a parsed Date.static InstantparseAWSInstant(String date) Returns a parsed Instant.sign(String httpeMethod, String endpoint, String resourcePath, Map<String, String> headers, Map<String, String> params, InputStream entity, String accessKey, String secretKey) Signs a request using AWS signature V4.software.amazon.awssdk.http.SdkHttpFullRequestsign(software.amazon.awssdk.http.SdkHttpFullRequest request, String accessKey, String secretKey, Clock override) Signs a request using AWS signature V4.signRequest(String accessKey, String secretKey, String httpMethod, String endpointURL, String reqPath, Map<String, String> headers, jakarta.ws.rs.core.MultivaluedMap<String, String> params, byte[] jsonEntity) Builds and signs a request to an API endpoint using the provided credentials.Methods inherited from class software.amazon.awssdk.auth.signer.internal.BaseAws4Signer
presign, presign, sign, signMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface software.amazon.awssdk.core.signer.Signer
credentialType
-
Constructor Details
-
Signer
public Signer()No-args constructor.
-
-
Method Details
-
sign
public Map<String,String> sign(String httpeMethod, String endpoint, String resourcePath, Map<String, String> headers, Map<String, String> params, InputStream entity, String accessKey, String secretKey) Signs a request using AWS signature V4.- Parameters:
httpeMethod- GET/POST/PUT... etc.endpoint- the hostname of the API serverresourcePath- the path of the resource (starting from root e.g. "/path/to/res")headers- the headers mapparams- the params mapentity- the entity object or nullaccessKey- the app's access keysecretKey- the app's secret key- Returns:
- a signed request. The actual signature is inside the
Authorizationheader.
-
sign
public software.amazon.awssdk.http.SdkHttpFullRequest sign(software.amazon.awssdk.http.SdkHttpFullRequest request, String accessKey, String secretKey, Clock override) Signs a request using AWS signature V4.- Parameters:
request- the request instanceaccessKey- the app's access keysecretKey- the app's secret keyoverride- the clock override from x-amz-date- Returns:
- the request object
-
parseAWSDate
Returns a parsed Date.- Parameters:
date- a date in the AWS format yyyyMMdd'T'HHmmss'Z'- Returns:
- a date
-
parseAWSInstant
Returns a parsed Instant.- Parameters:
date- a date in the AWS format yyyyMMdd'T'HHmmss'Z'- Returns:
- a date
-
signRequest
public Map<String,String> signRequest(String accessKey, String secretKey, String httpMethod, String endpointURL, String reqPath, Map<String, String> headers, jakarta.ws.rs.core.MultivaluedMap<String, String> params, byte[] jsonEntity) Builds and signs a request to an API endpoint using the provided credentials.- Parameters:
accessKey- access keysecretKey- secret keyhttpMethod- the method (GET, POST...)endpointURL- protocol://host:portreqPath- the API resource path relative to the endpointURLheaders- headers mapparams- parameters mapjsonEntity- an object serialized to JSON byte array (payload), could be null- Returns:
- a map containing the "Authorization" header
-