Include Page | ||||
---|---|---|---|---|
|
Panel | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
This topic is discussed in the "Grouper API - Part 2" training video. |
...
gsh is now a core part of the Grouper API and so is always compatible with the current release.
Installation
When using the Grouper API source distribution, grouper.jar needs to be built before using gsh.sh for the first time:
No Format |
---|
cd $GROUPER_HOME ant dist |
...
For Windows use $GROUPER_HOME\bin\gsh.bat
Run gsh as an interactive shell:
...
Command | Description |
---|---|
addGroup(parent stem name, extension, displayExtension) | Add group to registry |
delGroup(name) | Delete group from registry |
getGroupAttr(group name, attr) | Get value of group attribute |
getGroups(name) | Find all groups with a matching naming attribute value, returns a Set of groups |
setGroupAttr(group name, attr, value) | Set value of group attribute |
GroupFinder.findByName(grouperSession, name) | Find one group by name |
GroupFinder.findByUuid(grouperSession, name) | Find one group by uuid |
You can use GroupSave as an alternate way:
Code Block |
---|
new GroupSave(grouperSession).assignName("stem1:a").assignCreateParentStemsIfNotExist(true).save();
|
...
grouperSession = GrouperSession.startRootSession();
oldSubject = findSubject("10021368");
member = MemberFinder.findBySubject(grouperSession, oldSubject);
newSubject = findSubject("10021366");
member.changeSubject(newSubject);
Command | Description |
---|---|
member.changeSubject(newSubject); | Change the subject of the member object. If the subject is the same, its a no-op. If the new subject does not have a Member object, then the existing member object simply gets new subject information. If the new subject does have a member object, then all objects in the grouper registry which uses the old member, will be updated to the new member. Then the old member object is deleted from the registry |
member.changeSubject(newSubject,!Member.DELETE_OLD_MEMBER); | Change the subject, but dont delete the old member. Do this if the way which deletes the old member doesnt work due to foreign keys. This will do all the work it can, and the rest can be manual |
member.changeSubjectReport(newSubject,Member.DELETE_OLD_MEMBER); | Dont do any of the work, just print a report to the screen of what will be done. Dry-run. |
Memberships
Command | Description |
---|---|
addComposite(group name, composite type, left group name, right group name) | Add composite membership. e.g. CompositeType.UNION |
addMember(group name, subject id) | Add member to the members list for the group. |
addMember(group name, subject id, field) | Add member to the specified list for the group. |
delComposite(group name) | Delete composite membership from group |
delMember(group name, subject id) | Delete member from the members list for the group |
delMember(group name, subject id, field) | Delete member from the specified list for the group |
getMembers(group name) | Get members of group |
hasMember(group name, subject id) | Check whether subject is member of the members list |
hasMember(group name, subject id, field) | Check whether subject is member of the specified list |
...
Command | Description |
---|---|
registryInitializeSchema() | Will generate schema DDL for the DB, and wont drop before creating, will not run script |
registryInitializeSchema(registryInitializeSchema.DROP_THEN_CREATE) | generate DDL for the DB, dropping existing tables, will not run script |
registryInitializeSchema.WRITE_AND_RUN_SCRIPT) | generate DDL for the DB, not dropping, but will run the script after writing it to file |
registryInitializeSchema(registryInitializeSchema.DROP_THEN_CREATE | registryInitializeSchema.WRITE_AND_RUN_SCRIPT) | generate DDL for the DB, drop existing grouper tables, and run the script after writing it to file |
resetRegistry() | Restore registry to default state(delete data from all tables, install defaults) |
registryInstall() | If the default Grouper data is not there, it will be added (e.g. root stem, default fields, etc) |
Stems
Command | Description | |
---|---|---|
addRootStem(extension, displayExtension) | Add top-level stem to the registry | |
addStem(parent stem name, extension, displayExtension) | Add stem to registry | |
delStem(stem name) | Delete stem from registry | |
obliterateStem(stem name, testOnlyBoolean, deleteFromPointInTimeBoolean) (Grouper v2.0.2+) | Delete stem, and subobjects. | |
getStemAttr(stem name, attr) | Get value of stem attribute | |
getStems(name) | Find all stems with a matching naming attribute value, returns a Set of stems | |
setStemAttr(stem name, attr, value) | Set value of stem attribute | |
StemFinder.findByName(grouperSession, name) | Find one stem by name | |
StemFinder.findByUuid(grouperSession, uuid) | Find one stem by uuid | |
| ||
Delete stem and subcontents |
Subjects
Command | Description |
---|---|
addSubject(id, type, name) | Add local subject to registry |
findSubject(id) | Find a subject |
findSubject(id, type) | Find a subject |
findSubject(id, type, source) | Find a subject |
getSources() | Find all Subject sources |
grouperSession = GrouperSession.startRootSession(); | Find all subjects in a source by search string |
grouperSession = GrouperSession.startRootSession(); | Find a subject by id in a certain source |
grouperSession = GrouperSession.startRootSession(); | Find a subject by identifier in a certain source |
grouperSession = GrouperSession.startRootSession(); | Find a subject by id or identifier in a certain source |
...
For more information, see Unresolvable Subject Deletion Utility (USDU)
Command | Description |
---|---|
GrouperSession.startRootSession(); | Sample call to find all unresolvable subjects in the registry and print details to the screen |
usdu(usdu.DELETE) | Pass in that you want to delete memberships in the usdu call |
usduBySource("schoolperson") | Work only in a specific subject source, pass in the sourceId from sources.xml |
usduBySource("schoolperson", usdu.DELETE) | Work in a specific source and delete membeships |
subject=SubjectFinder.findById("GrouperSystem") | Work only with a specific member |
usduByMember(member, usdu.DELETE) | usdu by member, and delete memberships |
...
For more information, see Bad Membership Finder Utility
Command | Description |
---|---|
findBadMemberships() | complete findBadMemberships run |
XML legacy
Command | Description |
---|---|
xmlFromFile(filename) | Load registry from XML in file |
xmlFromString(xml) | Load registry from XML in string |
xmlFromURL(url) | Load registry from XML at URL |
xmlToFile(filename) | Exports registry to file |
xmlToString() | Exports registry to string. |
xmlUpdateFromFile(filename) | Update registry from XML in file |
xmlUpdateFromString(xml) | Update registry from XML in string |
xmlUpdateFromURL(url) | Update registry from XML at URL |
...
For more information, see Import-Export
Command | Description |
---|---|
XmlExport xmlExport.stem(stem) | The stem to export. Defaults to the ROOT stem. |
XmlExport xmlExport.group(group) | The group to export |
XmlExport xmlExport.relative(boolean) | If group or stem specified do not export parent Stems. |
XmlExport xmlExport.includeParent(boolean) | If group specified, export from the parent stem |
XmlExport xmlExport.childrenOnly(boolean) | If stem specified, export child stems and groups only - not the specified stem |
XmlExport xmlExport.userProperties(file) | Properties file for extra settings for import |
XmlExport xmlExport.grouperSession(grouperSession) | Operate within a certain grouper session (defaults to root session) |
void xmlExport.exportToFile(file) | Export to an XML file |
void xmlExport.exportToString(string) | Export to an XML string |
Examples:
No Format |
---|
gsh 1% new XmlExport().exportToFile(new File("c:/temp/export.xml")) |
...
For more information, see Import-Export
Command | Description |
---|---|
XmlImport xmlImport.stem(stem) | The Stem into which data will be imported. Defaults to the ROOT stem. |
XmlImport xmlImport.updateList(boolean) | XML contains a flat list of Stems or Groups which may be updated. |
XmlImport xmlImport.userProperties(file) | Properties file for extra settings for import |
XmlImport xmlImport.grouperSession(grouperSession) | Operate within a certain grouper session (defaults to root session) |
XmlImport xmlImport.ignoreInternal(boolean) | Ignore internal attributes, including group and stem uuids. |
void xmlImport.importFromFile(file) | Import from an XML file |
void xmlImport.importFromString(string) | Import from an XML string |
void xmlImport.importFromUrl(url) | Import XML from a URL |
Examples:
No Format |
---|
gsh 1% new XmlImport().importFromFile(new File("c:/temp/export.xml")) |
...
Transactions facilitate all commands succeeding or failing together, and perhaps some level of repeatable reads of the DB (depending on the DB). If there is an open transaction and an exception is thrown in a command, GSH will shut down so that subsequent commands will not execute outside of a transaction.
Command | Description |
---|---|
help("transaction") | print help information |
transactionStatus() | print the list of nested transactions |
transactionStart("<GrouperTransactionType>") | start a transaction, or make sure one is already started |
transactionCommit("<GrouperCommitType>") | commit a transaction |
transactionRollback("<GrouperRollbackType>") | rollback a transaction |
transactionEnd() | end a transaction |
...
Above, it describes how you can kick off the loader in daemon mode. You can also execute one job with:
Command | Description |
---|---|
grouperSession = GrouperSession.startRootSession(); | Kick off the loader for one group (configured by group attributes) |
loaderRunOneJob("MAINTENANCE_cleanLogs"); | Kick off the loader by job name |
loaderRunOneJob("CHANGE_LOG_changeLogTempToChangeLog"); | Move change log entries from the temp table to the real table |
loaderRunOneJob("CHANGE_LOG_consumer_grouperRules"); | Run the Grouper Rules daemon (the changelog or full version) |
loaderRunOneJob("CHANGE_LOG_consumer_test"); | Run a change log consumer |
v1.6+ loader
Command | Description |
---|---|
loaderRunOneJobAttr(attirbuteDef) | Run an attribute definition loader job |
You can run the loader as a linux service
...
v2.0: to sync up the point in time tables with regular tables, run this:
Code Block |
---|
new edu.internet2.middleware.grouper.misc.SyncPITTables().syncAllPITTables()
|
To create missing group sets:
Code Block |
---|
new edu.internet2.middleware.grouper.misc.AddMissingGroupSets().addAllMissingGroupSets();
|
...
Here is an example to remove access from someone... run a SQL to generate a GSH script, e.g. in oracle:
Code Block |
---|
set linesize 1000;
set pagesize 1000;
select 'delMember("' || gmlv.GROUP_NAME || '", "' || gmlv.SUBJECT_ID || '");' as script
from grouper_memberships_lw_v gmlv where subject_id = '12345678' and gmlv.LIST_NAME = 'members';
|
Put that script in a text editor and remove extra whitespace (probably optional), and add this to the beginning:
Code Block |
---|
grouperSession = GrouperSession.startRootSession();
|
Look at it and remove lines that dont apply... then run in GSH
Code Block |
---|
[appadmin@lorenzo bin]$ ./gsh.sh remove.script
|
Here is a more complicated example. I want all groups in a certain folder which do not have an ADMIN privilege assigned to my application service principal, to assign that privilege. Here is the query for oracle:
Code Block |
---|
select 'grantPriv("' || gg.name || '", "someid/server.school.edu", AccessPrivilege.ADMIN);' as script
from grouper_groups gg where gg.name like 'school:apps:appName:spaces:%'
and not exists
(select (1) from grouper_memberships_lw_v gmlv where gg.name = gmlv.group_name and list_name = 'admins'
and gmlv.subject_id = 'someid/server.school.edu');
|
Here is an example of deleting memberships for a user in oracle, dont forget at top of script to add grouperSession = GrouperSession.startRootSession():
Code Block |
---|
set linesize 1000;
set pagesize 1000;
select 'delMember("' || gg.name || '", "' || gm.subject_id || '");'
as script
from grouper_memberships_all_v gmav, grouper_fields gf, grouper_groups gg, grouper_members gm
where GMAV.FIELD_ID = GF.ID and gm.subject_id = '12345678' and GF.name = 'members'
and GMAV.OWNER_GROUP_ID = gg.ID and GMAV.MEMBER_ID = GM.ID and GMAV.DEPTH = 0
|
Here is an example of removing privileges from a user on groups in oracle, dont forget at top of script to add grouperSession = GrouperSession.startRootSession():
Code Block |
---|
set linesize 1000;
set pagesize 1000;
select 'revokePriv("' || gmlv.group_name || '", "' || gmlv.subject_id || '", AccessPrivilege.' ||
case
when gmlv.LIST_NAME = 'admins' then 'ADMIN'
when gmlv.LIST_NAME = 'readers' then 'READ'
when gmlv.LIST_NAME = 'viewers' then 'VIEW'
when gmlv.LIST_NAME = 'updaters' then 'UPDATE'
when gmlv.LIST_NAME = 'optins' then 'OPTIN'
when gmlv.LIST_NAME = 'optouts' then 'OPTOUT'
else gmlv.LIST_NAME
end || ');'
as script
from grouper_memberships_lw_v gmlv where subject_id = '12345678' and GMLV.LIST_TYPE = 'access'
|
This oracle script will remove privileges on folders for a certain user, dont forget at top of script to add grouperSession = GrouperSession.startRootSession():
Code Block |
---|
set linesize 1000;
set pagesize 1000;
select 'revokePriv("' || gs.name || '", "' || gm.subject_id || '", NamingPrivilege.' ||
case
when gf.NAME = 'stemmers' then 'STEM'
when gf.NAME = 'creators' then 'CREATE'
else gf.NAME
end || ');'
as script
from grouper_memberships_all_v gmav, grouper_fields gf, grouper_stems gs, grouper_members gm
where GMAV.FIELD_ID = GF.ID and gm.subject_id = '12345678' and GF.type = 'naming'
and GMAV.OWNER_STEM_ID = GS.ID and GMAV.MEMBER_ID = GM.ID
|
...
Create a permission and configure action list:
Code Block |
---|
grouperSession = GrouperSession.startRootSession();
attributeDef = new AttributeDefSave(grouperSession).assignName("stem2:sub:c").assignToEffMembership(true).assignToGroup(true).assignAttributeDefType(AttributeDefType.perm).assignCreateParentStemsIfNotExist(true).save();
attributeDef.getAttributeDefActionDelegate().configureActionList("read,write");
|
...