Liferay - AutoLogin +身份验证器 - 从请求标头获取凭据

Gua*_*o79 1 liferay

我需要Liferay Autologin和自定义身份验证方面的帮助.

我的目标是从头文件(由不同的身份验证框架填充)然后自动登录获取凭据.我还要在用户登录时调用一些服务.

我已经阅读了一些文档(也是http://www.liferay.com/community/wiki/-/wiki/Main/Developing+a+Custom+Authentication+System上的文档),但我仍然不明白.

我用portal.properties做了一个钩子:

auto.login.hooks=it.mypackage.filter.AutoLoginFilter
Run Code Online (Sandbox Code Playgroud)

和班级:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

在示例类AutoLogin中,我想只返回用户名(我不需要验证其他凭据).

然后我用portal-ext.properties创建一个ext:

auth.pipeline.pre=it.mypackage.auth.MyAuthenticator
auth.pipeline.enable.liferay.check=false
Run Code Online (Sandbox Code Playgroud)

和验证者:

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;
    }

}
Run Code Online (Sandbox Code Playgroud)

我对代码的期望是:

进入门户网站的每个用户都会自动进行身份验证,而不会看到任何登录页面,并被识别为用户"test@liferay.com"

我得到了什么:

调用AutoLoginFilter.login,但仍然将用户重定向到登录页面.MyAuthenticator从未调用过(仅当我删除AutoLogin-hook并删除auth.pipeline.enable.liferay.check = false属性时才调用它).

感谢帮助.

Mar*_*ark 5

返回的数组必须首先包含userId,这样的东西必须工作:

            String[] credentials = new String[3];
            credentials[0] = userId;
            credentials[1] = "undefined";
            credentials[2] = Boolean.FALSE.toString();
Run Code Online (Sandbox Code Playgroud)

您可以在控制面板 - >用户 - >中找到userId ...

或(更好的方式)加载程序式 UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);

auth.pipeline不需要这种方法.