Skip to content
Merged
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 @@ -84,6 +84,15 @@ public JdkLdapClient(LdapClientConfig ldapConfig)
ldapConfig.getTruststorePassword());
}

@Override
public <T> T processLdapContext(String userName, String password, LdapContextProcessor<T> contextProcessor)
throws NamingException
{
try (CloseableContext context = createUserDirContext(userName, password)) {
return contextProcessor.process(context.context);
}
}

@Override
public <T> T executeLdapQuery(String userName, String password, LdapQuery ldapQuery, LdapSearchResultProcessor<T> resultProcessor)
throws NamingException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchResult;

public interface LdapClient
{
<T> T processLdapContext(String userName, String password, LdapContextProcessor<T> contextProcessor)
throws NamingException;

<T> T executeLdapQuery(String userName, String password, LdapQuery ldapQuery, LdapSearchResultProcessor<T> resultProcessor)
throws NamingException;

Expand All @@ -27,4 +31,10 @@ interface LdapSearchResultProcessor<T>
T process(NamingEnumeration<SearchResult> searchResults)
throws NamingException;
}

interface LdapContextProcessor<T>
{
T process(DirContext dirContext)
throws NamingException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ public LdapAuthenticatorClient(LdapClient ldapClient)
public void validatePassword(String userDistinguishedName, String password)
throws NamingException
{
ldapClient.executeLdapQuery(
userDistinguishedName,
password,
new LdapQuery.LdapQueryBuilder()
.withSearchBase(userDistinguishedName)
.withSearchFilter(userDistinguishedName)
.build(),
searchResults -> null);
ldapClient.processLdapContext(userDistinguishedName, password, context -> null);
}

public boolean isGroupMember(String searchBase, String groupSearch, String contextUserDistinguishedName, String contextPassword)
Expand Down