Child pages
  • Grouper loader example with privileges
Skip to end of metadata
Go to start of metadata

Main Grouper Loader page

This example is in response to this post to the grouper-users email list

Add test users to the registry:

gsh 0% grouperSession = GrouperSession.startRootSession();
gsh 1% RegistryReset._addSubjects(0, 10);

Add an attribute:

Grouper starting up: version: 1.6.3, build date: null, env: <no label configured>
grouper.properties read from: C:\mchyzer\grouper\v1_6\grouper\build\grouper.properties
Grouper current directory is: C:\mchyzer\grouper\v1_6\grouper
log4j.properties read from:   C:\mchyzer\grouper\v1_6\grouper\build\log4j.properties
Grouper is logging to file:   C:\mchyzer\grouper\v1_6\grouper\logs\grouper_error.log, at min level WARN for package: edu.internet2.middleware.grouper, based on log4j.properties
grouper.hibernate.properties: C:\mchyzer\grouper\v1_6\grouper\build\grouper.hibernate.properties
grouper.hibernate.properties: grouper_v1_6@jdbc:mysql://localhost:3306/grouper_v1_6
sources.xml read from:        C:\mchyzer\grouper\v1_6\grouper\build\sources.xml
sources.xml groupersource id: g:gsa
sources.xml jdbc source id:   jdbc: GrouperJdbcConnectionProvider
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoader
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderType
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderDbName
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderScheduleType
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderQuartzCron
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderIntervalSeconds
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderPriority
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderAttrsLike
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderAttrQuery
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderAttrSetQuery
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderActionQuery
Grouper note: auto-created attributeDefName: etc:attribute:attrLoader:attributeLoaderActionSetQuery
Type help() for instructions
gsh 0% grouperSession = GrouperSession.startRootSession();
edu.internet2.middleware.grouper.GrouperSession: 68de5538cb694321a89d09acf41ca4a8,'GrouperSystem','application'
gsh 4% RegistryReset._addSubjects(0, 10);
gsh 5% RegistrySubject registrySubject = new RegistrySubject();
gsh 6% registrySubject.setId("uportal_user");
gsh 7% registrySubject.setName("uportal_user");
gsh 8% registrySubject.setTypeString("person");
gsh 17% registrySubject.getAttributes().put("monAttribut", GrouperUtil.toSet(new String[]{"Valeur A"}));
Valeur A
gsh 19% GrouperDAOFactory.getFactory().getRegistrySubject().create(registrySubject);
gsh 20% registrySubject = GrouperDAOFactory.getFactory().getRegistrySubject().find("test.subject.0", "person", true);
hibernatesubject: id='test.subject.0' type='person' name='my name is test.subject.0'
gsh 21% registrySubjectAttribute = new RegistrySubjectAttribute();
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@d23ad
gsh 22% registrySubjectAttribute.setName("monAttribut");
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@4ad820b6
gsh 23% registrySubjectAttribute.setValue("Valeur B");
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@f9cb2fb9
gsh 24% registrySubjectAttribute.setSearchValue("valeur b");
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@f9cb2fb9
gsh 25% registrySubjectAttribute.setSubjectId(registrySubject.getId());
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@11d79d7b
gsh 26% HibernateSession.byObjectStatic().save(registrySubjectAttribute);
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@11d79d7b
gsh 27% registrySubject = GrouperDAOFactory.getFactory().getRegistrySubject().find("test.subject.2", "person", true);
hibernatesubject: id='test.subject.2' type='person' name='my name is test.subject.2'
gsh 28% registrySubjectAttribute = new RegistrySubjectAttribute();
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@d23ad
gsh 29% registrySubjectAttribute.setName("monAttribut");
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@4ad820b6
gsh 30% registrySubjectAttribute.setValue("Valeur C");
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@f9cb2fba
gsh 31% registrySubjectAttribute.setSearchValue("valeur c");
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@f9cb2fba
gsh 32% registrySubjectAttribute.setSubjectId(registrySubject.getId());
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@11d7a82e
gsh 33% HibernateSession.byObjectStatic().save(registrySubjectAttribute);
edu.internet2.middleware.grouper.RegistrySubjectAttribute: edu.internet2.middleware.grouper.RegistrySubjectAttribute@11d7a82e
gsh 34% GrouperDAOFactory.getFactory().getRegistrySubject().create(registrySubject);

Create a view for the loader group:

CREATE OR REPLACE VIEW loader_test_listes AS
SELECT CONCAT('esup:groupes_auto:test_listes:',TRIM(VALUE)) AS group_name,
CONCAT('Groupe auto Attribut ',VALUE) AS group_display_name,
CONCAT('monAttribut=', VALUE) AS group_description,
CONCAT('esup:groupes_auto:test_listes:',TRIM(VALUE)) AS readers,
TRIM(VALUE) AS attribute_value
FROM subjectattribute WHERE NAME='monAttribut'

Create the loader type on startup in grouper-loader.properties:

# auto-add grouper loader types and attributes when grouper starts up if they are not there
loader.autoadd.typesAttributes = true

Create a view of members for the loader group:

CREATE OR REPLACE VIEW loader_test_listes_members AS
SELECT group_name, sa.subjectId AS subject_id
 FROM loader_test_listes ltl, subjectattribute sa
WHERE sa.name = 'monAttribut' AND sa.value = ltl.attribute_value

Create the loader group:

gsh 35% group=new GroupSave(grouperSession).assignName("aStem:loaderGroup").assignCreateParentStemsIfNotExist(true).save();
group: name='aStem:loaderGroup' displayName='aStem:loaderGroup' uuid='280fc3d01c6847aba35ea67bdea92be8'gsh 38% groupAddType("aStem:loaderGroup", "grouperLoader")
true
gsh 39% setGroupAttr("aStem:loaderGroup", "grouperLoaderDbName", "grouper")
true
gsh 40% setGroupAttr("aStem:loaderGroup", "grouperLoaderType", "SQL_GROUP_LIST")
true
gsh 41% setGroupAttr("aStem:loaderGroup", "grouperLoaderScheduleType", "CRON")
true
gsh 42% setGroupAttr("aStem:loaderGroup", "grouperLoaderQuartzCron", "0 0 8 * * ? ")
true
gsh 43% setGroupAttr("aStem:loaderGroup", "grouperLoaderGroupQuery", "SELECT group_name, group_display_name, group_description, readers FROM loader_test_listes")
true
gsh 44% setGroupAttr("aStem:loaderGroup", "grouperLoaderQuery", "SELECT group_name, subject_id, 'jdbc' as subject_source_id FROM loader_test_listes_members")
true

Run the loader job:

gsh 46% group = GroupFinder.findByName(grouperSession, "aStem:loaderGroup", true);
group: name='aStem:loaderGroup' displayName='aStem:loaderGroup' uuid='280fc3d01c6847aba35ea67bdea92be8'
gsh 47% loaderRunOneJob(group);
loader ran successfully, inserted 3 memberships, deleted 0 memberships, total membership count: 3

Check the memberships:

gsh 48% getMembers("esup:groupes_auto:test_listes:Valeur B");
member: id='test.subject.0' type='person' source='jdbc' uuid='e9c7d890774448e0a40d722e7c3d3209'
gsh 49% getMembers("esup:groupes_auto:test_listes:Valeur A");
member: id='uportal_user' type='person' source='jdbc' uuid='d596481e981b4404a35174633ef1d7f8'
gsh 50% getMembers("esup:groupes_auto:test_listes:Valeur C");
member: id='test.subject.2' type='person' source='jdbc' uuid='c8c8f3983bf642fbae5d4ae2e37ffe55'

Check the privileges

gsh 3% group = GroupFinder.findByName(grouperSession, "esup:groupes_auto:test_listes:Valeur B", true);
group: name='esup:groupes_auto:test_listes:Valeur B' displayName='esup:groupes_auto:test_listes:Groupe auto Attribut Valeur B' uuid='5242e40001a5441cab835714616fb1d4'
gsh 4% group.getReaders();
subject: id='5242e40001a5441cab835714616fb1d4' type='group' source='g:gsa' name='esup:groupes_auto:test_listes:Valeur B'
subject: id='GrouperAll' type='application' source='g:isa' name='EveryEntity'
subject: id='test.subject.0' type='person' source='jdbc' name='my name is test.subject.0'
gsh 5% group = GroupFinder.findByName(grouperSession, "esup:groupes_auto:test_listes:Valeur A", true);
group: name='esup:groupes_auto:test_listes:Valeur A' displayName='esup:groupes_auto:test_listes:Groupe auto Attribut Valeur A' uuid='da0ffbe3c5ae429d8f1ba4068f4dd935'
gsh 6% group.getReaders();
subject: id='uportal_user' type='person' source='jdbc' name='uportal_user'
subject: id='GrouperAll' type='application' source='g:isa' name='EveryEntity'
subject: id='da0ffbe3c5ae429d8f1ba4068f4dd935' type='group' source='g:gsa' name='esup:groupes_auto:test_listes:Valeur A'
gsh 7% group = GroupFinder.findByName(grouperSession, "esup:groupes_auto:test_listes:Valeur C", true);
group: name='esup:groupes_auto:test_listes:Valeur C' displayName='esup:groupes_auto:test_listes:Groupe auto Attribut Valeur C' uuid='da6f70a45e664cc3a956cdb17e53c19f'
gsh 8% group.getReaders();
subject: id='test.subject.2' type='person' source='jdbc' name='my name is test.subject.2'
subject: id='GrouperAll' type='application' source='g:isa' name='EveryEntity'
subject: id='da6f70a45e664cc3a956cdb17e53c19f' type='group' source='g:gsa' name='esup:groupes_auto:test_listes:Valeur C'
  • No labels