Package com.akamai.edgegrid.signer
Class AbstractEdgeGridRequestSigner<RequestT,MutableRequestT>
java.lang.Object
com.akamai.edgegrid.signer.AbstractEdgeGridRequestSigner<RequestT,MutableRequestT>
- Type Parameters:
RequestT
- a type of HTTP client specific request.
This is an abstract base class for implementing EdgeGrid request signing in a library-specific way. There are several HTTP client libraries available for Java, and this class offers a simple mechanism for supporting them.
This class uses a ClientCredentialProvider
to select a ClientCredential
appropriately for each request.
This interface permits sharing a single instance of the class for a variety of API calls. It also
offers a more configurable way to retrieve credentials any way the user wants.
- Author:
- [email protected], [email protected]
-
Constructor Summary
ConstructorDescriptionAbstractEdgeGridRequestSigner
(ClientCredential clientCredential) Creates an EdgeGrid request signer that will always sign requests with the sameClientCredential
.AbstractEdgeGridRequestSigner
(ClientCredentialProvider clientCredentialProvider) Creates an EdgeGrid request signer selecting aClientCredential
viaClientCredentialProvider.getClientCredential(Request)
for each request. -
Method Summary
Modifier and TypeMethodDescriptionfinal ClientCredentialProvider
protected abstract Request
Maps HTTP client-specific request to client-agnostic model of this request.protected abstract URI
requestUri
(RequestT request) Returns Request-URI of an original request.protected abstract void
setAuthorization
(MutableRequestT request, String signature) Updates a given HTTP request by adding Authorization header with a value containing request signature.protected abstract void
setHost
(MutableRequestT request, String host, URI uri) Updates a given HTTP request by replacing the request hostname withhost
instead.void
sign
(RequestT request, MutableRequestT requestToUpdate) Signsrequest
with appropriate credentials using EdgeGrid signer algorithm and replacesrequest
's host name with the one specified by the credential.
-
Constructor Details
-
AbstractEdgeGridRequestSigner
Creates an EdgeGrid request signer that will always sign requests with the sameClientCredential
. This constructor will automatically produce aDefaultClientCredentialProvider
out ofclientCredential
.- Parameters:
clientCredential
- aClientCredential
to be used for all requests
-
AbstractEdgeGridRequestSigner
Creates an EdgeGrid request signer selecting aClientCredential
viaClientCredentialProvider.getClientCredential(Request)
for each request.- Parameters:
clientCredentialProvider
- aClientCredentialProvider
to be used for selecting credentials for each request
-
-
Method Details
-
getClientCredentialProvider
-
sign
Signsrequest
with appropriate credentials using EdgeGrid signer algorithm and replacesrequest
's host name with the one specified by the credential.- Parameters:
request
- an HTTP request with data used to signrequestToUpdate
- an HTTP request to update with signature- Throws:
RequestSigningException
- if failed to sign a requestNoMatchingCredentialException
- if acquiring aClientCredential
throwsNoMatchingCredentialException
or returnsnull
-
requestUri
Returns Request-URI of an original request. -
map
Maps HTTP client-specific request to client-agnostic model of this request.- Parameters:
request
- an HTTP client-specific request- Returns:
- a
Request
representation ofrequest
- Throws:
IllegalArgumentException
- if duplicate header definitions are found
-
setAuthorization
Updates a given HTTP request by adding Authorization header with a value containing request signature.- Parameters:
request
- HTTP request to updatesignature
- HTTP request signature
-
setHost
Updates a given HTTP request by replacing the request hostname withhost
instead. Usually, it means updating Host header and Request-URI.- Parameters:
request
- HTTP request to updatehost
- an OPEN API hostnameuri
- request URI with OPEN API hostname
-