Fórum

Redirect on AutoLogin failure?

thumbnail
Andew Jardine, modificado 12 Anos atrás.

Redirect on AutoLogin failure?

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
I can't see to find the answer to this and my approach doesn't appear to be working. Here is what I have.

I create an class the implements the AutoLogin interface. This works without issue. Now what I am trying to do is have the PortalException handler (that occurs when the user is NOT found in the LR database) redirect the user to a fail page. I created a page called login-failed, and in my hook atempt to do a response.redirect("/web/guest/login-failed") ... but noticed that the system is trying to do the auto login from there as well. So I modified my portal.ext.properties file to contain these settings --

auth.public.paths=/web/guest/login-failed

auto.login.ignore.paths=/web/guest/login-failed

.. but neither appears to do anything as the issue persists. So my question is, how do I redirect a failed login attempt?!
thumbnail
Mani kandan, modificado 12 Anos atrás.

RE: Redirect on AutoLogin failure?

Expert Postagens: 492 Data de Entrada: 15/09/10 Postagens Recentes
You can use something like,


request.setAttribute(AutoLogin.AUTO_LOGIN_REDIRECT, "Your path");
return null;


Then also you can try,


response.sendRedirect( ( (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY)).getPathMain() );
return null;


Or try a hook
thumbnail
Andew Jardine, modificado 12 Anos atrás.

RE: Redirect on AutoLogin failure?

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hi Mani,

Thanks for taking the time to help me out. I've done as you suggested and set the request attribute for the AUTO_LOGIN_REDIRECT. Using teh debugger, I can see the value being set, and I can see the code in teh portal-impl using my value. However....

The redirect appears to be causing an infinite loop whcih I believe is the result of the portal-ext settings not being honored. I've tried to use this before and had no success last time either, but perhaps there is another attribute that works with it that I haven't set? Right now I have this in my file --

auto.login.ignore.paths=/web/guest/login-failed

is there another property that I need to see as well? I see one auto.login.ignore.hosts, but I don't want any hosts to be ignored. I am referencing my app using localhost, but that shouldn't matter (I mention only because I thought I saw something somewhere about this but I couldn't find it a second time).

Any further insight you can provide would really be appreciated.

aj.
thumbnail
Ali Shahrami, modificado 12 Anos atrás.

RE: Redirect on AutoLogin failure?

Junior Member Postagens: 52 Data de Entrada: 01/08/09 Postagens Recentes
Hi Andrew,

I'm not sure how you have implemented your AutoLogin but one thing I do know that by default LR redirect user to the login page when login failes. If there is a specific Exception that you want to redirect user to the "login-failed" page, then you might either redirect in your AutoLogin or even better redirect user using Hook.

I can think of three ways to handle this:
1) Try "login.events.pre" Hook. You do you own check to see if user exists or not and take action accordingly.
or
2) Try "login.events.post" Hook. I don't know when login fails you can use login post event. I would say give it a try.
or
3) use a client-side script (jQuery or javaScript) to redirect user from login page to your "login-failed" page. Not quit efficient but does the job.

Ali
thumbnail
Andew Jardine, modificado 12 Anos atrás.

RE: Redirect on AutoLogin failure?

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hi Ali,

The implementation of the AutoLogin hook that I am using is the standard appraoch (I think).

1. Create a class
2. Implments the AutoLogin interface
3. Provides an implementation for the login method() that --
a. Looks the user up by email address
b. creates the credentials array
c. returns the array of Strings.

as part of this implementation I have the following ---


		catch ( PortalException e )
		{
			log.error( "Portal exception occurred while trying to look up the user with email " + FAIL_EMAIL_ADDRESS, e );
			log.info( "User was not found in Liferay database. Redirecting user to page " + LOGIN_FAILED_PAGE );
			log.info( "Request attribute AutoLogin.AUTO_LOGIN_REDIRECT has been set." );
			
			request.setAttribute(AutoLogin.AUTO_LOGIN_REDIRECT, LOGIN_FAILED_PAGE );
			
			log.debug("Redirect attribute set.");
			
			return null;
		}


-- I'm forcing the fail to occur so I know that exception is being caught. I do see the redirect happening, so it's not a case of the redirect working now, I need to understand how to have the AutoLogin NOT FIRE for the /web/guest/login-failed path.

Any other ideas?
thumbnail
Ali Shahrami, modificado 12 Anos atrás.

RE: Redirect on AutoLogin failure?

Junior Member Postagens: 52 Data de Entrada: 01/08/09 Postagens Recentes
Andrew,

I hope I understood your use case correctly and here are couple of things that I'd like to add:

1) The PortalException is pretty generic Exception and it could mean exceptions other than NoSuchUserException. In your case you probably interested more in NoSuchUserException.

2) There are different ways to redirect user after a successful login, to a specific landing page, to user private pages, to last visited page. Which one are you using?

3) A good refference is to look into the com.liferay.portlet.login.action.LoginAction

Ali
thumbnail
Andew Jardine, modificado 12 Anos atrás.

RE: Redirect on AutoLogin failure?

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hi Ali,

I think you might have misunderstood. I am interested only in the FAILED login. Again, the redirection IS working, but the page I am redirected to is itself trying to perform the AutoLogin. I have configured it to be ignored by the AutoLogin, but it tries anyway.

I just managed to get it working but I have to have the property set to --

auto.login.ignore.paths=/web/guest/login-failed,/c/portal/layout

Can someone explain to me why I need to include /c/portal/layout in order for this to work?

The reason I am catching using PortalException is beacause regardless of what exception occurs, I want the user to go to the authentication failed page (since that is ultimately the result). I am logging the specific PortalException that has occurred though incase it is something other than the NoSuchUserException.