Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Pass/Set&Get Parameter MVCActionCommand to Custom Authenticator - Dxp
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.
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.
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 ?
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.
Powered by Liferay™