Pass/Set&Get Parameter MVCActionCommand to Custom Authenticator - Dxp

Amos Fong, modified 2 Years ago. Junior Member Posts: 72 Join Date: 2/17/14 Recent Posts

Hi All,

 

How to pass/set&get custom parameter from custom MVCActionCommand to authenticateByScreenName method of custom Authenticator + liferay dxp

 

I want set the custom parameter in Custom MVCActionCommand class.
And I want get that parameter in authenticateByScreenName method of Custom Authenticator class.

Can any one help me out.

Example Code:

public class CustomLoginMVCActionCommand extends BaseMVCActionCommand {

    @Override
    protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    
        HttpServletRequest request = PortalUtil
                .getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest));
        HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
        
        /* Some Other logic */
        
        request.setAttribute("EmpType1", "Developer");
        
        AuthenticatedSessionManagerUtil.login(request, response, screenName, password, rememberMe, authType);
    
    }


}


public class CustomAuthenticator implements Authenticator {
    @Override
    public int authenticateByScreenName(long companyId, String screenName, String password,
            Map<String, String[]> headerMap, Map<String, String[]> parameterMap) {
            
            /* Here  How get the "EmpType1"  parameter value in this  method */ 
            
            return Authenticator.SUCCESS;
        }

}

I tried with above code, but I was unable to get EmpType1 parameter value in authenticateByScreenName method.

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts

Have you tried using thread-local storage? For things you need to clear on each request, Liferay provides a convenience AutoResetThreadLocal that will get cleared by ThreadLocalFilter automatically after each request.

Srinivas P, modified 2 Years ago. Junior Member Posts: 72 Join Date: 2/17/14 Recent Posts

Hi Dang,

 

Thanks for your replay.

 

Can you please suggest me , how to implement thread-local storage and AutoResetThreadLocal .

 

Where we need to implement,  in Custom MVCActionCommand or Custom Authenticator ?

 

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Chanakya P:

Hi Dang,

Where we need to implement,  in Custom MVCActionCommand or Custom Authenticator ?

As noted in the linked Wikipedia article, a thread local is conceptually equivalent to a thread-based global variable (with some differences, because of class loaders), and you would need to add the relevant code in both: set the value in your action command, and get the value in your authenticator.

If you need a code example, you can see some examples of it everywhere in Liferay. One of the more obvious ones can be found in Liferay's audit application, where AuditFilter sets the thread-local values, and AuditMessageBuilder gets the thread-local values.