Determining if a Party is a Member of a Group
Grid Grouper: Administrators Guide | Developers Guide | caGrid: Documentation Guides
This guide will provide an example on how to use the GridGrouper client API to determine whether or not a user is a member of a Grid Grouper group. The code example below provides a method isMember() that determines whether or not a user is a member of a group. The isMember() method requires teh following inputs:- grouperURL - The URL of the Grid Grouper containing the Group.
- groupName - The full system name for the group (i.e Training:Trainees).
- userIdentity - The user's grid identity.
The method returns a boolean set to true if the user is a member or false if the users is not a member.
import edu.internet2.middleware.grouper.GroupNotFoundException; import edu.internet2.middleware.grouper.GrouperRuntimeException; import gov.nih.nci.cagrid.gridgrouper.client.GridGrouper; import gov.nih.nci.cagrid.gridgrouper.grouper.GrouperI; public class IsMemberExample { public static boolean isMember(String grouperURL, String groupName, String userIdentity) throws GrouperRuntimeException { // Create a Grid Grouper Instance GrouperI grouper = new GridGrouper(grouperURL); try { // Determine if the user is a member of the group. boolean isMember = grouper.isMemberOf(userIdentity, groupName); if (isMember) { System.out.println("The user " + userIdentity + " is a member of " + groupName); return true; } else { System.out.println("The user " + userIdentity + " is NOT a member of " + groupName); return false; } } catch (GroupNotFoundException e) { System.out.println("The group " + groupName + " does not exist, therefore the user " + userIdentity + " is NOT a member."); return false; } } }





