When I tried to use autologin in Liferay6.1.20, I found something strange.
1. I create a hook to do autologin test.
In the portal.properties, I add the setting to my autologin filter: auto.login.hooks=com.rujuan.filter.MyAutoLogin
2. I create my class like this:
package com.rujuan.filter;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.security.auth.AutoLogin;
import com.liferay.portal.security.auth.AutoLoginException;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyAutoLogin implements AutoLogin {
private static Log _log = LogFactoryUtil.getLog(MyAutoLogin.class);
@Override
public String[] login(HttpServletRequest req, HttpServletResponse response)
throws AutoLoginException {
System.out.println("*****************************");
String[] credentials = new String[3];
String userName = req.getParameter("userName");
long companyId = 0;
try {
companyId = PortalUtil.getCompany(req).getCompanyId();
User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, "test@liferay.com");
credentials[0] = String.valueOf(user.getUserId());
credentials[1] = userName;
credentials[2] = Boolean.FALSE.toString();
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
_log.error("why don't call?");
return credentials;
}
}
I don't know why the method isn't invoked. I also try to use portal-ext.properties in the first step. It also doesn't work.
************************************************************************************************************************************
Then I create a Ext plugins to do the same thing. It works.
1. Instead putting the setting in the portal.properties, this time we put it in portal-ext.properties.
2. In the WEB-INF/ext-impl/src folder, we create our own classes as before.
The login method is also called when we deploy the ext plugins. It's also called when I log out. It seems the method is called in different situations. Previously, when I did the same Ext plugins, it gives me an error when I deploy or restart server. This time it doesn't. All the things are strange.