Class AbstractSignOnServlet
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
An abstract servlet that provides the underlying structure to handle signon processing.
Handler methods (do<Request-name>())are defined for the common signon requests (/parameters, /authenticate, /sendtoken, /logout). Each method is passed the sign-on session data and the request's parsed JSON POST body.
For a detailed description of the common URL requests, see Request handling on the Overview page, and for details of the JSON POST bodies, see SignOn servlet JSON Specifications on the same page.
You must extend this class to implement the
authenticate(String, String, String, String, SessionData, Map, HttpServletRequest, HttpServletResponse)
and sendToken(String, String, SessionData, Map, HttpServletRequest, HttpServletResponse) methods.
Here are example implementations of authenticate() and sendtoken().
There are also some more examples provided in the KeyMaster distribution kit
Example authenticate(String, String, String, String, SessionData, Map, HttpServletRequest, HttpServletResponse) implementation:
public void authenticate(String scheme, String username, String password, String token, SessionData sessionData, Mapattributes, HttpServletRequest req, HttpServletResponse resp) throws ServletException { // check the user exists User user = users.get(username); if (user == null) { sendAuthenticateError(req, resp, "Invalid user"); return; } String newLevel = null; String nextStep = null; // check 1AF if (scheme.equals(SessionData.SCHEME_USER)) { if (password.equals(user.password)) { newLevel = SessionData.LEVEL_1FA; nextStep = SessionData.LEVEL_2FA; // user must now authenticate using a 2FA scheme } } // check SMS 2FA else if (scheme.equals(SessionData.SCHEME_SMS) && scheme.equals(sessionData.getSentScheme())) { // must be authenticated to level 1FA already if (sessionData.getLevel().equals(SessionData.LEVEL_1FA)) { // check scheme and token are same as sent if (token.equals(sessionData.getSentSchemeToken())) { newLevel = SessionData.LEVEL_2FA; } } } // if the level has been updated if (newLevel != null) { // update the session with the new level and scheme sessionData.setUserName(username); sessionData.setLevel(newLevel); sessionData.setScheme(scheme); sendAuthenticateOK(req, resp, newLevel, nextStep); } else { sendAuthenticateError(req, resp, "Invalid signon"); } }
Example sendToken(String, String, SessionData, Map, HttpServletRequest, HttpServletResponse) implementation:
public void sendToken(String scheme, String username, SessionData sessionData, Mapattributes, HttpServletRequest req, HttpServletResponse resp) throws ServletException { User user = users.get(username); if (user == null) { sendSendTokenError(req, resp, "Invalid user"); return; } if (scheme.equals(SessionData.SCHEME_SMS)) { String token = generateSMSToken(); // try to send the token via SMS boolean sent = sendSMSToken(user.smsPhoneNumber, token); if (sent) { // record scheme and token sent in the session sessionData.setSentScheme(SessionData.SCHEME_SMS); sessionData.setSentSchemeToken(token); sendSendTokenOK(req, resp, "SMS token has been sent to " + user.smsPhoneNumber); } else { sendSendTokenError(req, resp, "Error sending token using SMS"); } } else { sendSendTokenError(req, resp, "Error invalid 2FA scheme"); } } private boolean sendSMSToken(String phoneNumber, String text) { // implement this to send SMS message return true; } private String generateSMSToken() { // implement this to generate the SMS token return "123456"; }
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringJWT user claimstatic final StringValid algorithms for JWT validationstatic final StringJWT validation issuerstatic final StringJTI cache size for validation of JWT ID uniquenessstatic final StringMinutes after which JWK will expire.static final StringURI of JWKS for JWT public keystatic final StringLocation of JWT validation public keystatic final StringSingle sign-on path to login with an authorization codestatic final StringAdditional params for auth redirect location.static final StringSingle sign-on path to redirect to authorization serverstatic final StringSingle sign-on redirection on failurestatic final StringSingle sign-on path to login with a JWT tokenstatic final StringUsername credential to be used when requesting a tokenstatic final StringPassword credential to be used when requesting a tokenstatic final StringOpenID Connect Discovery endpointstatic final StringKeystore filenamestatic final StringKeystore file typestatic final StringKeystore passwordstatic final StringSingle sign-on redirection on successstatic final StringString constant for json failure code of invalid credentialsstatic final StringString constant for json failure code of server errorstatic final StringString constant for json request key 'password'static final StringString constant for json request key 'scheme'static final StringString constant for json request key 'token'static final StringString constant for json request key 'username'static final StringString constant for json response key 'level'static final StringString constant for json response key 'code'static final StringString constant for json response key 'reason'static final StringString constant for json response key 'message'static final StringString constant for json response key 'next_step'static final StringString constant for json response key 'result'static final StringString constant for json response key 'schemes'static final StringString constant for the authentication nextstep parameter indicating the next step is to authenticate at 2FA levelstatic final StringString constant for json result of failurestatic final StringString constant for json result of successstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAuthScheme(String scheme) Adds an authentication scheme to the list of those that are accepted.voidaddExtraParameter(String name, Object value) Adds an extra parameter to the list of parameters sent to the client in response to the /parameters request.abstract voidauthenticate(String scheme, String username, String password, String token, SessionData sessionData, Map<String, Object> attributes, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Abstract handler for the authenticate request.voidauthenticateJwt(String userClaim, com.auth0.jwt.interfaces.DecodedJWT jwtToken, Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Handler for JWT authenticate request.voidauthenticateOauth(String userClaim, com.auth0.jwt.interfaces.DecodedJWT idToken, String accessToken, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) voiddestroy()protected voiddoAuthenticate(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) The immediate handler for the /authenticate request.protected voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) protected voiddoLogout(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Handler for the /logout request.protected voiddoOtherRequest(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Handler for any request not handled elsewhere (that is, any request that isn't /parameters, /authenticate, /sendtoken or /logout).protected voiddoParameters(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Handler for the /parameters request.protected voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Parses the POST body as JSON text, retrieve the signon session data and then calls handlers for the standard signon requests:protected voiddoSendToken(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) The immediate handler for the /sendtoken request.protected StringextractJWTToken(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Extract the JWT token from the requestprotected StringgetAuthCodeRedirectUri(javax.servlet.http.HttpServletRequest req) protected IntegergetParameterAsInt(String key, Integer defaultValue) protected StringgetParameterAsString(String key, String defaultValue) protected BooleangetParameterBoolean(String key, Boolean defaultValue) protected ObjectgetParameterValue(String key) protected Pathvoidinit()logPrefix(javax.servlet.http.HttpServletRequest req) Gets the session id prefix added to all log messages.protected voidrenewRequestSession(SessionData sessionData, javax.servlet.http.HttpServletRequest req) Resets a user's session on the servlet request.voidsendAuthenticateError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String error) Sends an error response (in JSON format) for the /authenticate request.voidsendAuthenticateOK(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String level, String nextStep) Sends a success response (in JSON format) for the /authenticate request.voidsendJwtAuthenticateError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String reason) Sends an error response for the JWT authenticate request.voidsendJwtAuthenticateOK(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Sends a success response for the JWT authenticate request.voidsendResponse(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, int status, Map<String, Object> respData) Sends a JSON formatted response with no cache headers.voidsendSendTokenError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String error) Sends an error response (in JSON format) for the /sendtoken request.voidsendSendTokenOK(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String message) Sends a success response (in JSON format) for the /sendtoken request.abstract voidsendToken(String scheme, String username, SessionData sessionData, Map<String, Object> attributes, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Abstract handler for the /sendtoken request.protected voidservice(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Receives the sign-on related URL requests and dispatches them to the doXXX() methods defined in this class.Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, serviceMethods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
JSON_REQUEST_TOKEN
String constant for json request key 'token'- See Also:
-
JSON_REQUEST_SCHEME
String constant for json request key 'scheme'- See Also:
-
JSON_REQUEST_PASSWORD
String constant for json request key 'password'- See Also:
-
JSON_REQUEST_USERNAME
String constant for json request key 'username'- See Also:
-
JSON_RESPONSE_RESULT
String constant for json response key 'result'- See Also:
-
JSON_RESPONSE_FAILURE_CODE
String constant for json response key 'code'- See Also:
-
JSON_RESPONSE_FAILURE_REASON
String constant for json response key 'reason'- See Also:
-
JSON_RESPONSE_SCHEMES
String constant for json response key 'schemes'- See Also:
-
JSON_RESPONSE_AUTHENTICATION_LEVEL
String constant for json response key 'level'- See Also:
-
JSON_RESPONSE_NEXT_STEP
String constant for json response key 'next_step'- See Also:
-
JSON_RESPONSE_MESSAGE
String constant for json response key 'message'- See Also:
-
NEXT_STEP_2FA
String constant for the authentication nextstep parameter indicating the next step is to authenticate at 2FA level- See Also:
-
RESULT_SUCCESS
String constant for json result of success- See Also:
-
RESULT_FAILURE
String constant for json result of failure- See Also:
-
ERROR_SERVER
String constant for json failure code of server error- See Also:
-
ERROR_INVALID_CREDENTIALS
String constant for json failure code of invalid credentials- See Also:
-
CAPLIN_SIGNON_SSO_SUCCESS_REDIRECT
Single sign-on redirection on success- See Also:
-
CAPLIN_SIGNON_SSO_FAILURE_REDIRECT
Single sign-on redirection on failure- See Also:
-
CAPLIN_SIGNON_JWT_USER_CLAIM
JWT user claim- See Also:
-
CAPLIN_SIGNON_JWT_VALIDATION_ALGORITHMS
Valid algorithms for JWT validation- See Also:
-
CAPLIN_SIGNON_JWT_VALIDATION_PUBLICKEY_FILENAME
Location of JWT validation public key- See Also:
-
CAPLIN_SIGNON_JWT_VALIDATION_JWK_EXPIRY_TIME
Minutes after which JWK will expire.- See Also:
-
CAPLIN_SIGNON_JWT_VALIDATION_ISSUER
JWT validation issuer- See Also:
-
CAPLIN_SIGNON_JWT_VALIDATION_JTI_CACHE_SIZE
JTI cache size for validation of JWT ID uniqueness- See Also:
-
CAPLIN_SIGNON_JWT_VALIDATION_JWKS_URI
URI of JWKS for JWT public key- See Also:
-
CAPLIN_SIGNON_SSO_OIDC_DISCOVERY_URI
OpenID Connect Discovery endpoint- See Also:
-
CAPLIN_SIGNON_SSO_JWT_TOKEN_LOGIN_PATH
Single sign-on path to login with a JWT token- See Also:
-
CAPLIN_SIGNON_SSO_AUTH_REDIRECT_PATH
Single sign-on path to redirect to authorization server- See Also:
-
CAPLIN_SIGNON_SSO_AUTH_CODE_PATH
Single sign-on path to login with an authorization code- See Also:
-
CAPLIN_SIGNON_SSO_OAUTH_CLIENT_ID
Username credential to be used when requesting a token- See Also:
-
CAPLIN_SIGNON_SSO_OAUTH_CLIENT_SECRET
Password credential to be used when requesting a token- See Also:
-
CAPLIN_SIGNON_SSO_AUTH_REDIRECT_ADDITIONAL_PARAMS
Additional params for auth redirect location. redirect_uri, client_id, state and response_type will be set automatically Example: "&scope=openid%20profile&access_type=offline" Note: Must start with an ampersand. Ampersands in the URL must be written as "&" in the web.xml as above- See Also:
-
CAPLIN_SIGNON_SSO_REQUEST_KEYSTORE_FILETYPE
Keystore file type- See Also:
-
CAPLIN_SIGNON_SSO_REQUEST_KEYSTORE_FILENAME
Keystore filename- See Also:
-
CAPLIN_SIGNON_SSO_REQUEST_KEYSTORE_PASSWORD
Keystore password- See Also:
-
SSO_STATE_TOKEN
- See Also:
-
validGetPaths
-
-
Constructor Details
-
AbstractSignOnServlet
public AbstractSignOnServlet()
-
-
Method Details
-
init
public void init() throws javax.servlet.ServletException- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
getPath
-
getParameterValue
-
getParameterAsString
-
getParameterAsInt
-
getParameterBoolean
-
service
protected void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException Receives the sign-on related URL requests and dispatches them to the doXXX() methods defined in this class.- Overrides:
servicein classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException Parses the POST body as JSON text, retrieve the signon session data and then calls handlers for the standard signon requests:
Request Handler called /parameters doParameters() /authenticate doAuthenticate() /sendtoken doSendToken() /logout doLogout() any other requests will be handled by
doOtherRequest(Map, SessionData, HttpServletRequest, HttpServletResponse)- Overrides:
doPostin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException - Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletException
-
getAuthCodeRedirectUri
-
extractJWTToken
protected String extractJWTToken(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionExtract the JWT token from the request- Parameters:
attributes-sessionData-req-resp-- Returns:
- Throws:
javax.servlet.ServletException
-
authenticateJwt
public void authenticateJwt(String userClaim, com.auth0.jwt.interfaces.DecodedJWT jwtToken, Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionHandler for JWT authenticate request.
You must implement this method if you are using JWT authentication. You may use the existing security system to set the username and token in
SessionDatato determine the user's authentication level.If the request is successful, update the sessionData and send a SUCCESS response using the
sendJwtAuthenticateOK(HttpServletRequest, HttpServletResponse)method. If the request fails, send a FAILURE response using thesendJwtAuthenticateError(HttpServletRequest, HttpServletResponse, String)method.For more about how to implement the authenticate() method, see the examples supplied with the distribution kit.
- Parameters:
userClaim- the user claim retrieved from the JWT tokenjwtToken- the parsed and validated JWT tokenattributes- the request body text parsed from json into a MapsessionData- the signonSessionDataobject associated with the current sessionreq- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem responding to the authenicate request.
-
authenticateOauth
public void authenticateOauth(String userClaim, com.auth0.jwt.interfaces.DecodedJWT idToken, String accessToken, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException - Throws:
javax.servlet.ServletException
-
sendJwtAuthenticateOK
public void sendJwtAuthenticateOK(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException Sends a success response for the JWT authenticate request.
- Parameters:
req- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem sending the response.
-
sendJwtAuthenticateError
public void sendJwtAuthenticateError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String reason) throws javax.servlet.ServletException Sends an error response for the JWT authenticate request.
- Parameters:
req- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem sending the response.
-
doOtherRequest
protected void doOtherRequest(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionHandler for any request not handled elsewhere (that is, any request that isn't /parameters, /authenticate, /sendtoken or /logout).
Use this handler (by overriding it) to respond to any other requests that are part of your sign-on process.
- Parameters:
attributes- the request body text parsed from json into a MapsessionData- the signonSessionDataobject associated with the current sessionreq- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem responding to the other request.
-
doAuthenticate
protected void doAuthenticate(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionThe immediate handler for the /authenticate request.
It parses the request body to extract the scheme, username, password and 2FA token, does some validity checking and then calls the
authenticate(String, String, String, String, SessionData, Map, HttpServletRequest, HttpServletResponse)method.To handle the authenticate request you should implement authenticate() method rather than override this method.
- Parameters:
attributes- the request body text parsed from json into a MapsessionData- the signon SessionData object associated with the current sessionreq- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem responding to the authenticate request.
-
sendAuthenticateOK
public void sendAuthenticateOK(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String level, String nextStep) throws javax.servlet.ServletException Sends a success response (in JSON format) for the /authenticate request.
See the list of Response JSON parameters in the /authenticate request section in the Overview page.
- Parameters:
req- the servlet request objectresp- the servlet response objectlevel- the new authentication level (see SessionData.LEVEL_... constants)nextStep- a value indicating to the client the next step in the authentication process- Throws:
javax.servlet.ServletException- if there is a problem sending the response.
-
sendAuthenticateError
public void sendAuthenticateError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String error) throws javax.servlet.ServletException Sends an error response (in JSON format) for the /authenticate request.
See the list of Response JSON parameters in the /authenticate request section in the Overview page.
- Parameters:
req- the servlet request objectresp- the servlet response objecterror- the error text (sets the error reason in the JSON response)- Throws:
javax.servlet.ServletException- if there is a problem sending the response.
-
doSendToken
protected void doSendToken(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionThe immediate handler for the /sendtoken request. It parses the request body to extract the scheme and username, does some validity checking and then calls the
sendToken(String, String, SessionData, Map, HttpServletRequest, HttpServletResponse)method.To handle the /sendtoken request you should implement sendToken() method rather than override this method.
- Parameters:
attributes- the request body text parsed from JSON into a MapsessionData- the signonSessionDataobject associated with the current sessionreq- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem responding to the /sendtoken request.
-
sendSendTokenOK
public void sendSendTokenOK(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String message) throws javax.servlet.ServletException Sends a success response (in JSON format) for the /sendtoken request. See the list of Response JSON parameters in the /authenticate request/sendtoken request section in the Overview page.
- Parameters:
req- the servlet request objectresp- the servlet response objectmessage- a message associated with the OK response- Throws:
javax.servlet.ServletException- if there is a problem sending the response.
-
sendSendTokenError
public void sendSendTokenError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String error) throws javax.servlet.ServletException Sends an error response (in JSON format) for the /sendtoken request. See the list of Response JSON parameters in the /authenticate request/sendtoken request section in the Overview page.
- Parameters:
req- the servlet request objectresp- the servlet response objecterror- the error text (sets the error reason in the JSON response)- Throws:
javax.servlet.ServletException- if there is a problem sending the response.
-
doLogout
protected void doLogout(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionHandler for the /logout request. When this method executes successfully, it Invalidates the servlet session.
- Parameters:
attributes- the request body text parsed from json into a MapsessionData- the signonSessionDataobject associated with the current sessionreq- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem responding to the logout request.
-
doParameters
protected void doParameters(Map<String, Object> attributes, SessionData sessionData, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionHandler for the /parameters request.
Sends a JSON format response containing the allowed authentication schemes (including any added using the addAuthScheme() method) and any extra parameters added using the addExtraParameter() method.
- Parameters:
attributes- the request body text parsed from json into a MapsessionData- the signonSessionDataobject associated with the current sessionreq- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem responding to the parameters request.
-
sendResponse
public void sendResponse(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, int status, Map<String, Object> respData) throws javax.servlet.ServletExceptionSends a JSON formatted response with no cache headers. Use this method to send your own JSON responses that are not covered by the other send... methods.
for example:Map<String, Object> respData = new LinkedHashMap<String, Object>(); respData.put(JSON_RESPONSE_RESULT, RESULT_FAILURE); respData.put(JSON_RESPONSE_FAILURE_CODE, ERROR_SERVER); respData.put(JSON_RESPONSE_FAILURE_REASON, "Invalid request."); sendResponse(req, resp, HttpServletResponse.SC_OK, respData);- Parameters:
req- the servlet request objectresp- the servlet response objectstatus- the response status code (use one of the HttpServletResponse.SC_ constants)respData- a map of data to be serialised to a JSON string in the response body, if null then no value is added.- Throws:
javax.servlet.ServletException- if there is a problem writing the response data.
-
logPrefix
Gets the session id prefix added to all log messages. Use this method to include the session Id in your own log messages.- Parameters:
req- the servlet request object- Returns:
- the prefix to add to all log messages
-
addAuthScheme
Adds an authentication scheme to the list of those that are accepted. Common values are available as constants with names of the form SessionData.SCHEME_<SCHEME_NAME>.- Parameters:
scheme- the authentication scheme to add
-
addExtraParameter
Adds an extra parameter to the list of parameters sent to the client in response to the /parameters request.- Parameters:
name- the name of the parametervalue- the value of the parameter
-
authenticate
public abstract void authenticate(String scheme, String username, String password, String token, SessionData sessionData, Map<String, Object> attributes, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionAbstract handler for the authenticate request.
You must implement this method, using scheme, username, password, token and the stored sign-on session information in
SessionDatato determine the user's authentication level (say 1FA, or 2FA). For example, the implementation could obtain the authentication level from an existing security system.If the request is successful, update the sessionData and send a SUCCESS response using the
authenticate(String, String, String, String, SessionData, Map, HttpServletRequest, HttpServletResponse)method. If the request fails, send a FAILURE response using thesendToken(String, String, SessionData, Map, HttpServletRequest, HttpServletResponse)method.It is recommended to use the
renewRequestSessionmethod in order to reset the client user's session before a SUCCESS response is sent in order to mitigate session fixation attacks.For more about how to implement the authenticate() method, see the example above, and the examples SimpleSignonExample and EncryptedSignonExample supplied with the distribution kit.
- Parameters:
scheme- the authentication scheme parsed from the json request (see SessionData.SCHEME_ constants for common values)username- the username parsed from the json requestpassword- the password parsed from the json request, set to null if no password was received.token- the token parsed from the json request, set to null if no token was received.sessionData- the signonSessionDataobject associated with the current sessionattributes- the request body text parsed from json into a Mapreq- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem responding to the authenticate request.
-
renewRequestSession
protected void renewRequestSession(SessionData sessionData, javax.servlet.http.HttpServletRequest req) Resets a user's session on the servlet request.
It is recommended that this method be called from your implementation of the
authenticatemethod after each successful authentication step (scheme) and before the success response (sendAuthenticateOK) is returned to the client.Resetting the session can mitigate possible session fixation attacks whereby attackers can "fix" the client's session identifier prior to authentication, thereby enabling them to hijack the same session once authentication is complete.
- Parameters:
sessionData- the signonSessionDataobject associated with the current sessionreq- the servlet request object
-
sendToken
public abstract void sendToken(String scheme, String username, SessionData sessionData, Map<String, Object> attributes, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionAbstract handler for the /sendtoken request.
You must implement this method, using scheme, username and the stored sign-on session information in
SessionDatato generate a 2FA sign-on token for the user.If the request is successful update the sessionData and send a SUCCESS response using the
sendSendTokenOK(HttpServletRequest, HttpServletResponse, String)method. If the request fails, send a FAILURE response using thesendSendTokenError(HttpServletRequest, HttpServletResponse, String)method.- Parameters:
scheme- the authentication scheme parsed from the json request (see SessionData.SCHEME_ constants for common values)username- the username parsed from the json requestsessionData- the signonSessionDataobject associated with the current sessionattributes- the request body text parsed from json into a Mapreq- the servlet request objectresp- the servlet response object- Throws:
javax.servlet.ServletException- if there is a problem responding to the sendtoken request.
-
destroy
public void destroy()- Specified by:
destroyin interfacejavax.servlet.Servlet- Overrides:
destroyin classjavax.servlet.GenericServlet
-