Class 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 [[email protected]]
    • Constructor Detail

      • Signer

        public Signer()
        No-args constructor.
    • 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 server
        resourcePath - the path of the resource (starting from root e.g. "/path/to/res")
        headers - the headers map
        params - the params map
        entity - the entity object or null
        accessKey - the app's access key
        secretKey - 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 instance
        accessKey - the app's access key
        secretKey - the app's secret key
        override - 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 key
        secretKey - secret key
        httpMethod - the method (GET, POST...)
        endpointURL - protocol://host:port
        reqPath - the API resource path relative to the endpointURL
        headers - headers map
        params - parameters map
        jsonEntity - an object serialized to JSON byte array (payload), could be null
        Returns:
        a map containing the "Authorization" header