没有登录钩子的liferay中的身份验证

时间:2016-10-04 22:52:40

标签: authentication java-ee liferay hook liferay-hook

我有一个问题,我得到一个视图的用户和密码,我检查liferay数据中的数据是否正确,当它正确时,如果验证为真,我的方法返回1,但是我我不知道如何在liferay中成功登录,这是我的方法:

try {
        long companyId = PortalUtil.getDefaultCompanyId();
        System.out.println(companyId + " id company");
        User user1;
        try {
            user1 = UserLocalServiceUtil.getUserByEmailAddress(companyId,     name);
            long cmp = user1.getCompanyId();
            Company company = CompanyLocalServiceUtil.getCompany(cmp);
            int a =      UserLocalServiceUtil.authenticateByUserId(company.getCompanyId(), user.getId(), pass, null,
                    null, null);
            if (a == 1) {

                System.out.println("Log in successful");

            }
        } catch (PortalException e) {
            e.printStackTrace();
        } catch (SystemException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        System.out.println("algo salio mal");
    }

1 个答案:

答案 0 :(得分:1)

这似乎是您需要自动登录挂钩的情况。在Liferay 7中,您只需要像https://www.e-systems.tech/blog/-/blogs/autologin-in-liferay-7

这样的组件

您可以在用户会话中使用指标,如令牌,并在自定义逻辑中进行检查:

@Override
protected String[] doLogin(final HttpServletRequest request, final HttpServletResponse response) throws Exception {

    final long companyId = portal.getCompanyId(request);
    final HttpSession session = request.getSession();

        // code your logic here..

    final String[] credentials = new String[3];

    credentials[0] = String.valueOf(user.getUserId());
    credentials[1] = user.getPassword();
    credentials[2] = Boolean.FALSE.toString();

    return credentials;
}

此解决方案对LR6也有效,不同之处在于您没有在那里使用OSGi,因此您必须通过SDK创建一个钩子。