Fórum

Can't get AutoLogin to work

Manfred Paulus, modificado 14 Anos atrás.

Can't get AutoLogin to work

New Member Postagens: 2 Data de Entrada: 16/07/09 Postagens Recentes
Hi,

I'm using Liferay 5.2.3 on a linux machine with tomcat 6.0.18 and JRE 1.6.0_11.

I want to change the Liferay login mechanism so that I can do the authentication checking by my own, independent from the users configured in Liferay. When my own authentication checking accepts a user/password combination, I want to get logged in to Liferay with a special Liferay user that I did create for that purpose, e.g. user1.

So I made a copy of SiteMinderAutoLogin.java, named it AssistantLogin.java and changed it to my needs as you can see here:

[font=Courier New]package com.liferay.portal.security.auth;

import java.util.Map;

import com.liferay.portal.NoSuchUserException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.User;
import com.liferay.portal.security.ldap.PortalLDAPUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.util.PrefsPropsUtil;
import com.liferay.portal.util.PropsKeys;
import com.liferay.portal.util.PropsValues;
import com.liferay.portal.service.UserLocalServiceUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AssistantLogin implements AutoLogin {

	public String[] login(
		HttpServletRequest request, HttpServletResponse response) {

		String[] credentials = null;

		System.out.println( "Running AssistantLogin" );
		
		try {
		    User user = UserLocalServiceUtil.getUserById(10801);
//		    10801 is the User ID of user "user1"
		    if (user != null) {
		        credentials = new String[3];
		        credentials[0] = user.getLogin();
		        credentials[1] = user.getPassword();
		        credentials[2] = Boolean.TRUE.toString();
		    }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (credentials == null) {
                System.out.println("autologin FAILED");
            } else {
                System.out.print("autologin SUCCEEDED for ");
                System.out.println(credentials[0]);
            }
            System.out.println("##### RemoteUserAutoLogin end #####");          
        }
		
		return credentials;
	}

}
[/font]


Then I added
auto.login.hooks=com.liferay.portal.security.auth.AssistantLogin
to portal-ext.properties.

As a first test, I do no checking at all. So I expect, whatever I enter into the login mask, I always will get logged in as user1.

From the output in catalina.out I can see, that the code of my hook is executed.
But I always get logged in as the user I enter into the login mask, or I get not logged in at all when I enter something that Liferay doesn't know.

Can anybody give me a hint what I am doing wrong?

By the way: I changed authentication method from "By Email Address" to "By Screen Name", but I think that doesn't matter.

Manfred
Manfred Paulus, modificado 14 Anos atrás.

Solved: Can't get AutoLogin to work

New Member Postagens: 2 Data de Entrada: 16/07/09 Postagens Recentes
Ok, I found out what was wrong:

Whatever authentication method is configured in Liferay, AutoLogin always wants the user ID in credentials[0], not the user name.
It also always wants the password in clear text in credentials[1] and not encrypted like user.getPassword() returns.

I hope this will save some Newby like me some time.

Manfred