Child pages
  • Getting started with hooks
Skip to end of metadata
Go to start of metadata

Hooks Introduction
Proof of concept (A veto hook)
Hooks Example - Assign a Unix id to each new group

Instructions to get started with Grouper and hooks.

  • Install postgres, add a grouper user with a pass.
  • Download the latest grouper 1.4 branch
    • cvs login
    • cvs export -r GROUPER_1_4_BRANCH grouper
    • cvs export -r GROUPER_UI_1_4_BRANCH grouper-ui
  • In grouper dir, run: ant dist
  • Change these settings in conf/
    • hibernate.dialect               = org.hibernate.dialect.PostgreSQLDialect
    • hibernate.connection.driver_class =org.postgresql.Driver
    • hibernate.connection.url = jdbc:postgresql://localhost:5433/grouper
    • hibernate.connection.username         = grouper
    • hibernate.connection.password         = whateverYouSet
  • Copy the grouper_home/lib/jdbcSamples/postgresql.jar to grouper_home/lib/custom
    • cp lib/jdbcSamples/postgresql.jar lib/custom
  • Change this in conf/ so ddl can be done:
  • Add tables: bin/ -registry -runscript
    • You should now be able to browse the DB with pgAdmin or whatever tool you use to admin the db
  • Check tables:  bin/ -registry -check
    • Should output: NOTE: database table/object structure (ddl) is up to date
  • Start gsh and add a subject: bin/
    gsh 0% addSubject("mchyzer", "person", "Chris Hyzer")
    gsh 1% exit
  •  In, I will change/add these settings:
    groups.wheel.use                      = true                    = etc:sysadmingroup = etc:sysadmingroup = super users = mchyzer
  • Start gsh again: bin/      see if the user is in the groups.  Make a stem.  Add a type, and an attribute
    gsh 0% grouperSession = GrouperSession.startRootSession();
    edu.internet2.middleware.grouper.GrouperSession: f802d876-b876-4315-b76e-0586bcc561b1,'GrouperSystem','application'
    gsh 1% subject = findSubject("mchyzer");
    subject: id='mchyzer' type='person' source='jdbc' name='Chris Hyzer'
    gsh 2% member = MemberFinder.findBySubject(grouperSession, subject);
    member: id='mchyzer' type='person' source='jdbc' uuid='1324c75e-9435-4c45-97e9-af40f2b71046'
    gsh 3% member.getGroups();
    group: name='etc:sysadmingroup' displayName='etc:sysadmingroup' uuid='e8cf5974-97ea-4865-9ac9-719fe3a13134'
    gsh 4% addRootStem("aStem", "aStem");
    stem: name='aStem' displayName='aStem' uuid='3e1c5e6e-6dd4-43f0-8b6c-20cb39f01ac8'
    gsh 5% typeAdd("fubGroup");
    type: 'fubGroup'
    gsh 5% typeAddAttr("fubGroup", "gid", AccessPrivilege.READ, AccessPrivilege.ADMIN, false);
    attribute: 'gid'
  • Lets add the hook and try in gsh.  Just add in grouper source tree for simplicity sake
package test;

import edu.internet2.middleware.grouper.Group;
import edu.internet2.middleware.grouper.GroupType;
import edu.internet2.middleware.grouper.GroupTypeFinder;
import edu.internet2.middleware.grouper.hooks.beans.HooksContext;
import edu.internet2.middleware.grouper.hooks.beans.HooksGroupBean;

 * add a type after a group insert
public class GroupAddFubHook extends
    edu.internet2.middleware.grouper.hooks.GroupHooks {

   * @see edu.internet2.middleware.grouper.hooks.GroupHooks#groupPostInsert(edu.internet2.middleware.grouper.hooks.beans.HooksContext, edu.internet2.middleware.grouper.hooks.beans.HooksGroupBean)
  public void groupPostInsert(HooksContext hooksContext,
      HooksGroupBean postInsertBean) {

    super.groupPostInsert(hooksContext, postInsertBean);

    try {
      Group group = postInsertBean.getGroup();
      GroupType fubGroup = GroupTypeFinder.find("fubGroup");
      group.setAttribute("gid", "2");;

    } catch (Exception e) {
      throw new RuntimeException(e.getMessage(), e);


[mchyzer@flash2 grouper]$ ant dist

  • Add this line to the hooks section in conf/
  • See hook work, see new type and new attribute: bin\
gsh 0% group = addGroup("aStem", "aGroup5", "aGroup5");
group: name='aStem:aGroup5' displayName='aStem:aGroup5' uuid='b5552545-2ad2-462c-b5df-67586c987992'
gsh 1% group.getTypes();
type: 'base'
type: 'fubGroup'
gsh 2% group.getAttributes();
java.util.HashMap: {extension=aGroup5, displayExtension=aGroup5, gid=2, name=aStem:aGroup5, displayName=aStem:aGroup5}
gsh 3%


Grouper UI

  • Download or unzip grouper-ui
  • Run ant    -   exit
  • Edit the,
    • set the grouper.folder if not ../grouper
  • Run ant    -    dist
  • Edit your tomcat_home/conf/server.xml, add a context for the UI
    <Engine defaultHost="localhost" name="Catalina">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
        <Context docBase="/home/mchyzer/grouper_v1_4/grouper-ui/dist/grouper" path="/grouper" reloadable="false"/>
  • Add a user to your tomcat-users.xml file:
  <role rolename="grouper_user"/>
  <user username="mchyzer" password="whateveryouwant" roles="grouper_user"/>

  • If you are using mod_jk, hook up the url with the tomcat:
    JkMount /grouper/* tomcat_mchyzer
  • Stop and start apache and tomcat:
    [mchyzer@flash2 grouper]$ /home/mchyzer/apache2_0/bin/apachectl stop
    [mchyzer@flash2 grouper]$ /home/mchyzer/apache2_0/bin/apachectl start
    [mchyzer@flash2 grouper]$ /home/mchyzer/tomcat/bin/
    Using CATALINA_BASE:   /home/mchyzer/tomcat
    Using CATALINA_HOME:   /home/mchyzer/tomcat
    Using CATALINA_TMPDIR: /home/mchyzer/tomcat/temp
    Using JRE_HOME:       /opt/appserv/java6
    [mchyzer@flash2 grouper]$ /home/mchyzer/tomcat/bin/
    Using CATALINA_BASE:   /home/mchyzer/tomcat
    Using CATALINA_HOME:   /home/mchyzer/tomcat
    Using CATALINA_TMPDIR: /home/mchyzer/tomcat/temp
    Using JRE_HOME:       /opt/appserv/java6
    [mchyzer@flash2 grouper]$
  • Add a group with or without the fubGroup type, and see the type and attribute when done
  • No labels