Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Fix invalid group failure bug and baseDn #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,14 @@ protected Set<LdapName> resolveNestedRoles(final LdapName roleDn, final Connecti

final Set<LdapName> result = new HashSet<>(20);
final HashMultimap<LdapName, Map.Entry<String, Settings>> resultRoleSearchBaseKeys = HashMultimap.create();

final LdapEntry e0 = LdapHelper.lookup(ldapConnection, roleDn.toString());

LdapEntry e0 = null;
try {
e0 = LdapHelper.lookup(ldapConnection, roleDn.toString());
} catch (LdapException e) {
log.debug("Error found while going over nested groups ", e);
return result;
}

if (e0.getAttribute(userRoleName) != null) {
final Collection<String> userRoles = e0.getAttribute(userRoleName).getStringValues();
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/com/amazon/dlic/auth/ldap/util/LdapHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import java.util.ArrayList;
import java.util.List;

import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;

import org.elasticsearch.SpecialPermission;
import org.ldaptive.Connection;
import org.ldaptive.DerefAliases;
Expand Down Expand Up @@ -75,14 +79,35 @@ public List<LdapEntry> run() throws Exception {
}

public static LdapEntry lookup(final Connection conn, final String dn) throws LdapException {
try {
final List<LdapEntry> entries = search(conn, escapeDn(dn), "(objectClass=*)", SearchScope.OBJECT);

if (entries.size() == 1) {
return entries.get(0);
} else {
return null;
}
} catch (InvalidNameException e) {
throw new RuntimeException(e);
}
}

final List<LdapEntry> entries = search(conn, dn, "(objectClass=*)", SearchScope.OBJECT);
private static String escapeDn(String dn) throws InvalidNameException {
final LdapName dnName = new LdapName(dn);
final List<Rdn> escaped = new ArrayList<>(dnName.size());
for(Rdn rdn: dnName.getRdns()) {
escaped.add(new Rdn(rdn.getType(), escapeForwardSlash(rdn.getValue())));
}
return new LdapName(escaped).toString();
}

if (entries.size() == 1) {
return entries.get(0);
private static Object escapeForwardSlash(Object input) {
if(input != null && input instanceof String) {
return ((String)input).replace("/", "\\2f");
} else {
return null;
return input;
}

}

}