cancel
Showing results for 
Search instead for 
Did you mean: 

Missing getAllAuthorities() method

sergio
Champ in-the-making
Champ in-the-making
Hi all.

Looking at the Access Control Web Service wiki documentation, there some methods such as getAllAuthorities() to get the complete list of Authorities (and the Authorities for a specific user).

But I was not able to find the method inside the access control service class. Why?

Cheers,

Sergio
8 REPLIES 8

andy
Champ on-the-rise
Champ on-the-rise
Hi

The API does include calls to get all authorities of a given type (users, groups etc). You can also find contained and containing authorities by type for a given authority. See the AuthorityService.

Regards

Andy

sergio
Champ in-the-making
Champ in-the-making
Thanks Andy.

I will let you know asap.

Cheers,

Sergio

sylvain78
Champ in-the-making
Champ in-the-making
Hi,

I don't see how I can get the list of all authorities.  There are no AuthorityService in the Web Services API.  There must be a workaround but I  cannot find it!

How did you do it?

Thanks!

sergio
Champ in-the-making
Champ in-the-making
Hi.

The AuthorityService class is available in org.alfresco.service.cmr.security.AuthorityService

Here you can find an example of how to get all GROUPS defined into the repository.

public static String getGroups(AuthorityService authorityService)
  {
     String groupList = "";
     Set<String> auts = authorityService.getAllAuthorities(AuthorityType.GROUP);
     if (authorityService == null)
     {
        if (logger.isDebugEnabled())
         logger.info("AuthorityService is null");
     }
     else
     {
        Iterator<String> iter = auts.iterator();
       while (iter.hasNext())
       {
          String autName = iter.next();
          groupList += autName + "\n";
          System.out.println(autName);
       }
     }
     
     return (groupList);
  }

Here you can find an example of how to get all USERS defined into the repository.


public static String getUsers(AuthorityService authorityService)
  {
     String groupList = "";
     Set<String> auts = authorityService.getAllAuthorities(AuthorityType.USER);

     Iterator<String> iter = auts.iterator();
     while (iter.hasNext())
     {
        String autName = iter.next();
        groupList += autName + "\n";
        System.out.println(autName);
     }
     
     return (groupList);
  }

Here you can find an example of how to get all USERS belonging to specified GROUP defined into the repository.

public static String getGroupUsers(   AuthorityService authorityService,
                                                         String groupName)
   {
      String userList = "";
      AuthorityType authType = AuthorityType.getAuthorityType(AuthorityType.GROUP.toString());
      AuthorityDAO aut = new AuthorityDAOImpl();
      //aut.deleteAuthority(name)
      
      Set<String> users = authorityService.getContainedAuthorities(   AuthorityType.USER,
                                                                                                   groupName,
                                                                                                   false);
      Iterator<String> userIter = users.iterator();
      while (userIter.hasNext())
      {
         String userName = userIter.next();
         userList += userName + ";";
      }

      return (userList);
   }

Hope this could help.

All the best,

Sergio

sylvain78
Champ in-the-making
Champ in-the-making
Thanks for your reply Sergio.

I did not have time to dig into this, but AuthorityService is not a web service, I don't understand how I can use it from a remote application.

Is there an implementation of this service somewhere or am I missing something?

I am confused about this…

sergio
Champ in-the-making
Champ in-the-making
Hi Sylvain,

if you want to manage all Alfresco repository elements in a complete way, the best and only way is to use the core APIs instead of Alfresco web services. This is exactly what I am doing for my clinical-genomics project called GebbaLab.

I have extended the Alfresco web service creating some new customized ones that use directly Alfresco core APIs. So, these new web services are built around Alfresco core APIs and don't use Alfresco web services. The application (client or web) can interact with the repository calling these custom web services that fully cover all the aspects of the Alfresco repository.

Hoping this could help,

best regards,

Sergio

sylvain78
Champ in-the-making
Champ in-the-making
Thanks, I get it.

This clears it up!

sergiogarcia
Champ in-the-making
Champ in-the-making
We tried to call the method "getGroups", with both AuthorityService
implementations (AuthorityServiceImpl and
SimpleAuthorityServiceImpl), but the result has always been the same.
Should we call the AutorithyService with some kind of repository data?
It will be useful if you can say us another kind of method to list the
groups (groups by user, for example). Any possibility of another group
listing?

we use this code:


public static String getGroups(AuthorityService authorityService){
        String groupList = "";
        //AuthorityType authType = AuthorityType.getAuthorityType(AuthorityType.GROUP.toString());
        Set<String> auts = authorityService.getAllAuthorities(AuthorityType.GROUP);
       
       //System.out.println(auts.toString());
        if (authorityService == null){
            //if (logger.isDebugEnabled())
                //logger.info("AuthorityService is null");
            }else{
                Iterator<String> iter = auts.iterator();
               
                while (iter.hasNext()){
                    String autName = iter.next();
                    groupList += autName + "\n";
                    System.out.println(autName);
                    }
                }
        return (groupList);
    } 

call:
AuthorityService authorityService = new SimpleAuthorityServiceImpl();
User.getGroups(authorityService);



Thanks in advance