Skip to Content.
Sympa Menu

grouper-users - RE: [grouper-users] Search for people or groups: no attributes shown for LDAP subjects

Subject: Grouper Users - Open Discussion List

List archive

RE: [grouper-users] Search for people or groups: no attributes shown for LDAP subjects


Chronological Thread 
  • From: Chris Hyzer <>
  • To: "GW Brown, Information Systems and Computing" <>, "" <>
  • Cc: Grouper Users Mailing List <>
  • Subject: RE: [grouper-users] Search for people or groups: no attributes shown for LDAP subjects
  • Date: Fri, 3 Apr 2009 01:23:01 -0400
  • Accept-language: en-US
  • Acceptlanguage: en-US



> -----Original Message-----
> From: GW Brown, Information Systems and Computing
> [mailto:]
> Sent: Monday, March 30, 2009 8:36 AM
> To:
>
> Cc: Grouper Users Mailing List
> Subject: Re: [grouper-users] Search for people or groups: no attributes
> shown for LDAP subjects
>
> Hi Loris,
>
> There is no straightforward way to do this - as far as I'm aware you
> can't
> configure the JNDISourceAdapter to have composite attributes, though,
> in
> principle, you could subclass it and add extra behaviour.
>

Here is a simple example of this (well, this example uses the jdbc adapter,
but for JNDI: change name of class and file to MyGrouperJndiSourceAdapter,
and the name of the superclass to GrouperJndiSourceAdapter):

https://wiki.internet2.edu/confluence/display/GrouperWG/Example+of+customizing+the+subject+API+source+adapter

* Download the latest grouper 1.4 branch
o cvs
-d:pserver::/home/cvs/i2mi
login
o cvs
-d:pserver::/home/cvs/i2mi
export -r GROUPER_1_4_BRANCH grouper
* In grouper dir, run: ant dist
* Start the database (hsql in this case, could be mysql/postgres/oracle
also):
o F:\temp\grouper1.4\bin>java -cp ..\lib\jdbcSamples\hsqldb.jar
org.hsqldb.Server -database.0 file:grouper -dbname.0 grouper
* Add tables: (unix) bin> gsh.sh -registry -runscript (windows):
bin>gsh -registry -runscript
o (note: this is using hsql, you can do a similar thing on mysql or
postgres or oracle)
o You should now be able to browse the DB with hsqlManager or
whatever tool you use to admin the db
o (hsql) bin>java -cp ..\lib\jdbcSamples\hsqldb.jar
org.hsqldb.util.DatabaseManager -url jdbc:hsqldb:hsql://localhost/grouper
*
* Check tables: bin> gsh.sh -registry -check
o Should output: NOTE: database table/object structure (ddl) is up
to date
* Start gsh and add a subject: bin> gsh.sh
gsh 10% addSubject("mchyzer", "person", "Chris Hyzer")
hibernatesubject: id='mchyzer' type='person' name='Chris Hyzer'
gsh 11% SubjectFinder.findById("mchyzer", "person").getAttributes()

java.util.HashMap: {LFNAME=[null], LOGINID=[null]}

gsh 12% exit
* Make a directory under src/grouper called "poc" (proof of concept)
* Add a java source file of this name
"src/grouper/poc/MyGrouperJdbcSourceAdapter.java" with these contents:

/*
* @author mchyzer
* $Id$
*/
package poc;

import java.util.Set;

import org.apache.commons.lang.StringUtils;

import edu.internet2.middleware.grouper.subj.GrouperJdbcSourceAdapter;
import edu.internet2.middleware.grouper.util.GrouperUtil;
import edu.internet2.middleware.subject.Subject;
import edu.internet2.middleware.subject.SubjectNotFoundException;
import edu.internet2.middleware.subject.SubjectNotUniqueException;

/**
*
*/
public class MyGrouperJdbcSourceAdapter extends
GrouperJdbcSourceAdapter {

/**
* as an example, concatenate two attributes together, store as a
third attribute
* @param subject
*/
private void decorateSubject(Subject subject) {
if (subject != null) {
String idNameLoginid = subject.getId() + " " + subject.getName()
+ " "
+
StringUtils.defaultString(subject.getAttributeValue("LOGINID"));
subject.getAttributes().put("idNameLoginid", idNameLoginid);
}
}

@Override
public Subject getSubject(String id) throws SubjectNotFoundException,
SubjectNotUniqueException {
Subject subject = super.getSubject(id);
decorateSubject(subject);
return subject;
}

@Override
public Subject getSubjectByIdentifier(String id)
throws SubjectNotFoundException, SubjectNotUniqueException {
Subject subject = super.getSubjectByIdentifier(id);
decorateSubject(subject);
return subject;
}

@Override
public Set<Subject> search(String searchValue) {
Set<Subject> subjectSet = super.search(searchValue);
for (Subject subject : GrouperUtil.nonNull(subjectSet)) {
decorateSubject(subject);
}
return subjectSet;
}

}


* Edit the sources.xml, and instead of:
<source
adapterClass="edu.internet2.middleware.grouper.subj.GrouperJdbcSourceAdapter">
<id>jdbc</id>
Change it to:
<source adapterClass="poc.MyGrouperJdbcSourceAdapter">
<id>jdbc</id>
* Do another "ant dist" from GROUPER_HOME
* Start gsh from the bin dir, search for the subject again, see the new
attribute: idNameLoginid

gsh 0% SubjectFinder.findById("mchyzer", "person").getAttributes()
java.util.HashMap: {LFNAME=[null], idNameLoginid=mchyzer Chris Hyzer ,
LOGINID=[null]}
gsh 1%

* Note, after major upgrades of Grouper versions, you should test this to
make sure it is still accurate...


  • RE: [grouper-users] Search for people or groups: no attributes shown for LDAP subjects, Chris Hyzer, 04/03/2009

Archive powered by MHonArc 2.6.16.

Top of Page