Package net.solarnetwork.web.security
Class AuthenticationData
java.lang.Object
net.solarnetwork.web.security.AuthenticationData
- Direct Known Subclasses:
AuthenticationDataV1,AuthenticationDataV2
Abstract base class for parsing and exposing the authentication data included
in a HTTP authentication header.
- Since:
- 1.11
- Version:
- 2.1
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe fixed length of a SolarNetwork authentication token ID. -
Constructor Summary
ConstructorsConstructorDescriptionAuthenticationData(AuthenticationScheme scheme, SecurityHttpServletRequestWrapper request, String headerValue) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected final byte[]computeMACDigest(String secretKey, String macAlgorithm) Compute a Base64 MAC digest from the signature data.abstract StringcomputeSignatureDigest(String secretKey) Compute the signature digest from the request data and a given secret key.abstract StringGet the authentication token ID.getDate()Get the date associated with the request.longGet the date skew (in milliseconds) associated with the request (from the system date).The scheme of the authentication data.abstract StringGet the extracted signature data from this request.abstract StringGet the signature digest as presented in the HTTP header value.static StringGet a HTTP formatted date.booleanisDateValid(long maxDateSkew) Test if the date skew is less than a maximum date skew.static StringnullSafeHeaderValue(javax.servlet.http.HttpServletRequest request, String headerName) Get a string value of a specific HTTP header, returning an empty string if not available.static voidValidate a digest header value presented in a request against the request body content.
-
Field Details
-
AUTH_TOKEN_ID_LENGTH
public static final int AUTH_TOKEN_ID_LENGTHThe fixed length of a SolarNetwork authentication token ID.- See Also:
-
-
Constructor Details
-
AuthenticationData
public AuthenticationData(AuthenticationScheme scheme, SecurityHttpServletRequestWrapper request, String headerValue) Constructor.- Parameters:
scheme- The scheme associated with the data.request- The request.headerValue- The authentication HTTP header value.- Throws:
org.springframework.security.authentication.BadCredentialsException- if the request date is not available or no data is associated with the authentication header
-
-
Method Details
-
validateContentDigest
public static void validateContentDigest(SecurityHttpServletRequestWrapper request) throws IOException Validate a digest header value presented in a request against the request body content.- Parameters:
request- The request.- Throws:
IOException- If an IO error occurs.org.springframework.security.authentication.BadCredentialsException- If a digest does not match.
-
nullSafeHeaderValue
public static String nullSafeHeaderValue(javax.servlet.http.HttpServletRequest request, String headerName) Get a string value of a specific HTTP header, returning an empty string if not available.- Parameters:
request- The request.headerName- The name of the HTTP header to get.- Returns:
- The header value, or an empty string if not found.
-
httpDate
Get a HTTP formatted date.- Parameters:
date- The date to format.- Returns:
- The formatted date.
-
getDate
Get the date associated with the request.- Returns:
- The date.
-
getDateSkew
public long getDateSkew()Get the date skew (in milliseconds) associated with the request (from the system date).- Returns:
- The date skew.
-
getScheme
The scheme of the authentication data.- Returns:
- The scheme.
-
isDateValid
public boolean isDateValid(long maxDateSkew) Test if the date skew is less than a maximum date skew.- Parameters:
maxDateSkew- The maximum allowed date skew.- Returns:
trueif the date skew is within the allowed skew
-
computeMACDigest
Compute a Base64 MAC digest from the signature data.- Parameters:
secretKey- the secret keymacAlgorithm- the MAC algorithm to use- Returns:
- The base64 encoded digest.
- Throws:
SecurityException- if any error occurs
-
computeSignatureDigest
Compute the signature digest from the request data and a given secret key.- Parameters:
secretKey- The secret key.- Returns:
- The computed digest, as a Base64 encoded string.
-
getAuthTokenId
Get the authentication token ID.- Returns:
- The authentication token ID.
-
getSignatureDigest
Get the signature digest as presented in the HTTP header value.- Returns:
- The presented signature digest.
-
getSignatureData
Get the extracted signature data from this request.- Returns:
- The raw signature data.
-