没有登录挂钩的liferay中的身份验证
authentication in liferay without login hook
我有一个问题,我得到了一个视图的用户和密码,我检查了 liferay 数据中的数据是否正确,当它正确时我的方法 return 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");
}
这似乎是您需要自动登录挂钩的情况。在 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创建一个钩子。
我有一个问题,我得到了一个视图的用户和密码,我检查了 liferay 数据中的数据是否正确,当它正确时我的方法 return 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");
}
这似乎是您需要自动登录挂钩的情况。在 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创建一个钩子。