public class HmacSignatureFactory extends Object
HmacSignature objects for use in authenticating requests to a REST service. By
default this class will generate HmacSignature objects conforming to version 1 of the
JBEI authentication specification. An HTTP Authorization header is set with the format
Version:KeyId:UserId:Signature, with:
Version = 1,KeyId is a string identifying the key used to sign the request,UserId is a string identifying the user (if any) the request is submitted on behalf
of,Signature is a Base64-encoded string of the request content signed with the SHA-1
HMAC algorithm (specified in RFC 2104)Signature portion of the header, given a
request object and a UserId. The Signature is generated by constructing a string
containing the following separated by a newline character:
UserIdGET, POST)| Constructor and Description |
|---|
HmacSignatureFactory(KeyTable table)
Constructor initializes factory with the secret used to sign requests.
|
| Modifier and Type | Method and Description |
|---|---|
HmacSignature |
buildSignature(org.apache.http.client.methods.HttpRequestBase request,
String keyId,
String userId) |
HmacSignature |
buildSignature(javax.servlet.http.HttpServletRequest request,
String keyId,
String userId) |
HmacSignature |
buildSignature(String keyId,
String userId,
String method,
String host,
String path,
Map<String,? extends Iterable<String>> params)
Builds initial signature object from raw individual components.
|
static Key |
createKey()
Convenience method to create a new random key for signing requests.
|
static Key |
decodeKey(String encodedKey)
Convenience method to decode a key stored in Base64 encoding.
|
static String |
encodeKey(Key key)
Convenience method to encode a key to a Base64 String.
|
public HmacSignatureFactory(KeyTable table)
table - object used to look up keys for signingpublic static Key createKey() throws NoSuchAlgorithmException
NoSuchAlgorithmException - if the system has no registered security providers able to generate the keypublic static Key decodeKey(String encodedKey)
encodedKey - the encoded key Stringpublic static String encodeKey(Key key)
key - the key to encodepublic HmacSignature buildSignature(javax.servlet.http.HttpServletRequest request, String keyId, String userId) throws SignatureException
request - a request received via Servlet APIkeyId - the key identifier signing the requestuserId - the user creating the requestHmacSignature initialized with the request headers; the request stream may
need to be passed through HmacSignature.filterInput(InputStream) to calculate
the correct signatureSignatureException - if there is an error setting up the signaturepublic HmacSignature buildSignature(org.apache.http.client.methods.HttpRequestBase request, String keyId, String userId) throws SignatureException
request - a request to be sent via HttpClient APIkeyId - the key identifier signing the requestuserId - the user creating the requestHmacSignature initialized with the request headers; the request stream may
need to be passed through HmacSignature.filterOutput(OutputStream) to
calculate the correct signatureSignatureException - if there is an error setting up the signaturepublic HmacSignature buildSignature(String keyId, String userId, String method, String host, String path, Map<String,? extends Iterable<String>> params) throws SignatureException
keyId - userId - method - host - path - params - HmacSignature initialized with the request headers; the request stream may
need to be passed through HmacSignature.filterOutput(OutputStream) to
calculate the correct signatureSignatureExceptionCopyright © 2017. All rights reserved.