Versions Compared

Key

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

...

If groups are created within a certain stem some privileges are to be set automatically. This is done with the groupPostCommitInsert() method in the MyGroupHook.

 

Code Block
languagejava
public void groupPostCommitInsert(HooksContext hooksContext, HooksGroupBean postCommitInsertBean) {
     
    Group beanGroup = postCommitInsertBean.getGroup();																							// get group informations

    /* Read-Privilege for staff for all target groups */

    if ( beanGroup.getName().startsWith("targets:")) {																							// all target groups
        String employersGroupId = GroupFinder.findByName (GrouperSession.startRootSession(), "stem:group_of_employees", false).getId();			// id of staff group
        beanGroup.grantPriv ( SubjectFinder.findById ( employersGroupId, false)  , AccessPrivilege.READ );										// granting read privilege
     }

     /* Admin Privileges for xGroup for all myNet groups (i.e. groups that contain the string "myNet" in their full name */

     if ( beanGroup.getName().contains( "myNet" )) { 																							// all groups that contain "myNet"
         String xGroupId = GroupFinder.findByName (GrouperSession.startRootSession(), "stem:xGroup", false).getId();							// id of xGroup
         beanGroup.grantPriv ( SubjectFinder.findById ( xGroupId, true), AccessPrivilege.ADMIN );												// granting admin privilege
     }
 }

...