cancel
Showing results for 
Search instead for 
Did you mean: 

[Web Service] Way to retrieve Alfresco Groups ?

aragorn185
Champ in-the-making
Champ in-the-making
How do you retrieve all groups where a specific user belongs using Alfresco Web Services ?
7 REPLIES 7

openpj
Elite Collaborator
Elite Collaborator
In the following snippet you can get all the authorities for a user:

WebServiceFactory.getAuthorityService().getAuthoritiesForUser(userName);
Then you can filter all the values that start with the GROUP_ prefix to identify all the groups.

Hope this helps.

aragorn185
Champ in-the-making
Champ in-the-making
Thanks OpenPj for your response but i do not have a reference to AuthorityService.
The list of available webservices is:
  • AuthenticationService

  • RepositoryService

  • ContentService

  • AuthoringService

  • ClassificationService

  • ActionService

  • AccessControlService

  • AdministrationService

  • DictionaryService
So i wonder how to retrieve a reference to AuthorityService ?

openpj
Elite Collaborator
Elite Collaborator
I'm sorry, you're right!  :roll:

For solving this feature you can implement your own custom WebScript (Custom Action) to search all user groups, then you can call it from your web service and you can return values from WebScript to your Web Service.

WebScript code:

serviceRegistry.getAuthorityService().getAuthoritiesForUser(userName);
Web Service code:

Action userGroupsAction = new Action();
userGroupsAction.setActionName("userGroupsAction");
userGroupsAction.setParameters(properties);
ActionExecutionResult[] results = WebServiceFactory.getActionService().executeActions(predicate, new Action[]{userGroupsAction});
                 
You can see this pages from the wiki for more details:

http://wiki.alfresco.com/wiki/Custom_Actions

http://wiki.alfresco.com/wiki/Returning_Values_From_Actions

Hope this helps.

sebguillomon
Champ in-the-making
Champ in-the-making
Hello,

I have implemented this custom action and in the class, Ihave this code :


@Override
   protected void executeImpl(Action action, NodeRef nodeRef) {
      userName = action.getParameterValue(Constants.PARAM_USER_NAME).toString();
      System.out.println("Search groups of user : " + userName);
      
      Set<String> groups = serviceRegistry.getAuthorityService().getAuthoritiesForUser(userName);
      
      String strgroups = "";
      int i = 0;
      for ( String str : groups ){
         if ( i>0 )
            strgroups += ",";
         
         strgroups += str;
         i++;
      }
      
      action.setParameterValue(Constants.PARAM_USER_GROUPS, strgroups);
      System.out.println("Groups of user : " + strgroups);
   }

And when i call this action using webservice:


ActionServiceSoapBindingStub actionService = WebServiceFactory.getActionService();
Action action = new Action();
NamedValue nv = new NamedValue();
nv.setName(Constants.PARAM_USER_NAME);
nv.setValue("neil");
action.setActionName("userGroupsAction");
action.setParameters(new NamedValue[]{nv});
ActionExecutionResult[] results = actionService.executeActions(prd, new Action[]{action});

there is no Constants.PARAM_USER_GROUPS parameter in the results !
The action execute correctly.

Any Idea ?

openpj
Elite Collaborator
Elite Collaborator
Are you sure that you are calling exactly the same parameter?
I suggest you to recheck your code, look at what you have setted as parameter in the action and what you are calling from web service  :wink:

Hope this helps.

janv
Employee
Employee
FYI, although web scripts are the way to go, with Alfresco 3.x you also have the option to use the updated AccessControlService:

http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/remote-api/source/wsd...
http://wiki.alfresco.com/wiki/Access_Control_Web_Service_Future_Enhancements

Regards,
Jan

jeffwji
Champ in-the-making
Champ in-the-making
It doesn't work! I tried to use "PROP_USERNAME" instead of "PARAM_USER_NAME" to search "GROUP_EVERYONE", which must exists, like this:


NamedValue nv = new NamedValue();
nv.setName(Constants.PROP_USERNAME);
nv.setValue("GROUP_EVERYONE");

Action userGroupsAction = new Action();
userGroupsAction.setActionName("userGroupsAction");
userGroupsAction.setParameters(new NamedValue[]{nv});

ActionExecutionResult[] results = WebServiceFactory.getActionService().executeActions(predicate, new Action[]{userGroupsAction});

I still got AxisFault exception. The exception message is: "No bean named 'userGroupsAction' is defined"