Skip to content

Commit

Permalink
Add LDAP filter argument support to JdkLdapClient
Browse files Browse the repository at this point in the history
  • Loading branch information
mosiac1 committed Sep 20, 2024
1 parent 95f2b4d commit c5cb5aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static CloseableSearchResults searchContext(LdapQuery ldapQuery, Closeab
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
searchControls.setReturningAttributes(ldapQuery.getAttributes());
return new CloseableSearchResults(context.search(ldapQuery.getSearchBase(), ldapQuery.getSearchFilter(), searchControls));
return new CloseableSearchResults(context.search(ldapQuery.getSearchBase(), ldapQuery.getSearchFilter(), ldapQuery.getFilterArguments(), searchControls));
}

private CloseableContext createUserDirContext(String userDistinguishedName, String password)
Expand Down Expand Up @@ -175,10 +175,10 @@ public CloseableContext(DirContext context)
}

@SuppressWarnings("BanJNDI")
public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls searchControls)
public NamingEnumeration<SearchResult> search(String name, String filter, Object[] filterArguments, SearchControls searchControls)
throws NamingException
{
return context.search(name, filter, searchControls);
return context.search(name, filter, filterArguments, searchControls);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ public class LdapQuery
{
private final String searchBase;
private final String searchFilter;
private final Object[] filterArguments;
private final String[] attributes;

private LdapQuery(String searchBase, String searchFilter, String[] attributes)
private LdapQuery(String searchBase, String searchFilter, Object[] filterArguments, String[] attributes)
{
this.searchBase = requireNonNull(searchBase, "searchBase is null");
this.searchFilter = requireNonNull(searchFilter, "searchFilter is null");
requireNonNull(attributes, "attributes is null");
requireNonNull(filterArguments, "filterArguments is null");
this.filterArguments = Arrays.copyOf(filterArguments, filterArguments.length);
this.attributes = Arrays.copyOf(attributes, attributes.length);
}

Expand All @@ -41,6 +44,11 @@ public String getSearchFilter()
return searchFilter;
}

public Object[] getFilterArguments()
{
return filterArguments;
}

public String[] getAttributes()
{
return attributes;
Expand All @@ -51,6 +59,7 @@ public static class LdapQueryBuilder
private String searchBase;
private String searchFilter;
private String[] attributes = new String[0];
private Object[] filterArguments = new Object[0];

public LdapQueryBuilder withSearchBase(String searchBase)
{
Expand All @@ -64,6 +73,12 @@ public LdapQueryBuilder withSearchFilter(String searchFilter)
return this;
}

public LdapQueryBuilder withFilterArguments(Object... arguments)
{
this.filterArguments = requireNonNull(arguments, "arguments is null");
return this;
}

public LdapQueryBuilder withAttributes(String... attributes)
{
this.attributes = requireNonNull(attributes, "attributes is null");
Expand All @@ -72,7 +87,7 @@ public LdapQueryBuilder withAttributes(String... attributes)

public LdapQuery build()
{
return new LdapQuery(searchBase, searchFilter, attributes);
return new LdapQuery(searchBase, searchFilter, filterArguments, attributes);
}
}
}

0 comments on commit c5cb5aa

Please sign in to comment.