cancel
Showing results for 
Search instead for 
Did you mean: 

How get the UserGroup with Web Script [Solved]

thomasberment
Champ in-the-making
Champ in-the-making
Hi,

I tried to get the user group with a web script but I had an error like : Access Denied.  You do not have the appropriate permissions to perform this operation.

He's seem correct because it's a normal user that calls the web script.

I search a solution to make a session to get my user group, because it works with user admin. An other solution will be to force the getter with admin user.

Please, help me.

Thx.

if(serviceRegistry.getAuthorityService().getAuthoritiesForUser(theUserName) != null){
         Set<String> theSet = serviceRegistry.getAuthorityService().getAuthoritiesForUser(theUserName);
         if ((theSet.size() < 1) || (theSet.size() > 2)){
            this.getLogger().logTechnicalError(EnumTraitementMetierLevel.ERREUR.getCode(), "L'utilisateur est dans plusieurs groupes : " + theSet.size());
            return "";
         }else{
            String[] myElt = new String[Constantes.NB_MAX_GROUP_PER_USER];
            int i = 0;
            String theGroup = "";
            Iterator<String> it = theSet.iterator();
            while (it.hasNext()) {
                myElt[i] = (String) it.next();
                i++;
            }
            for (int j=0;j<myElt.length;j++){
               if (!Constantes.THE_GROUP_EVERYONE.equals(myElt[j])){
                  theGroup = myElt[j].substring(Constantes.INT_COUNT_WORD_GROUP);   
               }
            }
            return theGroup;
         }
      }
2 REPLIES 2

openpj
Elite Collaborator
Elite Collaborator
You can try to use the runas attribute in the WebScript descriptor:
<authentication runas="admin">user</authentication>
In this way Alfresco will check for authentication for that user and then it will execute the WebScript for the current user as the admin user.
Remember that the runas attribute works only for WebScript stored in the classpath, so it doesn't work if you stores your webscripts in the repository (Company Home/Data Dictionary/Web Scripts Extension)

Hope this helps.

thomasberment
Champ in-the-making
Champ in-the-making
Thank you to your help. This attribute works fine !