Class NeptuneApacheHttpSigV4Signer

  • All Implemented Interfaces:
    NeptuneSigV4Signer<org.apache.http.client.methods.HttpUriRequest>

    public class NeptuneApacheHttpSigV4Signer
    extends NeptuneSigV4SignerBase<org.apache.http.client.methods.HttpUriRequest>
    Signer for HTTP requests made via Apache Commons HttpUriRequests.

    Note that there are certain limitations for the usage of this class. In particular:

    • The implementation 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.
    • When using GET, the underlying HTTP request needs to encode whitespaces in query parameters using '%20' rather than (what most APIs such as the Apache commons URIBuilder do) using '+'.
    • Constructor Detail

      • NeptuneApacheHttpSigV4Signer

        public NeptuneApacheHttpSigV4Signer​(String regionName,
                                            com.amazonaws.auth.AWSCredentialsProvider v1AwsCredentialProvider)
                                     throws NeptuneSigV4SignerException
        Create a V4 Signer for Apache Commons HTTP requests.
        Parameters:
        regionName - name of the region for which the request is signed
        v1AwsCredentialProvider - the provider offering access to the credentials used for signing the request
        Throws:
        NeptuneSigV4SignerException - in case initialization fails
      • NeptuneApacheHttpSigV4Signer

        public NeptuneApacheHttpSigV4Signer​(String regionName,
                                            com.amazonaws.auth.AWSCredentialsProvider v1AwsCredentialProvider,
                                            String serviceName)
                                     throws NeptuneSigV4SignerException
        Create a V4 Signer for Apache Commons HTTP requests.
        Parameters:
        regionName - name of the region for which the request is signed
        v1AwsCredentialProvider - the provider offering access to the credentials used for signing the request
        serviceName - name of the service name used to sign the requests. Defaults to neptune-db
        Throws:
        NeptuneSigV4SignerException - in case initialization fails
      • NeptuneApacheHttpSigV4Signer

        public NeptuneApacheHttpSigV4Signer​(String regionName,
                                            software.amazon.awssdk.auth.credentials.AwsCredentialsProvider awsCredentialsProvider)
                                     throws NeptuneSigV4SignerException
        Create a V4 Signer for Apache Commons HTTP requests.
        Parameters:
        regionName - name of the region for which the request is signed
        awsCredentialsProvider - the provider offering access to the credentials used for signing the request
        Throws:
        NeptuneSigV4SignerException - in case initialization fails
      • NeptuneApacheHttpSigV4Signer

        public NeptuneApacheHttpSigV4Signer​(String regionName,
                                            software.amazon.awssdk.auth.credentials.AwsCredentialsProvider awsCredentialsProvider,
                                            String serviceName)
                                     throws NeptuneSigV4SignerException
        Create a V4 Signer for Apache Commons HTTP requests.
        Parameters:
        regionName - name of the region for which the request is signed
        awsCredentialsProvider - the provider offering access to the credentials used for signing the request
        serviceName - name of the service name used to sign the requests. Defaults to neptune-db
        Throws:
        NeptuneSigV4SignerException - in case initialization fails
    • Method Detail

      • toSignableRequest

        protected software.amazon.awssdk.http.SdkHttpFullRequest toSignableRequest​(org.apache.http.client.methods.HttpUriRequest request)
                                                                            throws NeptuneSigV4SignerException
        Description copied from class: NeptuneSigV4SignerBase
        Convert the native request into an AWS SDK 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).

        Specified by:
        toSignableRequest in class NeptuneSigV4SignerBase<org.apache.http.client.methods.HttpUriRequest>
        Parameters:
        request - the native HTTP request
        Returns:
        the SdkHttpFullRequest
        Throws:
        NeptuneSigV4SignerException - in case something goes wrong during translation
      • attachSignature

        protected void attachSignature​(org.apache.http.client.methods.HttpUriRequest request,
                                       NeptuneSigV4SignerBase.NeptuneSigV4Signature signature)
                                throws NeptuneSigV4SignerException
        Description copied from class: NeptuneSigV4SignerBase
        Attach the signature provided in the signature object to the nativeRequest. More precisely, the signature contains two headers, X-AMZ-DATE and an Authorization header, which need to be attached to the native HTTP request as HTTP headers or query string depending on the type of signature requested - header/pre-signed url.
        Specified by:
        attachSignature in class NeptuneSigV4SignerBase<org.apache.http.client.methods.HttpUriRequest>
        Parameters:
        request - the native HTTP request
        signature - the signature information to attach
        Throws:
        NeptuneSigV4SignerException - in case something goes wrong during signing of the native request