[Fix] read all group names
This commit is contained in:
parent
6deafccb33
commit
65ad19bffe
|
@ -11,6 +11,7 @@ import java.util.Set;
|
||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
import javax.naming.NamingEnumeration;
|
import javax.naming.NamingEnumeration;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
|
import javax.naming.directory.Attribute;
|
||||||
import javax.naming.directory.Attributes;
|
import javax.naming.directory.Attributes;
|
||||||
import javax.naming.directory.DirContext;
|
import javax.naming.directory.DirContext;
|
||||||
import javax.naming.directory.InitialDirContext;
|
import javax.naming.directory.InitialDirContext;
|
||||||
|
@ -97,21 +98,28 @@ public class LdapPrivilegeHandler extends DefaultPrivilegeHandler {
|
||||||
SearchResult sr = (SearchResult) answer.next();
|
SearchResult sr = (SearchResult) answer.next();
|
||||||
|
|
||||||
Attributes attrs = sr.getAttributes();
|
Attributes attrs = sr.getAttributes();
|
||||||
memberOfLdapString = (attrs.get("memberOf") != null) ? attrs.get("memberOf").get().toString() : "";
|
Attribute groupMembers = attrs.get("memberOf");
|
||||||
|
|
||||||
// extract group name from ldap string -> CN=groupname,OU=company,DC=domain,DC=country
|
if (groupMembers != null) {
|
||||||
LdapName memberOfName = new LdapName(memberOfLdapString);
|
for (int i = 0; i < groupMembers.size(); i++) {
|
||||||
for (Rdn rdn : memberOfName.getRdns()) {
|
|
||||||
if (rdn.getType().equalsIgnoreCase("CN")) {
|
memberOfLdapString = attrs.get("memberOf").get(i).toString();
|
||||||
String groupName = rdn.getValue().toString();
|
|
||||||
Set<String> foundStrolchRoles = rolesForLdapGroups.get(groupName);
|
// extract group name from ldap string -> CN=groupname,OU=company,DC=domain,DC=country
|
||||||
if (foundStrolchRoles != null)
|
LdapName memberOfName = new LdapName(memberOfLdapString);
|
||||||
strolchRoles.addAll(foundStrolchRoles);
|
for (Rdn rdn : memberOfName.getRdns()) {
|
||||||
break;
|
if (rdn.getType().equalsIgnoreCase("CN")) {
|
||||||
|
String groupName = rdn.getValue().toString();
|
||||||
|
Set<String> foundStrolchRoles = rolesForLdapGroups.get(groupName);
|
||||||
|
if (foundStrolchRoles != null)
|
||||||
|
strolchRoles.addAll(foundStrolchRoles);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("User " + username + " is member of groups: " + memberOfLdapString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("User " + username + " is member of groups: " + memberOfLdapString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.close();
|
ctx.close();
|
||||||
|
|
Loading…
Reference in New Issue