Access Keys:
Skip to content (Access Key - 0)

Knowledgebase


Part Eight: Get Grouper Groups for User


Table of Contents

Desired Application Functionality


This guide assumes the user has done part four (Authentication) in the last 12 hours. If not redo step "Synchronize with the Grid Trust Fabric" and "Logon to the Grid" from part three.

Viewing Membership in Grouper Groups


  1. Open GAARDS if you haven't already done so
    ant security
  2. Click the My Groups button on the menu bar.
  3. A window will appear listing all the grouper groups the user is a member of.

Creating Client Functionality


Now, we will begin to implement the functionality that we just invoked using Ant tasks and the GAARDS UI.

The following JARs are used in a Grid application that synchronizes with the trust fabric:

Jar dependency Purpose
caGrid-gridgrouper-client-1.4.jar
caGrid-gridgrouper-common-1.4.jar
caGrid-gridgrouper-stubs-1.4.jar
Provides the caGrid Grouper functionality
grouper-1.1.jar
subject-0.2.1.jar
Provides the underlying Internet2 group functionality.
Update Ivy Dependencies

  1. Update ivy.xml with dependencies by adding the following entries within the '<dependencies>' section. Note that some of these are base caGrid and Globus dependencies that have been placed here because your application will have to synchronize with the trust fabric.
    <!-- Grid Grouper Dependencies -->
    <dependency rev="${repository.version}" org="caGrid" name="gridgrouper" conf="default->client,common,stubs"/>
    <dependency rev="1.1" org="internet2" name="grouper" conf="default->default"/>
    <dependency rev="0.2.1" org="internet2" name="subject" conf="default->default"/>
    
  2. Save the ivy.xml file.
  3. From the command line run ant all to retrieve the new jars. You will see the required jars being downloaded from http://software.cagrid.org.

Import Jars into the Project

  1. Right-click on the caGridClient project in the Eclipse Package Explorer.
  2. Select the Properties entry at the bottom of the list.
  3. Select Java Build Path, then Libraries.
  4. Select the lib entry and click the Edit button.
  5. Click User Libraries
  6. Click Add Jars
  7. Navigate to the newly added jars in caGridClient/lib and add them to the lib user library.
  8. In the Preferences dialog, click OK.
  9. In the Add Library dialog, click Finish.

Create the GridGrouperActions Class

  1. In the Eclipse Package Explorer right-click the src/org.cagrid.client package and select New->Class
  2. Set the class name as GridGrouperActions and click 'Finish'.
  3. Add imports
    import edu.internet2.middleware.grouper.GroupNotFoundException;
    import edu.internet2.middleware.grouper.GrouperRuntimeException;
    import edu.internet2.middleware.grouper.InsufficientPrivilegeException;
    import edu.internet2.middleware.grouper.StemNotFoundException;
    import gov.nih.nci.cagrid.gridgrouper.client.GridGrouper;
    import gov.nih.nci.cagrid.gridgrouper.client.GridGrouperClient;
    import gov.nih.nci.cagrid.gridgrouper.grouper.GroupI;
    import gov.nih.nci.cagrid.gridgrouper.grouper.GrouperI;
    import gov.nih.nci.cagrid.gridgrouper.grouper.StemI;
    
    import java.net.MalformedURLException;
    import java.rmi.RemoteException;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.Vector;
    
    import org.apache.axis.types.URI.MalformedURIException;
    import org.globus.gsi.GlobusCredential;
    
  4. Add the following methods.
    private String serviceUrl = null;
    private GridGrouper grouper = null;
    
    public GridGrouperActions (String grouperURL, GlobusCredential cred)  throws MalformedURLException, MalformedURIException, RemoteException
    {
    	this.serviceUrl = grouperURL;
    	this.grouper = new GridGrouper(this.serviceUrl, cred);
    }
    
    public Set<GroupI> getGroupsForUser (String identity)
    {
    	Set<GroupI> membersGroups = null;
    	try{membersGroups = grouper.getMembersGroups(identity);}
    	catch (GrouperRuntimeException e){e.printStackTrace();}
    	catch (InsufficientPrivilegeException e) {e.printStackTrace();}
    	return membersGroups;
    }
    
  5. Save the file.

Update the GridClient Class

  1. Open GridClient.java and add the imports
    import java.util.Iterator;
    import java.util.Set;
    import gov.nih.nci.cagrid.gridgrouper.grouper.GroupI;
    
  2. Add the private variable
    private static final String DEFAULT_GROUPER_SERVICE_URL_PROP = "default.grouper.service.url";
    
  3. Add a method to call the getGroupsForUser
    private void getGroupsForUser()
    {
            String grouperServiceUrl = props.getProperty(DEFAULT_GROUPER_SERVICE_URL_PROP);
    
            System.out.println("--------------------------");
            System.out.println("1 : Current User");
            System.out.println("2 : Another User");
            String message = "Select group lookup option: ";
            int userInput = UserInteraction.getIntegerFromUser (message, 1, 2);
    
            String identity;
            if (userInput == 1)
            {
                identity = this.cred.getIdentity();
            }
            else
            {
                identity = UserInteraction.getStringFromUser("Provide User's Grid Identity");
            }
    
            try
            {
                GridGrouperActions grouperActions = new GridGrouperActions(grouperServiceUrl, this.cred);
                Set<GroupI> groups = grouperActions.getGroupsForUser(identity);
                Iterator<GroupI> iter = groups.iterator();
                while (iter.hasNext()) {
                    GroupI group = (GroupI) iter.next();
                    System.out.println(identity + " memberOf " + group.getName());
                }
    
            }
            catch (MalformedURLException e) {e.printStackTrace();}
            catch (MalformedURIException e) {e.printStackTrace();}
            catch (RemoteException e) {e.printStackTrace();}
    }
    
  4. Within the for loop of the main method, add the call to the getGroupsForUser method where we are evaluating the user input of the value 8.
    client.getGroupsForUser();
  5. Build the project
    > cd GRID_CLIENT_HOME
    > ant all
    
  6. Verify that the build completed successfully.
  7. Fix any compile errors that are reported.

Test the Client


The Ant build file includes a target for running the client. It will create a classpath from the jars included by Ivy.

  1. Open a command prompt.
  2. Change directory to your caGridClient location
  3. Type ant run. This will build and execute the project
  4. When prompted, type 8 to view the users grouper groups.
  5. You should see the following:
    [java] 1 : Current User
    [java] 2 : Another User
    [java] Select group lookup option:  [1..2] :
    
  6. To view the current logged in user's groups type 1, the terminal will then display them.
    [java] Select group lookup option:  [1..2] : 1       
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:Trainees       
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:photosharingtutorial:Gateway:summervacation:view 
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:photosharingtutorial:Gateway:summervacation:add       
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:photosharingtutorial:Gateway:work:view      
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:photosharingtutorial:Gateway:work:add
    
  7. To view another user's groups type 2.
  8. The terminal will ask for that user's grid identity - this is not the user's username but the grid identity in the form of /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=<userid>, the terminal will now show the groups.
    [java] Select group lookup option:  [1..2] :2 
    [java] Provide User's Grid Identity: /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b  
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:Trainees
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:photosharingtutorial:Gateway:summervacation:view
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:photosharingtutorial:Gateway:summervacation:add
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:photosharingtutorial:Gateway:work:view
    [java] /O=caBIG/OU=caGrid/OU=Training/OU=Dorian/CN=b memberOf Training:photosharingtutorial:Gateway:work:add
    
Last edited by
Saba Bokhari (759 days ago)
Adaptavist Theme Builder Powered by Atlassian Confluence