Package net.solarnetwork.web.security
Class AuthenticationDataV2
java.lang.Object
net.solarnetwork.web.security.AuthenticationData
net.solarnetwork.web.security.AuthenticationDataV2
Version 2 authentication token scheme based on HMAC-SHA256.
Signing keys are treated valid for up to 7 days in the past from the time of
the signature calculation in
computeSignatureDigest(String).- Since:
- 1.11
- Version:
- 2.0
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe token component for the credential (token ID).static final StringThe token component for the signature.static final StringThe token component for the signed headers list.Fields inherited from class net.solarnetwork.web.security.AuthenticationData
AUTH_TOKEN_ID_LENGTH -
Constructor Summary
ConstructorsConstructorDescriptionAuthenticationDataV2(SecurityHttpServletRequestWrapper request, String headerValue) Constructor.AuthenticationDataV2(SecurityHttpServletRequestWrapper request, String headerValue, String explicitHost) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncomputeSignatureDigest(String secretKey) Compute the signature digest from the request data and a given secret key.computeSignatureDigest(String secretKey, Instant signDate) Compute the signature digest, using a specific signing date.Get the authentication token ID.Get the extracted signature data from this request.Get the signature digest as presented in the HTTP header value.Get the set of signed header names.Methods inherited from class net.solarnetwork.web.security.AuthenticationData
computeMACDigest, getDate, getDateSkew, getScheme, httpDate, isDateValid, nullSafeHeaderValue, validateContentDigest
-
Field Details
-
TOKEN_COMPONENT_KEY_CREDENTIAL
The token component for the credential (token ID).- See Also:
-
TOKEN_COMPONENT_KEY_SIGNED_HEADERS
The token component for the signed headers list.- See Also:
-
TOKEN_COMPONENT_KEY_SIGNATURE
The token component for the signature.- See Also:
-
-
Constructor Details
-
AuthenticationDataV2
public AuthenticationDataV2(SecurityHttpServletRequestWrapper request, String headerValue) throws IOException Constructor.- Parameters:
request- the HTTP requestheaderValue- the Authorization HTTP header value- Throws:
IOException- if any IO error occurs
-
AuthenticationDataV2
public AuthenticationDataV2(SecurityHttpServletRequestWrapper request, String headerValue, String explicitHost) throws IOException Constructor.- Parameters:
request- the HTTP requestheaderValue- the Authorization HTTP header valueexplicitHost- a fixed value to use instead of the Host HTTP header value, or null to use the header value; this can be useful when sitting behind a proxy- Throws:
IOException- if any IO error occurs- Since:
- 1.3
-
-
Method Details
-
computeSignatureDigest
Description copied from class:AuthenticationDataCompute the signature digest from the request data and a given secret key.- Specified by:
computeSignatureDigestin classAuthenticationData- Parameters:
secretKey- The secret key.- Returns:
- The computed digest, as a Base64 encoded string.
-
computeSignatureDigest
Compute the signature digest, using a specific signing date.Generally the current date/time is used to sign the request, which is what the
computeSignatureDigest(String)method uses. This method can be useful for testing purposes.- Parameters:
secretKey- the secret keysignDate- the signature date- Returns:
- the computed digest
- See Also:
-
getAuthTokenId
Description copied from class:AuthenticationDataGet the authentication token ID.- Specified by:
getAuthTokenIdin classAuthenticationData- Returns:
- The authentication token ID.
-
getSignatureDigest
Description copied from class:AuthenticationDataGet the signature digest as presented in the HTTP header value.- Specified by:
getSignatureDigestin classAuthenticationData- Returns:
- The presented signature digest.
-
getSignatureData
Description copied from class:AuthenticationDataGet the extracted signature data from this request.- Specified by:
getSignatureDatain classAuthenticationData- Returns:
- The raw signature data.
-
getSignedHeaderNames
Get the set of signed header names.- Returns:
- The signed header names, or null.
-