【问题标题】:Liferay cannot get user by screennameLiferay 无法通过用户名获取用户
【发布时间】:2012-09-18 03:01:36
【问题描述】:

我正在为 liferay 编写一个自动登录钩子,它试图通过屏幕名称获取用户。我正在使用以下代码获取用户,主要是OpenSSOAutoLogin的变体:

User user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName);

这在大多数情况下都有效,除非在 liferay 中记录的屏幕名称是大写的。例如,如果存储的 liferay 的屏幕名称是“TEST”,我将无法获取用户。堆栈跟踪显示如下:

com.liferay.portal.NoSuchUserException: No User exists with the key {companyId=1, screenName=test}
    at com.liferay.portal.service.persistence.UserPersistenceImpl.findByC_SN(UserPersistenceImpl.java:2789)
    at com.liferay.portal.service.impl.UserLocalServiceImpl.getUserByScreenName(UserLocalServiceImpl.java:2590)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
    at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
    at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
    at $Proxy103.getUserByScreenName(Unknown Source)
    at com.liferay.portal.service.UserLocalServiceUtil.getUserByScreenName(UserLocalServiceUtil.java:1625)
    at me.and.my.business.MyAutoLogin.login(MyAutoLogin.java:175)

跟踪清楚地表明“不存在具有键 screenName=test 的用户”。这里的 'test' 是小写的,但 getUserByScreenName() 方法是用大写的屏幕名称调用的。

经过一番研究,我发现liferay UserLocalServiceImpl中进行了小写转换。我想这是导致搜索失败的原因,但我不确定。

有人可以确认吗? liferay 的屏幕名称是否应始终为小写?

感谢您的建议。

【问题讨论】:

  • 我认为传递的companyId 不正确。

标签: liferay autologin opensso openam


【解决方案1】:

在保存新用户时,Liferay 总是将屏幕名称转换为小写。如您所说,该方法在 UserLocalServiceImpl.java 中找到

protected String getScreenName(String screenName) {
    return StringUtil.lowerCase(StringUtil.trim(screenName));
}

所以如果你在创建/更新用户时传入大写的屏幕名称并不重要,Liferay 总是会转换它。

【讨论】:

    猜你喜欢
    • 2022-06-14
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多