Liferay无法通过screenname获取用户

时间:2012-09-26 13:10:36

标签: liferay autologin opensso openam

我正在为liferay编写一个自动挂载钩子,它试图通过screenname获取用户。我正在使用以下代码来获取用户,这主要是OpenSSOAutoLogin的变体:

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

这在大多数情况下都有效,除非在liferay中记录的screenname是大写的。例如,如果存储的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()方法是用大写的screenname调用的。

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

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

感谢您的建议。

1 个答案:

答案 0 :(得分:0)

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

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

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