Class Signer
java.lang.Object
com.erudika.para.core.rest.Signer
This class implements the AWS Signature Version 4 algorithm. The signatures that this class produces are compatible
with the original AWS SDK implementation.
- Author:
- Alex Bogdanovski [[email protected]]
-
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 httpMethod, 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.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.
-
Constructor Details
-
Signer
public Signer()
-
-
Method Details
-
sign
public Map<String,String> sign(String httpMethod, 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:
httpMethod- 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.
-
parseAWSDate
-
parseAWSInstant
-
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
-