cancel
Showing results for 
Search instead for 
Did you mean: 

Problems on Group Permission ?

alvisccc
Champ in-the-making
Champ in-the-making
Hello,

       I have created a group using web service call.
We can only apply group to a node (Space) with different user role such as administrator,editor,consumer etc.
But are there any web service call or method to make a group together with different Role or permissions ,for example a group can read all space contents.but need not to add group to node or space.

I  found that Alfresco has a created "ALFRESCO_ADMINISTRATORS" group ,when i add a user to that group .
That user get adminstrator right .How can i do ,like that  a goup have permission, please help me!
3 REPLIES 3

mdavid_cu
Champ in-the-making
Champ in-the-making
If you want to add a user to the ALFRESC0_ADMINISTRATORS group you may try something like that:

/**
* This method creates a group authority in the authority parent of Alfresco.
* @param name: The new user's name
* @param parent a Valid Group's name you have to concat a group prefix: "GROUP_"
*/
public void addUser(String name, String parent) {
      AccessControlServiceSoapBindingStub accessControlService = WebServiceFactory.getAccessControlService();      
      try {         
         String[] result = accessControlService.addChildAuthorities(parent, new String[]{name});      
         for (String string : result) {
            System.out.println("User added: "+ string);
         }
         
      } catch (RemoteException e) {      
         e.printStackTrace();
      }
   }

I hope this helps.

alvisccc
Champ in-the-making
Champ in-the-making
Thanks mdavid.cu !

But i want to create a group which can read all contents node only,but no administrator right.Still don't know how to grant permission to group.And i search throught internet,it seems no such WS api doing that.

mdavid_cu
Champ in-the-making
Champ in-the-making
Thanks mdavid.cu !

But i want to create a group which can read all contents node only,but no administrator right.Still don't know how to grant permission to group.And i search throught internet,it seems no such WS api doing that.

I think that you should try to apply a permission to a group in a root space, this will cause that all nodes can have the same hierarchical permission, that is a way for doing your requirement. I don't know very well if Alfresco internally manages the treatment for some permission like "ALFRESCO_ADMINISTRATORS", but I don't think so.

A way for doing that you want can be something like that:



     package org.my.self.test;

import java.rmi.RemoteException;

import org.alfresco.webservice.accesscontrol.ACE;
import org.alfresco.webservice.accesscontrol.ACL;
import org.alfresco.webservice.accesscontrol.AccessControlFault;
import org.alfresco.webservice.accesscontrol.AccessControlServiceSoapBindingStub;
import org.alfresco.webservice.accesscontrol.AccessStatus;
import org.alfresco.webservice.accesscontrol.NewAuthority;
import org.alfresco.webservice.authentication.AuthenticationFault;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.WebServiceFactory;

public class RoleAssigment {

   /**
    * This method creates a group authority in the authority root of Alfresco.
    *
    * @param name
    *            :The group's name
    */
   public void createGroup(String name) {

      AccessControlServiceSoapBindingStub accessControlService = WebServiceFactory
            .getAccessControlService();

      NewAuthority authority = new NewAuthority("GROUP", name);

      try {
         String[] result = accessControlService.createAuthorities(null,
               new NewAuthority[] { authority });
         for (String string : result) {
            System.out.println("Created group: " + string);
         }

      } catch (RemoteException e) {
         e.printStackTrace();
      }
   }

   public void createAssigment(String grupName, String permission,
         String pathTo) {

      Predicate predicate = new Predicate(new Reference[] { new Reference(
            new Store("workspace", "SpacesStore"), null, pathTo) }, null,
            null);

      AccessControlServiceSoapBindingStub accessControlService = WebServiceFactory
            .getAccessControlService();

      try {

         accessControlService.addACEs(predicate, new ACE[] { new ACE(
               grupName, permission, AccessStatus.acepted) });

      } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

   }
   
   public static void main(String[] args) {
      try {
         
         final String repositoryPath = "http://10.7.16.199:8080/alfresco/api";
         final String userName = "mdavid";
         final String passwd = "xxxxxxxxx";
         
         RoleAssigment roleAssigment = new RoleAssigment();
         
         WebServiceFactory.setEndpointAddress(repositoryPath);
         
         AuthenticationUtils.startSession(userName, passwd);
         
         roleAssigment.createGroup("NODE_READER_ONLY");
         roleAssigment.createAssigment("GROUP_NODE_READER_ONLY", "Read", "/app:company_home");
         
         System.out.println("Task Completed !!!");
         
      } catch (AuthenticationFault e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }finally{
         AuthenticationUtils.endSession();
      }
   }
}

If you have doubts about it please contact me at mdavid@uci.cu