Forums de discussion

Security exception when adding user to a community

thumbnail
Bla Bla, modifié il y a 13 années.

Security exception when adding user to a community

Junior Member Publications: 79 Date d'inscription: 22/12/10 Publications récentes
Hi all,

I'm trying to add programmatically a user I just created to a community :

long[] userIds = {user.getUserId()};
UserServiceUtil.addGroupUsers(10301, userIds);


However, I get the exception below. Am I using the right service to do so ? My guess is that my problem has something to do with the community security, but not sure...

Thank you,

Mat



com.liferay.portal.security.auth.PrincipalException
	at com.liferay.portal.service.permission.UserGroupPermissionImpl.check(UserGroupPermissionImpl.java:32)
	at com.liferay.portal.service.permission.UserGroupPermissionUtil.check(UserGroupPermissionUtil.java:30)
	at com.liferay.portal.service.impl.UserServiceImpl.addUserGroupUsers(UserServiceImpl.java:147)
	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 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:65)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
	at $Proxy87.addUserGroupUsers(Unknown Source)
	at com.liferay.portal.service.UserServiceUtil.addUserGroupUsers(UserServiceUtil.java:71)
	...
	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 org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
	at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:357)
	at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.doHandle(AnnotationMethodHandlerAdapter.java:345)
	at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.handleResource(AnnotationMethodHandlerAdapter.java:293)
	at org.springframework.web.portlet.DispatcherPortlet.doResourceService(DispatcherPortlet.java:831)
	at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:525)
	at org.springframework.web.portlet.FrameworkPortlet.serveResource(FrameworkPortlet.java:477)
	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:119)
	at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
	at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:652)
	at com.liferay.portlet.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:747)
	at com.liferay.portlet.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:504)
	at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:847)
	at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:602)
	at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:229)
	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
	at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:152)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
thumbnail
Sandeep Nair, modifié il y a 13 années.

RE: Security exception when adding user to a community

Liferay Legend Publications: 1744 Date d'inscription: 06/11/08 Publications récentes
Use UserLocalServiceUtil instead of UserServiceUtil

UserServiceUtil has additional permissional check, which means users who are allowed to do an action are only allowed.

Regards,
Sandeep
thumbnail
Bla Bla, modifié il y a 13 années.

RE: Security exception when adding user to a community

Junior Member Publications: 79 Date d'inscription: 22/12/10 Publications récentes
Okay - answering to myself.

So I'm not using the right service :got to use UserLocalServiceUtil instead of UserlServiceUtil.

So my code is now like this :

long[] userIds = {user.getUserId()};
UserLocalServiceUtil.addGroupUsers(10301, userIds);



But I'm now getting the following stacktrace. the exception is thrown by this piece of code :



public long getUserId() throws PrincipalException {
		String name = PrincipalThreadLocal.getName();

		if (name == null) {
			throw new PrincipalException();
		}


The "name" variable has a null value.
Any idea ? I'm develpping into the ext plugin in Liferay 6

here is the stacktrace :

com.liferay.portal.security.auth.PrincipalException
	at com.liferay.portal.service.base.PrincipalBean.getUserId(PrincipalBean.java:95)
	at com.liferay.portal.service.base.PrincipalBean.getUser(PrincipalBean.java:88)
	at com.liferay.portal.service.impl.UserServiceImpl.addGroupUsers(UserServiceImpl.java:82)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




Thank you,

Mat
thumbnail
Bla Bla, modifié il y a 13 années.

RE: Security exception when adding user to a community

Junior Member Publications: 79 Date d'inscription: 22/12/10 Publications récentes
Thank you Sandeep, I just see your message.

okay that solved my problem, my last post was out of context since my java class hasn't been really deployed to my container. Yhe UserLocalServiceUtil thing did the trick.

I notice that there are some serious problem with deployment when working in the ext plugin in LR6.