protected abstract void attachSignature()

in src/main/java/com/amazonaws/neptune/auth/NeptuneSigV4SignerBase.java [135:186]


    protected abstract void attachSignature(final T nativeRequest, final NeptuneSigV4Signature signature)
            throws NeptuneSigV4SignerException;

    /**
     * Main logics to sign the request. The scheme is to convert the request into a
     * signable request using toSignableRequest, then sign it using the AWS SDK, and
     * finally attach the signature headers to the original request using attachSignature.
     * <p>
     * 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.
     *
     * @param request the request to be signed
     * @throws NeptuneSigV4SignerException  in case something goes wrong during signing
     */
    @Override
    public void signRequest(final T request) throws NeptuneSigV4SignerException {

        try {

            // 1. Convert the Apache Http request into an AWS SDK signable request
            //    => to be implemented in subclass
            final SignableRequest<?> awsSignableRequest = toSignableRequest(request);

            // 2. Sign the AWS SDK signable request (which internally adds some HTTP headers)
            //    => generic, using the AWS SDK signer
            final AWSCredentials credentials = awsCredentialsProvider.getCredentials();
            aws4Signer.sign(awsSignableRequest, credentials);

            // extract session token if temporary credentials are provided
            String sessionToken = "";
            if ((credentials instanceof BasicSessionCredentials)) {
                sessionToken = ((BasicSessionCredentials) credentials).getSessionToken();
            }

            final NeptuneSigV4Signature signature =
                    new NeptuneSigV4Signature(
                            awsSignableRequest.getHeaders().get(HOST),
                            awsSignableRequest.getHeaders().get(X_AMZ_DATE),
                            awsSignableRequest.getHeaders().get(AUTHORIZATION),
                            sessionToken);

            // 3. Copy over the Signature V4 headers to the original request
            //    => to be implemented in subclass
            attachSignature(request, signature);

        } catch (final Throwable t) {

            throw new NeptuneSigV4SignerException(t);

        }
    }