0

我正在为 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 的用户”。这里的“测试”是用小写字母写的,但是 getUserByScreenName() 方法是用大写的屏幕名称调用的。

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

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

谢谢你的建议。

4

1 回答 1

0

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

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

因此,如果您在创建/更新用户时传入大写的屏幕名称并不重要,Liferay 将始终对其进行转换。

于 2012-09-26T19:58:58.037 回答