Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Andew Jardine
Redirect on AutoLogin failure?
15 de Setembro de 2011 11:29
Resposta

Andew Jardine

Ranking: Regular Member

Mensagens: 236

Data de entrada: 22 de Dezembro de 2010

Mensagens 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?!
Manikandan S
RE: Redirect on AutoLogin failure?
15 de Setembro de 2011 23:21
Resposta

Manikandan S

Ranking: Expert

Mensagens: 492

Data de entrada: 15 de Setembro de 2010

Mensagens recentes

You can use something like,

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


Then also you can try,

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


Or try a hook
Andew Jardine
RE: Redirect on AutoLogin failure?
16 de Setembro de 2011 11:07
Resposta

Andew Jardine

Ranking: Regular Member

Mensagens: 236

Data de entrada: 22 de Dezembro de 2010

Mensagens 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.
Ali Shahrami
RE: Redirect on AutoLogin failure?
16 de Setembro de 2011 11:35
Resposta

Ali Shahrami

Ranking: Junior Member

Mensagens: 52

Data de entrada: 31 de Julho de 2009

Mensagens 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
Andew Jardine
RE: Redirect on AutoLogin failure?
16 de Setembro de 2011 11:47
Resposta

Andew Jardine

Ranking: Regular Member

Mensagens: 236

Data de entrada: 22 de Dezembro de 2010

Mensagens 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 ---

 1
 2        catch ( PortalException e )
 3        {
 4            log.error( "Portal exception occurred while trying to look up the user with email " + FAIL_EMAIL_ADDRESS, e );
 5            log.info( "User was not found in Liferay database. Redirecting user to page " + LOGIN_FAILED_PAGE );
 6            log.info( "Request attribute AutoLogin.AUTO_LOGIN_REDIRECT has been set." );
 7            
 8            request.setAttribute(AutoLogin.AUTO_LOGIN_REDIRECT, LOGIN_FAILED_PAGE );
 9            
10            log.debug("Redirect attribute set.");
11            
12            return null;
13        }


-- 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?
Ali Shahrami
RE: Redirect on AutoLogin failure?
16 de Setembro de 2011 12:30
Resposta

Ali Shahrami

Ranking: Junior Member

Mensagens: 52

Data de entrada: 31 de Julho de 2009

Mensagens 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
Andew Jardine
RE: Redirect on AutoLogin failure?
16 de Setembro de 2011 12:35
Resposta

Andew Jardine

Ranking: Regular Member

Mensagens: 236

Data de entrada: 22 de Dezembro de 2010

Mensagens 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.