AnsweredAssumed Answered

Assign a user to a group using actions

Question asked by grosisimo on Dec 13, 2007
Hi

I'm getting crazy because I can't find what's happening and I need to make it work now!!.

I am working with Alfresco and Liferay, and I need to keep synchronized both so that a user created in Liferay was created in Alfresco.
I used Web Services to create the user, but I couldn't find anything to assign that user to a group, so I was trying to do that using Actions that i called from Liferay using web services too.

The source code i used is this

package org.alfresco.repo.action.executer;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.repo.security.authority.SimpleAuthorityServiceImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;

import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.namespace.QName;



public class AssignUserToGroupActionExecuter extends ActionExecuterAbstractBase
{
   public static final String NAME = "assign-user-to-group";
   public static final String PARAM_USER_NAME = "user-name";
   public static final String PARAM_GROUP_NAME = "group-name";

   private NodeService nodeService;
   public void setNodeService(NodeService nodeService)
   {
      this.nodeService = nodeService;
   }

   public void executeImpl(Action action, NodeRef actionedUponNodeRef)
   {
      QName param_user_name = (QName)action.getParameterValue(PARAM_USER_NAME);
      QName param_group_name = (QName)action.getParameterValue(PARAM_GROUP_NAME);
      
      String user_name = param_user_name.toString().substring(2);      //to remove the characters "{}" that appears at the beginning
      String group_name = param_group_name.toString().substring(2);   //to remove the characters "{}" that appears at the beginning

      System.out.println("the user " + user_name + " will be assigned to the group " + group_name);

      AuthorityService authorityService = new SimpleAuthorityServiceImpl();
      
      System.out.println("antes de crear el authentication service");
      
      try {
         System.out.println("*************************************");
         System.out.println("users:");
         Set<String> users = authorityService.getAllAuthorities(AuthorityType.USER);
         
         if (users == null)
            System.out.println("It doesn't work because its null");
         else
         {
            for (Iterator<String> i = users.iterator(); i.hasNext(); )
            {
               String user = i.next();
               System.out.println("user: " + user);
            }
            System.out.println();
         }
         
      } catch (SecurityException e) {
         e.printStackTrace();
      } catch (IllegalStateException e) {
         e.printStackTrace();
      } catch (AuthenticationException e) {
         e.printStackTrace();
      }
      
      
      System.out.println("despues de agregar la Authority");
   }

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList)
   {
      paramList.add(new ParameterDefinitionImpl(PARAM_GROUP_NAME,DataTypeDefinition.QNAME,true,getParamDisplayLabel(PARAM_GROUP_NAME)));
      paramList.add(new ParameterDefinitionImpl(PARAM_USER_NAME,DataTypeDefinition.QNAME,true,getParamDisplayLabel(PARAM_USER_NAME)));
   }
}

The action gets 2 parameters and try to list all users. This is not what the action will do, but its the simplest code where the exception is thrown.

The problem is that when I call the action I get the following error:


users:
10:59:58,921 ERROR [encoding.ser.BeanSerializer] Exception:
java.io.IOException: Non nillable element 'message1' is null.
        at org.apache.axis.encoding.ser.BeanSerializer.serialize(BeanSerializer.
java:215)
        at org.apache.axis.encoding.SerializationContext.serializeActual(Seriali
zationContext.java:1504)
        at org.apache.axis.encoding.SerializationContext.serialize(Serialization
Context.java:980)
        at org.apache.axis.encoding.SerializationContext.serialize(Serialization
Context.java:680)
        at org.alfresco.repo.webservice.action.ActionFault.writeDetails(ActionFa
ult.java:156)
        at org.apache.axis.message.SOAPFault.outputImpl(SOAPFault.java:165)
        at org.apache.axis.message.MessageElement.output(MessageElement.java:120
8)
        at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:139)
        at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478
)
        at org.apache.axis.message.MessageElement.output(MessageElement.java:120
8)
        at org.apache.axis.AxisFault.output(AxisFault.java:759)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:301)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
        at org.apache.axis.SOAPPart.saveChanges(SOAPPart.java:530)
        at org.apache.axis.attachments.AttachmentsImpl.getAttachmentCount(Attach
mentsImpl.java:554)
        at org.apache.axis.Message.getContentType(Message.java:486)
        at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:77
5)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
e.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:210)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:174)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:151)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:870)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:685)
        at java.lang.Thread.run(Thread.java:619)
10:59:59,093 ERROR [apache.axis.SOAPPart] Exception:
java.io.IOException: java.io.IOException: Non nillable element 'message1' is nul
l.
        at org.apache.axis.encoding.ser.BeanSerializer.serialize(BeanSerializer.
java:275)
        at org.apache.axis.encoding.SerializationContext.serializeActual(Seriali
zationContext.java:1504)
        at org.apache.axis.encoding.SerializationContext.serialize(Serialization
Context.java:980)
        at org.apache.axis.encoding.SerializationContext.serialize(Serialization
Context.java:680)
        at org.alfresco.repo.webservice.action.ActionFault.writeDetails(ActionFa
ult.java:156)
        at org.apache.axis.message.SOAPFault.outputImpl(SOAPFault.java:165)
        at org.apache.axis.message.MessageElement.output(MessageElement.java:120
8)
        at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:139)
        at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478
)
        at org.apache.axis.message.MessageElement.output(MessageElement.java:120
8)
        at org.apache.axis.AxisFault.output(AxisFault.java:759)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:301)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
        at org.apache.axis.SOAPPart.saveChanges(SOAPPart.java:530)
        at org.apache.axis.attachments.AttachmentsImpl.getAttachmentCount(Attach
mentsImpl.java:554)
        at org.apache.axis.Message.getContentType(Message.java:486)
        at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:77
5)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
e.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:210)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:174)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:151)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:870)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:685)
        at java.lang.Thread.run(Thread.java:619)
10:59:59,265 WARN  [axis.attachments.AttachmentsImpl] Exception:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString:
faultActor:
faultNode:
faultDetail:
        {http://xml.apache.org/axis/}exceptionName:org.alfresco.repo.webservice.
action.ActionFault
        {http://xml.apache.org/axis/}stackTrace:
        at org.alfresco.repo.webservice.action.ActionWebService.executeActions(A
ctionWebService.java:848)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.j
ava:397)
        at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider
.java:186)
        at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:
323)
        at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
y.java:32)
        at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
        at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
        at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454
)
        at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
        at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:69
9)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
e.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:210)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:174)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:151)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:870)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:685)
        at java.lang.Thread.run(Thread.java:619)

        {http://xml.apache.org/axis/}hostname:eoc-eai


        at org.alfresco.repo.webservice.action.ActionWebService.executeActions(A
ctionWebService.java:848)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.j
ava:397)
        at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider
.java:186)
        at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:
323)
        at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
y.java:32)
        at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
        at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
        at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454
)
        at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
        at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:69
9)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
e.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:210)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:174)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:151)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:870)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:685)
        at java.lang.Thread.run(Thread.java:619)

This error happens every time I try to use one of the Apis functionalities, for example, when i try to list users, or add a user to a group, or anything else.
I have already tried to authenticate using AuthenticationServiceImpl, but when i call the method authenticate happens the same.

The only exception I found is when I try to list groups instead of users, i don't get that exception. I get only one group called EVERYONE. That's strange because I have other groups.

Just in case you ask, if I only make a System.out.println showing the parameters, it works right. That means, the action was executed and the parameters arrived well.

Thanks

PD: By the way, to assign the user, the source i have to add is this, isn't it?
authorityService.addAuthority(group_name, user_name);

Outcomes