Implementation teams can send meaningful error messages to end-users using AJAX calls during user authentication.
For example, let’s assume user ‘terrim’ logs on to Modelhouse application. If the user’s credentials are incorrect or if the user does not have access, a meaningful error message must be displayed to the user.
Perform the following steps to validate session using AJAX:
Index.jsp
function validateUser() { var aparams={ "INPUT_ACTION": "SESSIONTEST", "INPUT_FUNCTION_CODE": "VSBLTY", "INPUT_PRODUCT": "CUSER", "INPUT_SUB_PRODUCT": "CUSER", "PAGE_CODE_TYPE": "SESSIONTEST", "PRODUCT_NAME": "CUSER", "AJAX_REQUEST": "Y", "transactionCode":"logn", "ctLoginID":"terrim" }; extAjax({ params: aparams, success: function(response){ if(response.JSON_MAP.STATUS == 'failure') alert(response.JSON_MAP.ADDITIONAL_INFO); }, failure:function (response,request) { alert("fail"); } }); } <input type = "submit" onclick = "validateUser()" name = "commit" value = "LOGIN" class = "login-btn" aria-label = "Click to Login" />
Forward mapping
<action-map screenCode = "SESSIONTEST" prodCode = "CUSER" subProdCode = "CUSER" funcCode = "VSBLTY" host = "SESSIONTESTHOST" > <action-class> com.intellectdesign.app.iquiz.action.TxnAction </action-class> </action-map>
Action class
package com.intellectdesign.app.iquiz.action; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.intellectdesign.canvas.action.PortletAction; import com.intellectdesign.canvas.common.ReplyObject; import com.intellectdesign.canvas.constants.common.FrameworkConstants; import com.intellectdesign.canvas.exceptions.action.OrbiActionException; import com.intellectdesign.canvas.exceptions.common.ProcessingErrorException; import com.intellectdesign.canvas.logger.Logger; import com.intellectdesign.canvas.login.sessions.SessionInfo; import com.intellectdesign.canvas.web.config.ActionMap; public class TxnAction extends PortletAction{ @Override public ReplyObject executePortletActionUsing(String action, SessionInfo sessionInfo, ActionMap actionMap, Map requestParams, HttpServletRequest request) throws OrbiActionException { logger.ctinfo("CTTXN0001"); ReplyObject reply = null; try { logger.ctdebug("CTTXN0002"); /* * if ("SUBMIT".equals(action) || "DRAFT".equals(action)) { */ reply = executeHostRequest(sessionInfo, actionMap.getHostCode(), requestParams, request); /* } */ logger.ctdebug("CTTXN0003"); } catch (ProcessingErrorException procExcep) { logger.cterror("CTTXN0004"); throw new OrbiActionException(FrameworkConstants.ERROR_SYSTEM_ERROR, "Received processing error while handling action - '" + action + "in TxnAction action", procExcep); } logger.ctinfo("CTTXN0005"); return reply; } private static final Logger logger = Logger.getLogger(TxnAction.class); }
Handler Properties and class
Authentication Provider
Securityconfig.properties update to indicate the respective authentication provider.