I have a custom post login event class that in Liferay DXP. I am trying to handle exceptions by doing a redirect to an external (non-Liferay) error page.
The code I have in place is not redirecting.
I have tried to do a redirect with the lifecycleEvent.getResponse().sendRedirect(redirectURL);
and request.setAttribute(AutoLogin.AUTO_LOGIN_REDIRECT, redirectURL);
. Both of these don't work in this class below.
I am not sure if the post login lifecycle action has different commands for the request.setattribute
to work or that if it is too late lifecycleEvent.getResponse()
to work because the response is already committed.
There are no errors in the logs or otherwise. The user simply is directed to the Liferay default landing page after login whether there are exceptions or not in post login.
Has anyone tried to get this type of error handling to work in Liferay DXP? Any insight is much appreciated. I am under a very tight deadline to get this to work.
My code below:
@Component ( immediate = true, property = { "key=login.events.post" }, service = LifecycleAction.class )
public class CustomPostLoginFilter implements LifecycleAction {
@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
final HttpSession session = lifecycleEvent.getRequest().getSession();
HttpServletRequest request = lifecycleEvent.getRequest();
String redirectURL = loginKeys.defaultErrorRedirectURL;
try {
// custom code
} catch(PortalException e) {
_log.error("Error in post login filter portal exception " + redirectURL, e);
request.setAttribute(AutoLogin.AUTO_LOGIN_REDIRECT, redirectURL);
} catch (Exception e) {
_log.error("Error in post login filter exception " + redirectURL, e);
try {
_log.info("Trying to post login filter redirect ");
if (Validator.isNotNull(redirectURL)) {
_log.info("redirect url not null ");
lifecycleEvent.getResponse().sendRedirect(redirectURL);
}
else {
_log.info("redirect url null");
}
} catch (Exception e1) {
_log.error("Error in post login filter redirect ", e1);
}
// does not seem to redirect on post login
//request.setAttribute(AutoLogin.AUTO_LOGIN_REDIRECT, redirectURL);
}
}
}
Thanks!