cancel
Showing results for 
Search instead for 
Did you mean: 

isAdmin in java files?

jriker1
Champ in-the-making
Champ in-the-making
This is related to my other thread on JS files, however now that with the help of Mike I have overcome that, have possibly one more hurdle to tackle.  I need to check if someone is an admin in Java files.  One of which is specifically InvitationServiceImpl.java.  If I comment out a bit of code like the below:

   private void checkManagerRole(String userId, Invitation.ResourceType resourceType, String siteShortName)
   {
      // if inviter is not the site manager then throw web script exception
      String inviterRole = this.siteService.getMembersRole(siteShortName,
            userId);
/*      if ((inviterRole == null)
            || (inviterRole.equals(SiteModel.SITE_MANAGER) == false)
            || !(authorityService.hasAdminAuthority())  )
      {
         Object objs[] = { userId, siteShortName };
         throw new InvitationExceptionForbidden(
               "invitation.invite.not_site_manager", objs);
      } */
   }


I can execute site manager activities.  I however have not been able to get the above block to work specifically with checking if they are an admin and then allowing them to execute the activity.  I have imported:


import org.alfresco.service.cmr.security.AuthorityService;

and added:


private AuthorityService authorityService;

also added:


    /**
     * @param authorityService  authorityService
     */
    public void setAuthorityService(AuthorityService authorityService)
    {
        this.authorityService = authorityService;
    }

and as you can see from the original code block added:


|| !(authorityService.hasAdminAuthority())

to the original code block.  It errors and I get a NULL in the logs.  All I did above was mostly from looking at other similar code.  Any help in how to check if the current  user is an admin in the checkManagerRole and make the system assume they are a site manager would be appreciated.

Thanks.

JR
2 REPLIES 2

mikeh
Star Contributor
Star Contributor
Did you remember to update the bean definition for InvitationServiceImpl, specifically to add the authorityService (that's what you need the setter function for).

Mike

jriker1
Champ in-the-making
Champ in-the-making
Did you remember to update the bean definition for InvitationServiceImpl, specifically to add the authorityService (that's what you need the setter function for).

Mike

Thanks again Mike.  That was the ticket.  Updated the definition and worked.  Well, after I fixed my flawed if statement posted above, but worked.  One other question for ya.  Where does the CancelInviteAction.java code visually show in Share?  I am not sure if the changes I made in InvitationServiceImpl.java to allow the system admins to manage site invitees needs to be done on that code also as I can't see where it is even referrenced in the GUI.

Thanks again.

JR