Package com.erudika.para.rest
Class Signer
- 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.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 extendsBaseAws4Signer
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 [[email protected]]
-
-
Constructor Summary
Constructors Constructor Description Signer()
No-args constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Date
parseAWSDate(String date)
Returns a parsed Date.static Instant
parseAWSInstant(String date)
Returns a parsed Instant.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.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.Map<String,String>
signRequest(String accessKey, String secretKey, String httpMethod, String endpointURL, String reqPath, Map<String,String> headers, javax.ws.rs.core.MultivaluedMap<String,String> params, byte[] jsonEntity)
Builds and signs a request to an API endpoint using the provided credentials.
-
-
-
Method Detail
-
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
Authorization
header.
-
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
public static Date parseAWSDate(String date)
Returns a parsed Date.- Parameters:
date
- a date in the AWS format yyyyMMdd'T'HHmmss'Z'- Returns:
- a date
-
parseAWSInstant
public static Instant parseAWSInstant(String date)
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, javax.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
-
-