Liferay-自动登录+身份验证器-从请求标头中获取凭据 [英] Liferay - AutoLogin + Authenticator - Get Credentials From Request Header
问题描述
我需要有关Liferay自动登录和自定义身份验证的帮助.
I need help with Liferay Autologin and Custom Authentication.
我的目标是从标头(由Differents身份验证框架填充)中获取凭据,然后自动登录.用户登录时,我还必须致电某些服务.
My goal is to get credentials from header (populated by differents authentication framework) and then autologin. I have also to call some services when user login.
我已经阅读了一些文档(也来自 http://www.liferay.com/community/wiki/-/wiki/Main/Developing+a+Custom+Authentication+System ),但我还是不明白.
I've read some docs (also that one at http://www.liferay.com/community/wiki/-/wiki/Main/Developing+a+Custom+Authentication+System) but still I doesn't understand.
我已经完成了与portal.properties的连接:
I've done a hook with portal.properties:
auto.login.hooks=it.mypackage.filter.AutoLoginFilter
和班级:
public class AutoLoginFilter implements AutoLogin {
public AutoLoginFilter() {
super();
}
@Override
public String[] login(HttpServletRequest req, HttpServletResponse arg1) throws AutoLoginException {
String[] credentials = new String[] { "test@liferay.com" };
return credentials;
}
}
在示例类AutoLogin中,我想只返回用户名(我不需要验证其他凭据).
In the example class AutoLogin I suppose to return just the username (I doesn' need to verify other credentials).
然后我用portal-ext.properties创建一个ext:
Then I create a ext with portal-ext.properties:
auth.pipeline.pre=it.mypackage.auth.MyAuthenticator
auth.pipeline.enable.liferay.check=false
和身份验证器:
public class MyAuthenticator implements Authenticator {
private static Log _log = LogFactory.getLog(SwaFiamAuthenticator.class);
@Override
public int authenticateByEmailAddress(long companyId, String emailAddress, String password,
Map<String, String[]> headerMap, Map<String, String[]> parameterMap) throws AuthException {
return authenticate();
}
@Override
public int authenticateByScreenName(long companyId, String screenName, String password,
Map<String, String[]> headerMap, Map<String, String[]> parameterMap) throws AuthException {
return authenticate();
}
@Override
public int authenticateByUserId(long companyId, long userId, String password, Map<String, String[]> headerMap,
Map<String, String[]> parameterMap) throws AuthException {
return authenticate();
}
protected int authenticate() {
_log.debug("returning SUCCESS");
return SUCCESS;
}
}
我对代码的期望是:
每个进入门户的用户都会自动进行身份验证,而不会看到任何登录页面,并且被识别为用户"test@liferay.com"
Every user entering the portal is automatically authenticated without seeing any login page, and is recognized as user "test@liferay.com"
我得到的东西:
AutoLoginFilter.login被调用,但是用户仍被重定向到登录页面. MyAuthenticator从未调用过(仅当我删除AutoLogin-hook和 还要删除auth.pipeline.enable.liferay.check = false属性).
AutoLoginFilter.login is called, but the user is still redirected to login page. MyAuthenticator never called (it's called only if I remove AutoLogin-hook and remove also auth.pipeline.enable.liferay.check=false property).
感谢帮助.
推荐答案
返回的数组必须首先包含userId,类似这样的东西必须起作用:
The returned array must contains at first the userId, something like this must work:
String[] credentials = new String[3];
credentials[0] = userId;
credentials[1] = "undefined";
credentials[2] = Boolean.FALSE.toString();
您可以在控制面板->用户-> ...中找到的用户ID
the userId you can find in Control Panel -> Users ->...
或(更好的方式)使用UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);
or (better way) load it programmaticaly with UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);
此方法不需要auth.pipeline
.
这篇关于Liferay-自动登录+身份验证器-从请求标头中获取凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!