|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.internet2.middleware.grouper.eg.Bootstrap
public class Bootstrap
EXAMPLE Bootstrap your Groups Registry by creating a sysadmin (wheel) group.
Running ant eg.bootstrap
will run this example code.
To begin using the Grouper API you will first need to import the Grouper API, located in the edu.internet2.middleware.grouper package. For many operations, including those in this example, you will also need to import the I2MI Subject API which is located in the edu.internet2.middleware.subject package.
import edu.internet2.middleware.grouper.*; // Import Grouper API import edu.internet2.middleware.subject.*; // Import Subject API
The next step is to find the GrouperSystem subject. This subject is internal to the Grouper API and is the "root" user for your Groups Registry. As normal access and naming privileges do not apply to GrouperSystem you must as as this subject to bootstrap your registry for use by others.
Subject grouperSystem = SubjectFinder.findRootSubject();
Almost all Grouper API operations take place within the context of a
GrouperSession
and each session has an associated subject. The privilegs
of the session's subject determine what API actions can be performed. As this session
will be acting as GrouperSystem there will be no restrictions.
try { GrouperSession s = GrouperSession.start(grouperSystem); } catch (SessionException eS) { // Error starting session }
At the very base of the Groups Registry is the root stem. All other stems and groups in the registry descend from this stem.
Stem root = StemFinder.findRootStem(s);
After retrieving the root stem you can create a new top-level stem, in this case named "etc", beneath the root stem.
Stem etc; String extn = "etc"; String displayExtn = "Grouper Administration"; // check to see if stem already exists try { etc = StemFinder.findByName(s, extn); } catch (StemNotFoundException eNSNF) { // create stem if it doesn't exist try { etc = root.addChildStem(extn, displayExtn); } catch (InsufficientPrivilegeException eIP) { // not privileged to create top-level stem } catch (StemAddException eNSA) { // error adding top-level stem } }However, we are creating a dynamically named stem based on the wheel group named in grouper.properties:
try { this.etc = Stem.saveStem(this.s, etcStem, null, etcStem, displayExtn, null, SaveMode.INSERT_OR_UPDATE, true); System.err.println("created top-level stem: " + this.etc); } catch (Exception eIP) { throw new GrouperRuntimeException( "error adding top-level stem: " + eIP.getMessage() + ", " + etcStem, eIP ); }
After adding the top-level "etc" stem you can then create the wheel group ("etc:sysadmin") beneath it.
Group wheel; String extn = "wheel"; String displayExtn = "Wheel Group"; // check to see if group exists try { wheel = GroupFinder.findByName( s, etc.getName() + ":" + extn ); } catch (GroupNotFoundException eGNF) { try { // create group if it doesn't exist wheel = etc.addChildGroup(extn, displayExtn); } catch (GroupAddException eGA) { // error adding wheel group } catch (InsufficientPrivilegeException eIP) { // not privileged to create wheel group } }However, we are doing things more dynamically:
try { // create group if it doesn't exist this.wheel = Group.saveGroup(this.s, wheelGroupName, null, wheelGroupName, displayExtn, null, SaveMode.INSERT_OR_UPDATE, true); System.err.println("created sysadmin (wheel) group: " + this.wheel); } catch (Exception eGA) { throw new GrouperRuntimeException( "error adding sysadmin group: " + eGA.getMessage() + ", " + wheelGroupName, eGA ); }
GrouperAll is another subject internal to Grouper. When you assign a membership or grant a privilege to GrouperAll it is the equivalent of performing that operation for *all subjects*..
Subject grouperAll = SubjectFinder.findAllSubject();
Now that the wheel group exists you may add members to it. Provided you have
enabled use of a wheel group in conf/grouper.properties
all members added
to this group will now have root-like privileges over the entire Groups Registry.
// verify GrouperAll is not already a member before attempting to add it if ( !wheel.hasMember(grouperAll) ) { try { // this is *not* recommend for most grouper deployments as it will give every // subject root-like privileges over the entire groups registry. wheel.addMember(grouperAll); } catch (InsufficientPrivilegeException eIP) { // not privileged to add GrouperAll as member to wheel group } catch (MemberAddException eMA) { // error adding GrouperAll as member to wheel group } }
The final action after bootstrapping your Groups Registry is to stop the session you started at the beginning of the bootstrapping process.
try { s.stop(); } catch (SessionException eS) { // Error stopping session }
Method Summary | |
---|---|
static void |
main(java.lang.String[] args)
Run example code. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |