Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sid L
Auto Login Hook - Redirect to error page if authentication fails
December 31, 2010 9:53 PM
Answer

Sid L

Rank: Junior Member

Posts: 28

Join Date: December 2, 2010

Recent Posts

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?
Jelmer Kuperus
RE: Auto Login Hook - Redirect to error page if authentication fails
January 1, 2011 9:22 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

You can try doing this when authentication fails in your AutoLogin.login implementation

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


And not throw the exception. Looking at the code of AutoLoginFilter that should work. But its kind of ugly
Sid L
RE: Auto Login Hook - Redirect to error page if authentication fails
January 3, 2011 3:51 AM
Answer

Sid L

Rank: Junior Member

Posts: 28

Join Date: December 2, 2010

Recent Posts

Thanks a lot . This solution worked for me
gofri _
RE: Auto Login Hook - Redirect to error page if authentication fails
January 28, 2011 3:25 AM
Answer

gofri _

Rank: Junior Member

Posts: 92

Join Date: March 2, 2007

Recent Posts

I have similar question - is there a way to redirect users to another page when authentication fails?
I mean with hook.
Faris Abdulla
RE: Auto Login Hook - Redirect to error page if authentication fails
January 28, 2011 7:12 AM
Answer

Faris Abdulla

Rank: Regular Member

Posts: 183

Join Date: September 1, 2009

Recent Posts

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 _
RE: Auto Login Hook - Redirect to error page if authentication fails
January 28, 2011 7:53 AM
Answer

gofri _

Rank: Junior Member

Posts: 92

Join Date: March 2, 2007

Recent Posts

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.
Jelmer Kuperus
RE: Auto Login Hook - Redirect to error page if authentication fails
January 28, 2011 11:27 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

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 _
RE: Auto Login Hook - Redirect to error page if authentication fails
January 28, 2011 11:03 AM
Answer

gofri _

Rank: Junior Member

Posts: 92

Join Date: March 2, 2007

Recent Posts

10x a lot!