Foren

ExpandoBridge Permission Error

Rice Owl, geändert vor 13 Jahren.

ExpandoBridge Permission Error

Regular Member Beiträge: 177 Beitrittsdatum: 24.04.09 Neueste Beiträge
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.

private void initExpando(ExpandoBridge expando) {
		LOG.debug("initExpando()");
		// TODO: Need to redo how the expando is initialized - need to have some other mechanism
		// to do this.
		try {
			if(!expando.hasAttribute(UserCommunicationPropsTO.PROPS_CELL_NUMBER)) {
				expando.addAttribute(UserCommunicationPropsTO.PROPS_CELL_NUMBER);
			}
			if(!expando.hasAttribute(UserCommunicationPropsTO.PROPS_CELL_PROVIDER)) {
				expando.addAttribute(UserCommunicationPropsTO.PROPS_CELL_PROVIDER);
			}
			if(!expando.hasAttribute(UserCommunicationPropsTO.PROPS_RECEIVE_EMAIL)) {
				expando.addAttribute(UserCommunicationPropsTO.PROPS_RECEIVE_EMAIL);
			}
			if(!expando.hasAttribute(UserCommunicationPropsTO.PROPS_RECEIVE_SMS)) {
				expando.addAttribute(UserCommunicationPropsTO.PROPS_RECEIVE_SMS);
			}
		} catch(PortalException e) {
			LOG.error("Exception while initExpando()", e);
		}
	}


Pretty straightforward method to add a property to a user's expando bridge. This method fails when the user is not an admin


public void setUserProperty(String remoteUserName, String propertyName,
			String propertyValue) throws UserNotFoundException {
		LOG.debug("setUserProperty()");
		LOG.debug("User id: " + remoteUserName);
		LOG.debug("[property, value] : [" + propertyName + ", " + propertyValue + "]");
		try {
			long userId = Long.parseLong(remoteUserName);
			User liferayUser = UserLocalServiceUtil.getUser(userId);
			if(liferayUser == null) {
				UserNotFoundException t = new UserNotFoundException(String.valueOf(userId));
				throw t;
			}
			ExpandoBridge exbridge = liferayUser.getExpandoBridge();
			exbridge.setAttribute(propertyName, propertyValue);
			LOG.debug("Property set via expando bridge.");
		} catch (PortalException e) {
			LOG.error("Exception thrown in setUserProperty()", e);
			// TODO: Handle exception
			
		} catch (SystemException e) {
			LOG.error("Exception thrown in setUserProperty()", e);
			// TODO: Handle exception
			
		}
		
	}


Pretty straightforward method on getting a property from the user's expando. This method fails when the user is not an admin

public String getUserProperty(String remoteUserName, String propertyName)
			throws UserNotFoundException {
		LOG.debug("getUserProperty()");
		LOG.debug("User id: " + remoteUserName);
		LOG.debug("Property Name: " + propertyName);
		try {
			long userId = Long.parseLong(remoteUserName);
			User liferayUser = UserLocalServiceUtil.getUser(userId);
			if(liferayUser == null) {
				UserNotFoundException t = new UserNotFoundException(String.valueOf(userId));
				throw t;
			}
			ExpandoBridge exbridge = liferayUser.getExpandoBridge();
			String ret = (String)exbridge.getAttribute(propertyName);
			LOG.debug("Property Value: " + ret);
			return ret;
			
		} catch (PortalException e) {
			LOG.error("Exception thrown in setUserProperty()", e);
			// TODO: Handle exception
			return null;
			
		} catch (SystemException e) {
			LOG.error("Exception thrown in setUserProperty()", e);
			// TODO: Handle exception
			return null;
		}
		
	}


Here is the exception stack trace:


[#|2010-06-17T21:14:19.599-0500|INFO|sun-appserver2.1|javax.enterprise.system.s$
com.liferay.portal.security.auth.PrincipalException
        at com.liferay.portlet.expando.service.permission.ExpandoColumnPermissi$
        at com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl.add$
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl$
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce$
        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!
thumbnail
Shagul Khajamohideen, geändert vor 13 Jahren.

RE: ExpandoBridge Permission Error

Liferay Master Beiträge: 758 Beitrittsdatum: 27.09.07 Neueste Beiträge
If you look at the ExpandoBridgeImpl code, you will notice that some of the calls are made to ServiceUtils and not the LocalServiceUtils. ServiceImpls' check for permission.

If you need to do something irrespective of the user you could use Expando*LocalServiceUtils.
StartupAction in WOL-Portlet can serve as an example.

You could give a user permission to update their own custom attribute so that ExpandoBridgeImpl can be used to update the attributes. You could refer to the code that allows you to set permissions for a custom attribute via the control panel to any role.


Best,
Shagul