public void authenticate() {
LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
ActionRequest actionRequest = (ActionRequest) liferayFacesContext.getPortletRequest();
ActionResponse actionResponse = (ActionResponse) liferayFacesContext.getPortletResponse();
ThemeDisplay themeDisplay = liferayFacesContext.getThemeDisplay();
HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(actionRequest);
// If the request object is a wrapper that handles special namespacing considerations for portlet session
// attributes, then get the inner-most wrapped request. This will ensure that the following call to
// LoginUtil.login(...) will be able to work with a session that has an attribute map shared by the portal.
if (httpServletRequest.getClass().getName().equals(NAMESPACE_SERVLET_REQUEST_FQCN)) {
while (httpServletRequest instanceof HttpServletRequestWrapper) {
HttpServletRequestWrapper httpServletRequestWrapper = (HttpServletRequestWrapper) httpServletRequest;
httpServletRequest = (HttpServletRequest) httpServletRequestWrapper.getRequest();
}
}
HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse);
String handle = loginModelBean.getHandle();
String password = loginModelBean.getPassword();
boolean rememberMe = loginModelBean.isRememberMe();
boolean authenticated = false;
String feedbackMessageId = null;
try {
LoginUtilCompat.invokeLogin(httpServletRequest, httpServletResponse, handle, password, rememberMe,
authType);
authenticated = true;
}
catch (AuthException e) {
feedbackMessageId = "authentication-failed";
}
catch (CompanyMaxUsersException e) {
feedbackMessageId = "unable-to-login-because-the-maximum-number-of-users-has-been-reached";
}
catch (CookieNotSupportedException e) {
feedbackMessageId = "authentication-failed-please-enable-browser-cookies";
}
catch (NoSuchUserException e) {
feedbackMessageId = "authentication-failed";
}
catch (PasswordExpiredException e) {
feedbackMessageId = "your-password-has-expired";
}
catch (UserEmailAddressException e) {
feedbackMessageId = "authentication-failed";
}
catch (UserLockoutException e) {
feedbackMessageId = "this-account-has-been-locked";
}
catch (UserPasswordException e) {
feedbackMessageId = "authentication-failed";
}
catch (UserScreenNameException e) {
feedbackMessageId = "authentication-failed";
}
catch (Exception e) {
logger.error(e);
}
if (authenticated) {
try {
ExternalContext externalContext = liferayFacesContext.getExternalContext();
if (PropsValuesCompat.PORTAL_JAAS_ENABLE) {
externalContext.redirect(themeDisplay.getPathMain() + "/portal/protected");
}
else {
String redirect = ParamUtil.getString(actionRequest, "redirect");
if (Validator.isNotNull(redirect)) {
redirect = PortalUtilCompat.escapeRedirect(redirect);
if (!redirect.startsWith(Http.HTTP)) {
redirect = getCompleteRedirectURL(httpServletRequest, redirect);
}
externalContext.redirect(redirect);
}
else {
boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");
if (doActionAfterLogin) {
return;
}
else {
redirect = getCompleteRedirectURL(httpServletRequest, themeDisplay.getPathMain());
externalContext.redirect(redirect);
}
}
}
}