Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Include Page
spaceKeyGrouper
pageTitleNavigation

Using the Grouper API to bootstrap your Groups Registry

    This document is current as of the v2.0 release.

  • Find GrouperSystem Subject
Code Block
Subject grouperSystem = SubjectFinder.findRootSubject();
  • Start-and-stop sessions
Code Block
Subject subject = SubjectFinder.findById("mchyzer", true);
    GrouperSession grouperSession = GrouperSession.start(subject);
    try {
      
      //do some grouper stuff
      
    } finally {
      GrouperSession.stopQuietly(grouperSession);
    }
  • Find the root stem
Code Block
Stem rootStem = StemFinder.findRootStem(grouperSession);
  • Find stem by name (note: the true/false is if an exception should be thrown if not found)
Code Block
Stem stem = StemFinder.findbyName(grouperSession, "some:stem:name", true);
  • Create stem
Code Block
Stem stem = new StemSave(grouperSession).assignName("some:stem:name").assignCreateParentStemsIfNotExist(true).save();
  • Find group by name (note: the true/false is if an exception should be thrown if not found)
Code Block
Group group = GroupFinder.findByName(grouperSession, "some:group:name", true);
  • Create group
Code Block
Group group = new GroupSave(grouperSession).assignName("some:folder:groupName").save();
  • Find GrouperAll subject
Code Block
Subject grouperAll = SubjectFinder.findAllSubject();
  • Check for membership in the wheel group
    Code Block
     boolean isWheelOrRoot = PrivilegeHelper.isWheelOrRoot(subject);
    
  • Add wheel group member
Code Block
String groupName = GrouperConfig.getProperty( GrouperConfig.PROP_WHEEL_GROUP );
Group wheelGroup = GroupFinder.findByName( GrouperSession.staticGrouperSession().internal_getRootSession(), groupName, true );
wheelGroup.addMember(subject, false);