Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Dave Weitzel
Allowing Guests to set expando Attributes
March 27, 2013 2:14 PM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 186

Join Date: November 18, 2009

Recent Posts

Hi,
continuing my trials and tribulations on coding a user applying to join a web site (surely a use case for training?) I cracked the login issue:
https://www.liferay.com/community/forums/-/message_boards/message/23076064
but now have hit a problem with Expando fields.

The application form has new fields for the user profile (member-type etc).
I can manually set these to always be updated by guest users and things work well but that would leave things open.
So I tried using this method to set the attribute as RW by guest:
 1  public static void setGuestPermissionOnExpandoColumn(long groupId, long companyId, String attr){
 2        try{
 3            Role guestRole = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST);
 4             String[] actionsRW = new String[] { ActionKeys.VIEW, ActionKeys.UPDATE };
 5            ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge( companyId, User.class.getName());
 6            ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
 7                     companyId,  expandoBridge.getClassName(),
 8                     ExpandoTableConstants.DEFAULT_TABLE_NAME,
 9                     attr);   
10            _log.info("set expando name = " + ExpandoColumn.class.getName() + " Columnid= "  +
11                    String.valueOf(column.getColumnId()) + " roleid= " + guestRole.getRoleId());   
12            
13            ResourcePermissionServiceUtil.setIndividualResourcePermissions(groupId, companyId,
14                    ExpandoColumn.class.getName(), String.valueOf(column.getColumnId()),
15                    guestRole.getRoleId(), actionsRW);
16        }catch (Exception e){
17            e.printStackTrace();
18        }
19    }


However I am now getting an error because I am calling this as a guest still (setting them read write first before adding user and logging said user in).

 120:53:15,025 INFO  [http-bio-8080-exec-21][ActionUtil:343] set expando name = com.liferay.portlet.expando.model.ExpandoColumn Columnid= 15201 roleid= 10161
 2com.liferay.portal.security.auth.PrincipalException
 3    at com.liferay.portal.service.impl.PermissionServiceImpl.checkPermission(PermissionServiceImpl.java:700)
 4    at com.liferay.portal.service.impl.PermissionServiceImpl.checkPermission(PermissionServiceImpl.java:140)
 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:122)
10    at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
11    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
12    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
13    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
14    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
15    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
16    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
17    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
18    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
19    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
20    at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:133)
21    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
22    at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
23    at $Proxy57.checkPermission(Unknown Source)
24    at com.liferay.portal.service.impl.ResourcePermissionServiceImpl.setIndividualResourcePermissions(ResourcePermissionServiceImpl.java:192)
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.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
30    at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
31    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
32    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
33    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
34    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
35    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
36    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
37    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
38    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
39    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
40    at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:133)
41    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
42    at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
43    at $Proxy85.setIndividualResourcePermissions(Unknown Source)
44    at com.liferay.portal.service.ResourcePermissionServiceUtil.setIndividualResourcePermissions(ResourcePermissionServiceUtil.java:204)
45    at com.plaza.membership.ActionUtil.setGuestPermissionOnExpandoColumn(ActionUtil.java:345)
46    at com.plaza.membership.ActionUtil.setGuestPermissionOnExpandoColumns(ActionUtil.java:330)
47    at com.plaza.membership.ActionUtil.addUser(ActionUtil.java:169)
48    at com.plaza.membership.UserPortlet.join(UserPortlet.java:177)
49    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Am I right in thinking this is what is happening (trying as guest to set permissions on these attributes) and if so can anyone think of how this can be done?

Thanks