Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need help getting users from nested groups
currently I am getting the users within a group, but not users within sub groups

what is it that I can add to the existing queries to get all users within nested groups

for eg
Main group
-User 1
-User 2
-Sub group
|
-user 3
My current code will return only User 1 & User 2. I need it to return User 3 as well

What I have tried:

Java
//snippet of my function which calls all methods
List<Attribute> memAttrList = ldapTemplate.search(getUsersInGrp(distributionList), new UsersMapper());
for (String distinguishedName : getUsersFromAttributeList(memAttrList )) {
    //String subGroup = (String)distinguishedName.
    membersKerbList.addAll(ldapTemplate.search(getUsername(distinguishedName), new KerberosMapper()));
}
 
//child methods
private LdapQuery getUsersInGrp(String distributionList) {
    return query().base(this.base)
            .attributes(AD_FIELD_MEMBER)
            .where(AD_FIELD_OBJECT_CLASS).is("group")
            .and(query()
                            .where(AD_FIELD_CN).is(distributionList)
                            .or(AD_FIELD_MAIL_NICKNAME).is(distributionList)
            );
}
private List<String> getUsersFromAttributeList(List<Attribute> memAttrList ) {
    List<String> membersDn = new ArrayList<>();
    try {
        for (Attribute membersAttribute : memAttrList ) {
            NamingEnumeration<?> memberEnumeration = membersAttribute.getAll();
            while (memberEnumeration.hasMore()) {
                membersDn.add(memberEnumeration.next().toString());
            }
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
    return membersDn;
}

private LdapQuery getUsername(String distinguishedName) {
    
    return query().base(this.base)
            .attributes(AD_FIELD_KERBEROS)
            .where(AD_FIELD_OBJECT_CLASS).is("user")
                    //.or(AD_FIELD_OBJECT_CLASS).is("group")
            //.or(AD_FIELD_OBJECT_CLASS).is("group");
            .and(AD_FIELD_DN).is(distinguishedName);
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900