Fórum

Redirect to new page after autologin failure

thumbnail
Manish Jha, modificado 9 Anos atrás.

Redirect to new page after autologin failure

Junior Member Postagens: 50 Data de Entrada: 07/02/13 Postagens Recentes
i am using Site minder for authentication in liferay. I have created autologin hook for the same.

However, i would like to forward user to errorPage if user is present in SiteMinder but not in the liferay Portal.
I tried using following code but it is creating "server redirect loop".

public String[] login(HttpServletRequest request,
HttpServletResponse response) {
String[] credentials = null;
try {

Company company = PortalUtil.getCompany(request);
long companyId = company.getCompanyId();
String siteMinderUserHeader = request.getHeader(PrefsPropsUtil
.getString(companyId, SITEMINDER_USER_HEADER,
SITEMINDER_USER_HEADER));

if (Validator.isNull(siteMinderUserHeader)) {
return credentials;
}
String authType = company.getAuthType();
User user = null;

user = UserLocalServiceUtil.getUserByScreenName(companyId,
siteMinderUserHeader);

long userId = user.getUserId();
String password = user.getPassword();
credentials = new String[THREE];
credentials[0] = Long.toString(userId);
credentials[1] = password;
credentials[2] = Boolean.TRUE.toString();
} catch (Exception e) {
String uri = (String) request
.getAttribute(WebKeys.INVOKER_FILTER_URI);
log.info("Redirecting to Error Page");
log.info("request URI = "+uri);
log.error(e.getMessage(), e);
// redirect user to a Error Page
StringBuffer redirect = new StringBuffer(
PortalUtil.getPortalURL(request)).append(
PortalUtil.getPathContext(request)).append(
PropsUtil.get(ERR_PAGE));
try {
request.setAttribute(AutoLogin.AUTO_LOGIN_REDIRECT, ERR_PAGE );
//response.sendRedirect(redirect.toString());

} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

}
return credentials;
}
thumbnail
Manish Jha, modificado 9 Anos atrás.

RE: Redirect to new page after autologin failure (Resposta)

Junior Member Postagens: 50 Data de Entrada: 07/02/13 Postagens Recentes
it was resolved after i put a logic to detect loop inside exception handling block.
Kumar Yadanaparthi, modificado 9 Anos atrás.

RE: Redirect to new page after autologin failure

New Member Postagens: 2 Data de Entrada: 12/12/13 Postagens Recentes
Hi Manish,

I also have same requirement like redirect to error page after liferay auto-login/ladap import fails. Could you please let me know where(like which class) I need to hook the below code.

Thanks for You help.

Regards,
Kumar
thumbnail
Andew Jardine, modificado 9 Anos atrás.

RE: Redirect to new page after autologin failure

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
I would guess that he made a custom login hook and either extended the SiteMinderAutoLogin class so that he could access it's features, or simply copied the code from the portal source, pasted it into his own, and then made the changes. The latter of the two will ensure that the logic doesn't change on you with future releases.

A Liferay Hook plugin for the property auto.login.hooks is where you need to start, configuring it to use your custom class. Then make sure your implementation class implements the AutoLogin interface.