diff --git a/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/JdkLdapClient.java b/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/JdkLdapClient.java index 0431c6df8188..4c3d5bad09f6 100644 --- a/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/JdkLdapClient.java +++ b/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/JdkLdapClient.java @@ -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) @@ -175,10 +175,10 @@ public CloseableContext(DirContext context) } @SuppressWarnings("BanJNDI") - public NamingEnumeration search(String name, String filter, SearchControls searchControls) + public NamingEnumeration 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 diff --git a/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/LdapQuery.java b/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/LdapQuery.java index 68e49488c01c..7a6c48c0c38b 100644 --- a/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/LdapQuery.java +++ b/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/LdapQuery.java @@ -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); } @@ -41,6 +44,11 @@ public String getSearchFilter() return searchFilter; } + public Object[] getFilterArguments() + { + return filterArguments; + } + public String[] getAttributes() { return attributes; @@ -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) { @@ -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"); @@ -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); } } }