grouper-users - RE: [grouper-users] loading nested groups from an LDAP source
Subject: Grouper Users - Open Discussion List
List archive
- From: "Hyzer, Chris" <>
- To: Rob Gorrell <>
- Cc: "" <>
- Subject: RE: [grouper-users] loading nested groups from an LDAP source
- Date: Thu, 4 Aug 2016 16:37:20 +0000
- Accept-language: en-US
- Authentication-results: spf=none (sender IP is ) ;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
Glad it worked. Heres my test case: String subjectId = convertDntoSubjectIdOrIdentifier("CN=JNWHITWO,OU=Users,OU=ITS-23101,OU=UNIT-InformationTechnologyServices-2D031,OU=COLL-InformationTechnologyServices-02C01,OU=DIV-InformationTechnologyServices-DIV02,OU=FACSTAFF,DC=campus,DC=uncg,DC=edu");
if (!"jnwhitwo".equals(subjectId)) { throw new RuntimeException("Expecting jnwhitwo but got: '" + subjectId + "'"); }
subjectId = convertDntoSubjectIdOrIdentifier("CN=ITS-23101-SYN-Identity_Architecture,OU=Groups,OU=ITS-23101,OU=UNIT-InformationTechnologyServices-2D031,OU=COLL-InformationTechnologyServices-02C01,OU=DIV-InformationTechnologyServices-DIV02,OU=FACSTAFF,DC=campus,DC=uncg,DC=edu"); if (!"uncg:facstaff:ITS-23101:ITS-23101-SYN-Identity_Architecture".equals(subjectId)) { throw new RuntimeException("Expecting uncg:facstaff:ITS-23101:ITS-23101-SYN-Identity_Architecture but got: '" + subjectId + "'"); } System.out.println("Success"); For people: CN=JNWHITWO,OU=Users,OU=ITS-23101,OU=UNIT-InformationTechnologyServices-2D031,OU=COLL-InformationTechnologyServices-02C01,OU=DIV-InformationTechnologyServices-DIV02,OU=FACSTAFF,DC=campus,DC=uncg,DC=edu Needs to be converted to Jnwhitwo That is what the
loaderLdapElUtils.convertDnToSpecificValue(subjectId) does. For groups: CN=ITS-23101-SYN-Identity_Architecture,OU=Groups,OU=ITS-23101,OU=UNIT-InformationTechnologyServices-2D031,OU=COLL-InformationTechnologyServices-02C01,OU=DIV-InformationTechnologyServices-DIV02,OU=FACSTAFF,DC=campus,DC=uncg,DC=edu Needs to be converted to:
uncg:facstaff:ITS-23101:ITS-23101-SYN-Identity_Architecture As you can see that is not as straightforward. I think flat vs bushy for ldap groups could be a factor. In fact, you might want to look at the attached source
and make sure it works for you, i.e. are those two test cases sufficient?
J Thanks Chris Ps. well, attachments might not work, here it is inline: /** *
@author mchyzer * $Id$ */ package ldapGroupUserConverter; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; /** * Convert a DN to a subjectId if its a person or to a groupName in Grouper if a group */ public
class LdapGroupUserConverter {
/** *
*/
public LdapGroupUserConverter() { }
/** *
@param args */
public
static
void main(String[] args) { String equalsValuePart =
equalsValuePart("CN=ABCDEF");
if
(!"ABCDEF".equals(equalsValuePart)) {
throw
new RuntimeException("Expecting ABCDEF
as the equals value part but got: '" + equalsValuePart +
"'"); }
String subjectId =
convertDntoSubjectIdOrIdentifier("CN=JNWHITWO,OU=Users,OU=ITS-23101,OU=UNIT-InformationTechnologyServices-2D031,OU=COLL-InformationTechnologyServices-02C01,OU=DIV-InformationTechnologyServices-DIV02,OU=FACSTAFF,DC=campus,DC=uncg,DC=edu");
if
(!"jnwhitwo".equals(subjectId)) {
throw
new RuntimeException("Expecting jnwhitwo
but got: '" + subjectId +
"'"); }
subjectId =
convertDntoSubjectIdOrIdentifier("CN=ITS-23101-SYN-Identity_Architecture,OU=Groups,OU=ITS-23101,OU=UNIT-InformationTechnologyServices-2D031,OU=COLL-InformationTechnologyServices-02C01,OU=DIV-InformationTechnologyServices-DIV02,OU=FACSTAFF,DC=campus,DC=uncg,DC=edu");
if (!"uncg:facstaff:ITS-23101:ITS-23101-SYN-Identity_Architecture".equals(subjectId))
{
throw
new RuntimeException("Expecting uncg:facstaff:ITS-23101:ITS-23101-SYN-Identity_Architecture
but got: '" + subjectId +
"'"); } System.out.println("Success"); }
/** logger */
final
static Logger
LOG = Logger.getLogger(LdapGroupUserConverter.class);
/** * convert dn to subject identifier or group name, log the result *
@param dn *
@return the subject identifier or group name */
public
static String convertDntoSubjectIdOrIdentifier(String dn) { String result =
convertDntoSubjectIdOrIdentifierHelper(dn);
LOG.debug("Converting dn '"
+ dn + "' to: '" + result +
"'");
return result; }
/** * convert dn to subject identifier or group name, log the result *
@param dn *
@return the subject identifier or group name */
private
static String convertDntoSubjectIdOrIdentifierHelper(String dn) {
if (dn ==
null ||
"".equals(dn.trim())) {
return dn; } String[] partsArray = dn.split(",");
List<String> partsList =
new ArrayList<String>();
for
(String string : partsArray) { partsList.add(string); }
//get a user: CN=JNWHITWO,OU=Users
if (partsList.size() >= 2 &&
"OU=Users".equals(partsList.get(1))) { String firstPart = partsList.get(0);
if (firstPart !=
null && firstPart.startsWith("CN="))
{
return
equalsValuePart(firstPart).toLowerCase(); } }
//get a group:
// From: CN=ITS-23101-SYN-Identity_Architecture,OU=Groups,OU=ITS-23101,OU=UNIT-InformationTechnologyServices-2D031,OU=COLL-InformationTechnologyServices-02C01,OU=DIV-InformationTechnologyServices-DIV02,OU=FACSTAFF,DC=campus,DC=uncg,DC=edu
//CN=ITS-23101-SYN-Identity_Architecture,
//OU=Groups,
//OU=ITS-23101,
//OU=UNIT-InformationTechnologyServices-2D031,
//OU=COLL-InformationTechnologyServices-02C01,
//OU=DIV-InformationTechnologyServices-DIV02,
//OU=FACSTAFF,
//DC=campus,
//DC=uncg,
//DC=edu
// To: uncg:facstaff:ITS-23101:ITS-23101-SYN-Identity_Architecture
if (partsList.size() >= 2 &&
"OU=Groups".equals(partsList.get(1))) {
StringBuilder groupName =
new StringBuilder(); groupName.insert(0,
equalsValuePart(partsList.get(0))); groupName.insert(0,
":");
//remove extension partsList.remove(0);
//remove ou=groups partsList.remove(0);
if
(partsList.size() > 0) {
groupName.insert(0,
equalsValuePart(partsList.get(0))); groupName.insert(0,
":"); partsList.remove(0); }
//go until facstaff
while(true)
{
if (partsList.size() >= 2 && partsList.get(1) !=
null &&
"dc=campus".equals(partsList.get(1).toLowerCase()) ) { groupName.insert(0,
equalsValuePart(partsList.get(0)).toLowerCase()); groupName.insert(0,
":"); partsList.remove(0);
break; } partsList.remove(0); }
if
(partsList.size() > 2) {
//get rid of campus partsList.remove(0);
//we are left with uncg groupName.insert(0,
equalsValuePart(partsList.get(0)).toLowerCase());
return
groupName.toString(); }
}
return dn; }
/** * convert AB=whatever to whatever *
@param string *
@return the "whatever" value */
public
static String equalsValuePart(String string) {
if
(string == null) {
return string; }
int
equalsIndex = string.indexOf('=');
if
(equalsIndex < 0) {
return string; }
return string.substring(equalsIndex+1, string.length());
}
} From: Rob Gorrell [mailto:]
Excellent Chris, thank you, this is working flawlessly... i'm now loading AD groups of groups inside grouper preserving the "nesting". I'm trying to understand in english terms, why this was a customization and I guess it has to do with my lack of understanding for the LDAP subject _expression_ attribute. Normally, I was using loaderLdapElUtils.convertDnToSpecificValue(subjectId)...
which I guess took the user object's ldap DN and matched it to a subjectID. but the part that doesn't make sense to me, is our users's subjectID's are unix UID's... not usernames or DNs. So why were we mapping users ok based on DN's but not groups? I'm just trying to understand why this customization that you so wonderfully wrote for me was needed in the first place (but I am still very thankful that it works). Could I have named/loaded/etc my groups differently
where such a customization wouldn't have been needed to load groups of groups? -Rob On Thu, Aug 4, 2016 at 8:55 AM, Hyzer, Chris <> wrote:
Robert W. Gorrell University of NC at Greensboro |
- RE: [grouper-users] loading nested groups from an LDAP source, Hyzer, Chris, 08/04/2016
- <Possible follow-up(s)>
- RE: [grouper-users] loading nested groups from an LDAP source, Hyzer, Chris, 08/04/2016
- Re: [grouper-users] loading nested groups from an LDAP source, Rob Gorrell, 08/04/2016
- RE: [grouper-users] loading nested groups from an LDAP source, Hyzer, Chris, 08/04/2016
- Re: [grouper-users] loading nested groups from an LDAP source, Rob Gorrell, 08/04/2016
Archive powered by MHonArc 2.6.19.