Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Ken Driscoll
Custom User Field Issue
10 luglio 2012 15.29
Risposta

Ken Driscoll

Punteggio: Junior Member

Messaggi: 57

Data di Iscrizione: 2 luglio 2012

Messaggi recenti

I am trying to add a custom field to a newly created user.

Here is the code I am trying:
1           User newUser = UserLocalServiceUtil.addUser(creatorUserId, 1, autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName1, middleName, lastName1, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
2          
3           if(!newUser.getExpandoBridge().hasAttribute("Employee_Id")){
4               newUser.getExpandoBridge().addAttribute("Employee_Id");
5           }
6           newUser.getExpandoBridge().setAttribute("Employee_Id", employeeId);


However when I run the method, the custom field is not created and I get the following error:

  1com.liferay.portal.security.auth.PrincipalException
  2    at com.liferay.portal.service.permission.PortletPermissionImpl.check(PortletPermissionImpl.java:146)
  3    at com.liferay.portal.service.permission.PortletPermissionUtil.check(PortletPermissionUtil.java:108)
  4    at com.liferay.portlet.expando.service.impl.ExpandoColumnServiceImpl.addColumn(ExpandoColumnServiceImpl.java:45)
  5    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  6    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  7    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  8    at java.lang.reflect.Method.invoke(Method.java:597)
  9    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:112)
 10    at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
 11    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
 12    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
 13    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
 14    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
 15    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
 16    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
 17    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
 18    at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
 19    at $Proxy140.addColumn(Unknown Source)
 20    at com.liferay.portlet.expando.service.ExpandoColumnServiceUtil.addColumn(ExpandoColumnServiceUtil.java:52)
 21    at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.addAttribute(ExpandoBridgeImpl.java:133)
 22    at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.addAttribute(ExpandoBridgeImpl.java:80)
 23    at com.liferay.portal.security.auth.CustomAuthenticator.doCreateNewUser(CustomAuthenticator.java:160)
 24    at com.liferay.portal.security.auth.CustomAuthenticator.authenticateByEmailAddress(CustomAuthenticator.java:100)
 25    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 26    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 27    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 28    at java.lang.reflect.Method.invoke(Method.java:597)
 29    at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
 30    at $Proxy373.authenticateByEmailAddress(Unknown Source)
 31    at com.liferay.portal.security.auth.AuthPipeline._authenticate(AuthPipeline.java:224)
 32    at com.liferay.portal.security.auth.AuthPipeline.authenticateByEmailAddress(AuthPipeline.java:39)
 33    at com.liferay.portal.service.impl.UserLocalServiceImpl.authenticate(UserLocalServiceImpl.java:4943)
 34    at com.liferay.portal.service.impl.UserLocalServiceImpl.authenticateByEmailAddress(UserLocalServiceImpl.java:851)
 35    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 36    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 37    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 38    at java.lang.reflect.Method.invoke(Method.java:597)
 39    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:112)
 40    at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
 41    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
 42    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
 43    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
 44    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
 45    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
 46    at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
 47    at $Proxy96.authenticateByEmailAddress(Unknown Source)
 48    at com.liferay.portal.service.UserLocalServiceUtil.authenticateByEmailAddress(UserLocalServiceUtil.java:571)
 49    at com.liferay.portlet.login.util.LoginUtil.getAuthenticatedUserId(LoginUtil.java:153)
 50    at com.liferay.portlet.login.util.LoginUtil.login(LoginUtil.java:243)
 51    at com.liferay.portlet.login.action.LoginAction.login(LoginAction.java:189)
 52    at com.liferay.portlet.login.action.LoginAction.processAction(LoginAction.java:88)
 53    at com.liferay.portal.struts.PortletRequestProcessor.process(PortletRequestProcessor.java:175)
 54    at com.liferay.portlet.StrutsPortlet.processAction(StrutsPortlet.java:190)
 55    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
 56    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
 57    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:651)
 58    at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:686)
 59    at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:361)
 60    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:845)
 61    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:633)
 62    at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:244)
 63    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 64    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 65    at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:174)
 66    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 67    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 68    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
 69    at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:533)
 70    at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:510)
 71    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 72    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 73    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 74    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
 75    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
 76    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
 77    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
 78    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
 79    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:201)
 80    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
 81    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
 82    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
 83    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
 84    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:240)
 85    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
 86    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
 87    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
 88    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
 89    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 90    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 91    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
 92    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
 93    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
 94    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
 95    at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:135)
 96    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 97    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 98    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 99    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
100    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
101    at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:304)
102    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
103    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
104    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
105    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
106    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
107    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
108    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
109    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
110    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
111    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
112    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:201)
113    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
114    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
115    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
116    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
117    at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:241)
118    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
119    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
120    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
121    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
122    at com.liferay.portal.servlet.filters.etag.ETagFilter.processFilter(ETagFilter.java:55)
123    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
124    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
125    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
126    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
127    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:240)
128    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
129    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
130    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
131    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
132    at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
133    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
134    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
135    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
136    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
137    at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:80)
138    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
139    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
140    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
141    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
142    at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:208)
143    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
144    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
145    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
146    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:184)
147    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
148    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
149    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
150    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
151    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:164)
152    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
153    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:164)
154    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
155    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:184)
156    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
157    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
158    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
159    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
160    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
161    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
162    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
163    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
164    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
165    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
166    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
167    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
168    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
169    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
170    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
171    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
172    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
173    at java.lang.Thread.run(Thread.java:619)


I have tried a couple of different methods with no success. Any assistance would be greatly appreciated.
Mk Sin
RE: Custom User Field Issue
10 luglio 2012 19.28
Risposta

Mk Sin

Punteggio: Junior Member

Messaggi: 74

Data di Iscrizione: 25 maggio 2012

Messaggi recenti

go to control panel -> your site -> custom fields -> select your expando key -> click on action and select permission -> on permission page, check permission to view for all your role (within "user" role)

i think it can help ^^, i'm not good at english, sr for that
Amit Doshi
RE: Custom User Field Issue
10 luglio 2012 23.34
Risposta

Amit Doshi

Punteggio: Liferay Master

Messaggi: 549

Data di Iscrizione: 29 dicembre 2010

Messaggi recenti

Hi Ken,

Simply adding newUser.getExpandoBridge().addAttribute("Employee_Id");, will not create Custom Attribute for you.

Please check below link. It will help you to create Custom Attribute with the help of Coding in liferay.

http://www.liferay.com/community/wiki/-/wiki/Main/Developing+with+Expando

Thanks & Regards,
Amit Doshi
Mazhar Alam
RE: Custom User Field Issue
10 luglio 2012 23.58
Risposta

Mazhar Alam

Punteggio: Regular Member

Messaggi: 201

Data di Iscrizione: 25 novembre 2011

Messaggi recenti

Helpful post
Ken Driscoll
RE: Custom User Field Issue
11 luglio 2012 7.38
Risposta

Ken Driscoll

Punteggio: Junior Member

Messaggi: 57

Data di Iscrizione: 2 luglio 2012

Messaggi recenti

I managed to get it working. I had been avoiding initializing the field from the Liferay GUI.

What worked for me:
1. Go to control panel.
2. On the left panel under "Portal" click Custom Fields.
3. Click on the resource you want to add the field to (in my case "User").
4. Click "Add custom field" and make whatever field you want.
5. Now you should see your custom field listed. Click "Actions" next to it and select "Permissions".
6. Select "View" and "Update" for all roles and click save.

Now your field is initialized and a brand new user should be able to set it.
All you need to call in your code after you've created your new user is:
1newUser.getExpandoBridge().setAttribute("CustomFieldName", customFieldValue);


I hope this helps some people who have been struggling with this issue.

I will admit there are some downsides to this method though. If you don't want to have to use the GUI to create the field, or don't want our user to be able to edit it's value once set, then perhaps try Amit's link above.