Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Include Page
spaceKeyGrouper
pageTitleNavigation

Hooks

Panel
borderColor#ccc
bgColor#FcFEFF
titleColorwhite
titleBGColor#00a400

Image Removed  This topic is discussed in the Advanced Topics training video.

Hooks are points in the Grouper API that will callback custom code if configured to do so.  The custom code has the opportunity to be notified that something happened, change data as it is being operated on, veto operations, kickoff other logic (log something, call another grouper API method, etc).

Hooks are available for the following database persistable objects: Group, Stem, Member, Membership, Composite, Field, GrouperSession, GroupType, GroupTypeTuple

Getting started with hooks
Proof of concept (A veto hook)
Hooks Example - Assign a Unix id to each new group

Children Display

Each of these objects has low-level hooks associated with it: preInsert, postInsert, postCommitInsert, preUpdate, postUpdate, postCommitUpdate, preDelete, postDelete, postCommitDelete. 

...

To configure a hook, subclass one of the hooks base classes, e.g. GroupHooks, MembershipHooks, etc.  Then either register this in the grouper.properties (see grouper.example.properties[broken] for documentation).  Note the class must be threadsafe, as an instance is cached and called repeatedly (i.e. dont store instance vars etc)

...

To find out how the data has changed (in an update or delete), you can use the dbVersion API.  Note, this is probably only available in the "pre" hooks.

To veto a hook, throw a HookVeto which is a runtime exception.  The specific hooks which is vetoing will be assigned to the exception, and will be known wherever it is caught.  This HookVeto takes a system name and a friendly description of a reason why it is being vetoed.  The system name can be used to look up a localized error message.  The friendly version can be used for logging or if a localized message doesnt exist.  You can only veto pre and post synchronous hooks.  You cannot veto asynchronous or postCommit hooks.  You also cannot veto lifecycle hooks (e.g. hibernate init).

...

No Format
2008/07/09 02:18:05.482 GrouperHooksUtils.executeHook(174) - START: Hook GroupTypeTupleHooksImpl.groupTypeTuplePreInsert id: PSPTRJ8J
2008/07/09 02:18:05.497 GrouperHooksUtils.executeHook(181) - END (normal): Hook GroupTypeTupleHooksImpl.groupTypeTuplePreInsert id: PSPTRJ8J (15ms)
2008/07/09 02:18:05.497 GrouperHooksUtils.executeHook(174) - START: Hook GroupTypeTupleHooksImpl.groupTypeTuplePostInsert id: PSPTRJ8K
2008/07/09 02:18:05.497 GrouperHooksUtils.executeHook(186) - END (veto): Hook GroupTypeTupleHooksImpl.groupTypeTuplePostInsert id: PSPTRJ8K (0ms),
   veto key: hook.veto.groupTypeTuple.insert.name.not.test4, veto message: name cannot be test4

Use cases

To do

  • Add more high level hooks
  • Collect and code use cases

See also

Grouper Rules

Access Management Features Overview