我正在爲liferay編寫自動登錄鉤子,它嘗試通過screenname獲取用戶。我用下面的代碼來獲得用戶,這主要是OpenSSOAutoLogin變化:Liferay無法通過screenname獲取用戶
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()方法是用大寫的screenname調用的。
經過一番研究,我發現在liferay UserLocalServiceImpl中執行了小寫轉換。我想這是導致搜索失敗的原因,但我不確定。
任何人都可以證實嗎?生命週期屏幕名稱是否應始終爲小寫?
感謝您的諮詢。
我認爲'companyId'通過是不正確的。 –