Liferay-自动登录+身份验证程序-从请求标头获取凭据
我需要有关Liferay Autologin和自定义身份验证的帮助 我的目标是从由不同身份验证框架填充的头中获取凭据,然后自动登录。我还需要在用户登录时调用一些服务 我也读了一些文件,但我还是不明白 我用portal.properties做了一个钩子:Liferay-自动登录+身份验证程序-从请求标头获取凭据,liferay,Liferay,我需要有关Liferay Autologin和自定义身份验证的帮助 我的目标是从由不同身份验证框架填充的头中获取凭据,然后自动登录。我还需要在用户登录时调用一些服务 我也读了一些文件,但我还是不明白 我用portal.properties做了一个钩子: auto.login.hooks=it.mypackage.filter.AutoLoginFilter auth.pipeline.pre=it.mypackage.auth.MyAuthenticator auth.pipeline.ena
auto.login.hooks=it.mypackage.filter.AutoLoginFilter
auth.pipeline.pre=it.mypackage.auth.MyAuthenticator
auth.pipeline.enable.liferay.check=false
班级:
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中,我假设只返回用户名,而不需要验证其他凭据
然后使用portal-ext.properties创建一个ext:
auto.login.hooks=it.mypackage.filter.AutoLoginFilter
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
我得到的是:
调用了AutoLoginFilter.login,但用户仍被重定向到登录页面。
MyAuthenticator从未调用它只有在我移除AutoLogin钩子并
同时删除auth.pipeline.enable.liferay.check=false属性
感谢您的帮助。返回的数组首先必须包含用户ID,类似这样的内容必须有效:
String[] credentials = new String[3];
credentials[0] = userId;
credentials[1] = "undefined";
credentials[2] = Boolean.FALSE.toString();
可以在控制面板->用户->中找到的用户ID
或者更好的方法是使用UserLocalServiceUtil.getUserByEmailAddresscompanyId、emailAddress加载它
此方法不需要auth.pipeline。返回的数组首先必须包含userId,类似这样的内容必须有效:
String[] credentials = new String[3];
credentials[0] = userId;
credentials[1] = "undefined";
credentials[2] = Boolean.FALSE.toString();
可以在控制面板->用户->中找到的用户ID
或者更好的方法是使用UserLocalServiceUtil.getUserByEmailAddresscompanyId、emailAddress加载它
此方法不需要auth.pipeline。谢谢标记:我找不到关于字符串[]凭据=新字符串[3]的文档;凭证[0]=用户ID;凭证[1]=未定义;凭据[2]=Boolean.FALSE.toString;第三个参数设置为false是什么?还有其他参数吗?类似于其他很多东西,我在liferay source中查看这些东西。第二个参数是密码,最后一个参数是密码验证。当最后一个参数设置为“false”时,则密码不相关。谢谢标记:在此处我找不到有关字符串[]凭据=新字符串[3]的文档;凭证[0]=用户ID;凭证[1]=未定义;凭据[2]=Boolean.FALSE.toString;第三个参数设置为false是什么?还有其他参数吗?类似于其他很多东西,我在liferay source中查看这些东西。第二个参数是密码,最后一个参数是密码验证。当最后一个参数设置为“false”时,则密码不相关。