Hi all,
I'm using the ExpandoBridge to add some custom attributes to a user profile. While logged in as an admin, it works fine. However, if I use a non-admin account I get a security exception when trying to either view or put attributes on the user's profile. Is there a setting somewhere that will allow non-administrators from manipulating and viewing attributes in the ExpandoBridge? Any help would be much appreciated. I'm using Liferay 5.2.3 on Glassfish.
here is a sample of my code.
This method gets executed before an attribute is attempted to retrieved or written to.. this was to fix a problem I had with not adding the attribute before setting it, which makes sense.
1private void initExpando(ExpandoBridge expando) {
2 LOG.debug("initExpando()");
3 // TODO: Need to redo how the expando is initialized - need to have some other mechanism
4 // to do this.
5 try {
6 if(!expando.hasAttribute(UserCommunicationPropsTO.PROPS_CELL_NUMBER)) {
7 expando.addAttribute(UserCommunicationPropsTO.PROPS_CELL_NUMBER);
8 }
9 if(!expando.hasAttribute(UserCommunicationPropsTO.PROPS_CELL_PROVIDER)) {
10 expando.addAttribute(UserCommunicationPropsTO.PROPS_CELL_PROVIDER);
11 }
12 if(!expando.hasAttribute(UserCommunicationPropsTO.PROPS_RECEIVE_EMAIL)) {
13 expando.addAttribute(UserCommunicationPropsTO.PROPS_RECEIVE_EMAIL);
14 }
15 if(!expando.hasAttribute(UserCommunicationPropsTO.PROPS_RECEIVE_SMS)) {
16 expando.addAttribute(UserCommunicationPropsTO.PROPS_RECEIVE_SMS);
17 }
18 } catch(PortalException e) {
19 LOG.error("Exception while initExpando()", e);
20 }
21 }
Pretty straightforward method to add a property to a user's expando bridge. This method fails when the user is not an admin
1
2public void setUserProperty(String remoteUserName, String propertyName,
3 String propertyValue) throws UserNotFoundException {
4 LOG.debug("setUserProperty()");
5 LOG.debug("User id: " + remoteUserName);
6 LOG.debug("[property, value] : [" + propertyName + ", " + propertyValue + "]");
7 try {
8 long userId = Long.parseLong(remoteUserName);
9 User liferayUser = UserLocalServiceUtil.getUser(userId);
10 if(liferayUser == null) {
11 UserNotFoundException t = new UserNotFoundException(String.valueOf(userId));
12 throw t;
13 }
14 ExpandoBridge exbridge = liferayUser.getExpandoBridge();
15 exbridge.setAttribute(propertyName, propertyValue);
16 LOG.debug("Property set via expando bridge.");
17 } catch (PortalException e) {
18 LOG.error("Exception thrown in setUserProperty()", e);
19 // TODO: Handle exception
20
21 } catch (SystemException e) {
22 LOG.error("Exception thrown in setUserProperty()", e);
23 // TODO: Handle exception
24
25 }
26
27 }
Pretty straightforward method on getting a property from the user's expando. This method fails when the user is not an admin
1
2public String getUserProperty(String remoteUserName, String propertyName)
3 throws UserNotFoundException {
4 LOG.debug("getUserProperty()");
5 LOG.debug("User id: " + remoteUserName);
6 LOG.debug("Property Name: " + propertyName);
7 try {
8 long userId = Long.parseLong(remoteUserName);
9 User liferayUser = UserLocalServiceUtil.getUser(userId);
10 if(liferayUser == null) {
11 UserNotFoundException t = new UserNotFoundException(String.valueOf(userId));
12 throw t;
13 }
14 ExpandoBridge exbridge = liferayUser.getExpandoBridge();
15 String ret = (String)exbridge.getAttribute(propertyName);
16 LOG.debug("Property Value: " + ret);
17 return ret;
18
19 } catch (PortalException e) {
20 LOG.error("Exception thrown in setUserProperty()", e);
21 // TODO: Handle exception
22 return null;
23
24 } catch (SystemException e) {
25 LOG.error("Exception thrown in setUserProperty()", e);
26 // TODO: Handle exception
27 return null;
28 }
29
30 }
Here is the exception stack trace:
1
2[#|2010-06-17T21:14:19.599-0500|INFO|sun-appserver2.1|javax.enterprise.system.s$
3com.liferay.portal.security.auth.PrincipalException
4 at com.liferay.portlet.expando.service.permission.ExpandoColumnPermissi$
5 at com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl.add$
6 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
7 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl$
8 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce$
9 at java.lang.reflect.Method.invoke(Method.java:597)
Any help would be much appreciated. I'm sure I'm missing something where I'm supposed to set the permissions, but I can't figure out where to do it.
Thanks!
Please sign in to flag this as inappropriate.