留言板

Auto Login Hook - Redirect to error page if authentication fails

Sid L,修改在13 年前。

Auto Login Hook - Redirect to error page if authentication fails

Junior Member 帖子: 28 加入日期: 10-12-3 最近的帖子
I have an application developed in liferay. Now I need to
provide a link on an external site to my app.

I have written a hook ( class extending from AutoLogin) which gets called when any request is being made.
In the login method of my class, I have a logic to authenticate the request parameters sent with the request.

Now what I want to achieve is, incase the authentication fails, I want to redirect the user to a error page.
Currently I am throwing an 'AutoLoginException' incase the validation fails. However it still redirects me to my desired page instead of error page.

Any suggestions on how this can be achieved?
thumbnail
jelmer kuperus,修改在13 年前。

RE: Auto Login Hook - Redirect to error page if authentication fails (答复)

Liferay Legend 帖子: 1191 加入日期: 10-3-10 最近的帖子
You can try doing this when authentication fails in your AutoLogin.login implementation

request.setAttribute(AutoLogin.AUTO_LOGIN_REDIRECT, "http://www.yourhost.com/somerrorpage.html");
return null;


And not throw the exception. Looking at the code of AutoLoginFilter that should work. But its kind of ugly
Sid L,修改在13 年前。

RE: Auto Login Hook - Redirect to error page if authentication fails (答复)

Junior Member 帖子: 28 加入日期: 10-12-3 最近的帖子
Thanks a lot . This solution worked for me
gofri _,修改在13 年前。

RE: Auto Login Hook - Redirect to error page if authentication fails

Junior Member 帖子: 92 加入日期: 07-3-2 最近的帖子
I have similar question - is there a way to redirect users to another page when authentication fails?
I mean with hook.
thumbnail
Faris Abdulla,修改在13 年前。

RE: Auto Login Hook - Redirect to error page if authentication fails

Regular Member 帖子: 183 加入日期: 09-9-2 最近的帖子
The login portlet returns to same page when authentication fails. The LoginAction throws exception to the login.jsp.

You can either use your own LoginAction just changing the struts action path. See this wiki for overriding the struts action using hooks.
gofri _,修改在13 年前。

RE: Auto Login Hook - Redirect to error page if authentication fails

Junior Member 帖子: 92 加入日期: 07-3-2 最近的帖子
10x,
I was thinking almost the same, but cannot make it work (I don't know Struts very well).
I created Custom class that extends LoginAction. Can someone give me hints how to use it? I mean
1. Should I write it as ext-service and place .jar in /lib/ext folder? Or I can use it in a hook?
2. What exactly should I change in struts action paths.
thumbnail
jelmer kuperus,修改在13 年前。

RE: Auto Login Hook - Redirect to error page if authentication fails

Liferay Legend 帖子: 1191 加入日期: 10-3-10 最近的帖子
You mean if you use the regular login portlet ?

Hmm if the page you want to redirect to also has the login portlet on it you can override login.jsp in a jsp hook and change the action url of the form to

<liferay-portlet:actionURL plid="THE PAGE ID GOES HERE" secure="<%= PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS || request.isSecure() %>" var="loginURL"?
<portlet:param name="saveLastPath" value="0" />
<portlet:param name="struts_action" value="/login/login" />
</liferay-portlet:actionURL>

That way the error messages will be displayed in the login portlet of the other page

If the page you want to redirect to does not contain a login portlet then i think all you can do is extend LoginAction in an ext plugin and do a redirect if there is an error eg. check for !SessionErrors.isEmpty()
gofri _,修改在13 年前。

RE: Auto Login Hook - Redirect to error page if authentication fails

Junior Member 帖子: 92 加入日期: 07-3-2 最近的帖子
10x a lot!