T
- type of the request to be signedpublic abstract class NeptuneSigV4SignerBase<T> extends Object implements NeptuneSigV4Signer<T>
NeptuneSigV4Signer
interface.
This implementation uses the internal AWS SDK signer to sign requests. The constructor
requires the region name for which to sign as well as an AWSCredentialsProvider
providing access to the credentials used for signing the request. The service name used
within the signing process is hardcoded to be "neptune-db", which is the official name
of the Amazon Neptune service.
The implementation uses the following approach for signing the request:
SignableRequest
.SignableRequest
using an AWS SDK AWS4Signer
Modifier and Type | Class and Description |
---|---|
static class |
NeptuneSigV4SignerBase.NeptuneSigV4Signature
Simple struct encapsulating pre-computed Signature V4 signing information.
|
Constructor and Description |
---|
NeptuneSigV4SignerBase(String regionName,
com.amazonaws.auth.AWSCredentialsProvider awsCredentialsProvider)
Create a
NeptuneSigV4Signer instance for the given region and service name. |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
attachSignature(T nativeRequest,
NeptuneSigV4SignerBase.NeptuneSigV4Signature signature)
Attach the signature provided in the signature object to the nativeRequest.
|
protected void |
checkNotNull(Object obj,
String errMsg)
Tiny helper function to assert that the object is not null.
|
protected com.amazonaws.SignableRequest<?> |
convertToSignableRequest(String httpMethodName,
URI httpEndpointUri,
String resourcePath,
Map<String,String> httpHeaders,
Map<String,List<String>> httpParameters,
InputStream httpContent)
Helper method to create an AWS SDK
SignableRequest based on HTTP information. |
protected Map<String,List<String>> |
extractParametersFromQueryString(String queryStr)
Extracts the parameters from a query string (such as param1=value1¶m2=value2&...).
|
void |
signRequest(T request)
Main logics to sign the request.
|
protected abstract com.amazonaws.SignableRequest<?> |
toSignableRequest(T nativeRequest)
Convert the native request into an AWS SDK
SignableRequest object which
can be used to perform signing. |
public NeptuneSigV4SignerBase(String regionName, com.amazonaws.auth.AWSCredentialsProvider awsCredentialsProvider) throws NeptuneSigV4SignerException
NeptuneSigV4Signer
instance for the given region and service name.regionName
- name of the region for which the request is signedawsCredentialsProvider
- the provider offering access to the credentials used for signing the requestNeptuneSigV4SignerException
- in case initialization failsprotected abstract com.amazonaws.SignableRequest<?> toSignableRequest(T nativeRequest) throws NeptuneSigV4SignerException
SignableRequest
object which
can be used to perform signing. This means that the information from the request relevant
for signing (such as request URI, query string, headers, etc.) need to be extracted from
the native request and mapped to a SignableRequest
object, which is used internally
for the signing process.
Note that the signable request internally, during the signing process, adds a "Host" header. This may lead to problems if the original request has a host header with a name in different capitalization (e.g. "host"), leading to duplicate host headers and the signing process to fail. Hence, when using the API you need to make sure that there is either no host header in your original request or the host header uses the exact string "Host" as the header name. The easiest solution, if you have control over the native HTTP request, is to just leave out the host header when translating and create one when signing (the host header value will be part of the struct returned from the signing process).
nativeRequest
- the native HTTP requestSignableRequest
NeptuneSigV4SignerException
- in case something goes wrong during translationprotected abstract void attachSignature(T nativeRequest, NeptuneSigV4SignerBase.NeptuneSigV4Signature signature) throws NeptuneSigV4SignerException
nativeRequest
- the native HTTP requestsignature
- the signature information to attachNeptuneSigV4SignerException
- in case something goes wrong during signing of the native requestpublic void signRequest(T request) throws NeptuneSigV4SignerException
Note that toSignableRequest and attachSignature are abstract classes in this base class, they require dedicated implementations depending on the type of the native HTTP request.
signRequest
in interface NeptuneSigV4Signer<T>
request
- the request to be signedNeptuneSigV4SignerException
- in case something goes wrong during signingprotected com.amazonaws.SignableRequest<?> convertToSignableRequest(String httpMethodName, URI httpEndpointUri, String resourcePath, Map<String,String> httpHeaders, Map<String,List<String>> httpParameters, InputStream httpContent) throws NeptuneSigV4SignerException
SignableRequest
based on HTTP information.
None of the information passed in here must be null. Can (yet must not) be used by
implementing classes.
Also note that the resulting request will not yet be actually signed; this is really only a helper to convert the relevant information from the original HTTP request into the AWS SDK's internal format that will be used for computing the signature in a later step, see the signRequest method for details.
httpMethodName
- name of the HTTP method (e.g. "GET", "POST", ...)httpEndpointUri
- URI of the endpoint to which the HTTP request is sent. E.g. http://[host]:port/resourcePath
- the resource path of the request. /resource/id is the path in http://[host]:port/resource/idhttpHeaders
- the headers, defined as a mapping from keys (header name) to values (header values)httpParameters
- the parameters, defined as a mapping from keys (parameter names) to a list of valueshttpContent
- the content carried by the HTTP request; use an empty InputStream for GET requestsNeptuneSigV4SignerException
- in case something goes wrong signing the requestprotected Map<String,List<String>> extractParametersFromQueryString(String queryStr)
queryStr
- the query string from which parameters are extractedprotected void checkNotNull(Object obj, String errMsg) throws NeptuneSigV4SignerException
NeptuneSigV4SignerException
is thrown, with the specified error message.obj
- the object to be checked for nullerrMsg
- the error message to be propagated in case the check failsNeptuneSigV4SignerException
- if the check fails