Package org.teiid.translator.amazon.s3
Class AWS4SignerBase
- java.lang.Object
-
- org.teiid.translator.amazon.s3.AWS4SignerBase
-
- Direct Known Subclasses:
AWS4SignerForAuthorizationHeader,AWS4SignerForChunkedUpload
public abstract class AWS4SignerBase extends Object
Common methods and properties for all AWS4 signer variants This code was taken from Amazon Example, No copyright found.
-
-
Field Summary
Fields Modifier and Type Field Description static StringALGORITHMprotected SimpleDateFormatdateStampFormatstatic StringDateStringFormatprotected SimpleDateFormatdateTimeFormatstatic StringEMPTY_BODY_SHA256SHA256 hash of an empty request bodyprotected URLendpointUrlprotected StringhttpMethodstatic StringISO8601BasicFormatformat strings for the date/time and date stamps required during signingprotected StringregionNamestatic StringSCHEMEprotected StringserviceNamestatic StringTERMINATORstatic StringUNSIGNED_PAYLOAD
-
Constructor Summary
Constructors Constructor Description AWS4SignerBase(URL endpointUrl, String httpMethod, String serviceName, String regionName)Create a new AWS V4 signer.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static StringgetCanonicalizedHeaderString(Map<String,String> headers)Computes the canonical headers with values for the request.static StringgetCanonicalizedQueryString(Map<String,String> parameters)Examines the specified query string parameters and returns a canonicalized form.protected static StringgetCanonicalizedResourcePath(URL endpoint)Returns the canonicalized resource path for the service endpoint.protected static StringgetCanonicalizeHeaderNames(Map<String,String> headers)Returns the canonical collection of header names that will be included in the signature.protected static StringgetCanonicalRequest(URL endpoint, String httpMethod, String queryParameters, String canonicalizedHeaderNames, String canonicalizedHeaders, String bodyHash)Returns the canonical request string to go into the signer process; this consists of several canonical sub-parts.protected static StringgetStringToSign(String scheme, String algorithm, String dateTime, String scope, String canonicalRequest)static byte[]hash(byte[] data)Hashes the byte array using the SHA-256 algorithm.static byte[]hash(String text)Hashes the string contents (assumed to be UTF-8) using the SHA-256 algorithm.protected static byte[]sign(String stringData, byte[] key, String algorithm)static StringurlEncode(String url, boolean keepPathSlash)
-
-
-
Field Detail
-
EMPTY_BODY_SHA256
public static final String EMPTY_BODY_SHA256
SHA256 hash of an empty request body- See Also:
- Constant Field Values
-
UNSIGNED_PAYLOAD
public static final String UNSIGNED_PAYLOAD
- See Also:
- Constant Field Values
-
SCHEME
public static final String SCHEME
- See Also:
- Constant Field Values
-
ALGORITHM
public static final String ALGORITHM
- See Also:
- Constant Field Values
-
TERMINATOR
public static final String TERMINATOR
- See Also:
- Constant Field Values
-
ISO8601BasicFormat
public static final String ISO8601BasicFormat
format strings for the date/time and date stamps required during signing- See Also:
- Constant Field Values
-
DateStringFormat
public static final String DateStringFormat
- See Also:
- Constant Field Values
-
endpointUrl
protected URL endpointUrl
-
httpMethod
protected String httpMethod
-
serviceName
protected String serviceName
-
regionName
protected String regionName
-
dateTimeFormat
protected final SimpleDateFormat dateTimeFormat
-
dateStampFormat
protected final SimpleDateFormat dateStampFormat
-
-
Constructor Detail
-
AWS4SignerBase
public AWS4SignerBase(URL endpointUrl, String httpMethod, String serviceName, String regionName)
Create a new AWS V4 signer.- Parameters:
endpointUrl- The service endpoint, including the path to any resource.httpMethod- The HTTP verb for the request, e.g. GET.serviceName- The signing name of the service, e.g. 's3'.regionName- The system name of the AWS region associated with the endpoint, e.g. us-east-1.
-
-
Method Detail
-
getCanonicalizeHeaderNames
protected static String getCanonicalizeHeaderNames(Map<String,String> headers)
Returns the canonical collection of header names that will be included in the signature. For AWS4, all header names must be included in the process in sorted canonicalized order.
-
getCanonicalizedHeaderString
protected static String getCanonicalizedHeaderString(Map<String,String> headers)
Computes the canonical headers with values for the request. For AWS4, all headers must be included in the signing process.
-
getCanonicalRequest
protected static String getCanonicalRequest(URL endpoint, String httpMethod, String queryParameters, String canonicalizedHeaderNames, String canonicalizedHeaders, String bodyHash)
Returns the canonical request string to go into the signer process; this consists of several canonical sub-parts.- Returns:
-
getCanonicalizedResourcePath
protected static String getCanonicalizedResourcePath(URL endpoint)
Returns the canonicalized resource path for the service endpoint.
-
getCanonicalizedQueryString
public static String getCanonicalizedQueryString(Map<String,String> parameters)
Examines the specified query string parameters and returns a canonicalized form.The canonicalized query string is formed by first sorting all the query string parameters, then URI encoding both the key and value and then joining them, in order, separating key value pairs with an '&'.
- Parameters:
parameters- The query string parameters to be canonicalized.- Returns:
- A canonicalized form for the specified query string parameters.
-
getStringToSign
protected static String getStringToSign(String scheme, String algorithm, String dateTime, String scope, String canonicalRequest)
-
hash
public static byte[] hash(String text)
Hashes the string contents (assumed to be UTF-8) using the SHA-256 algorithm.
-
hash
public static byte[] hash(byte[] data)
Hashes the byte array using the SHA-256 algorithm.
-
-