forked from trinodb/trino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract LdapClient to plugin-toolkit
- Loading branch information
1 parent
02955a1
commit 9e0b2e5
Showing
16 changed files
with
246 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/LdapClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.plugin.base.ldap; | ||
|
||
import javax.naming.NamingEnumeration; | ||
import javax.naming.NamingException; | ||
import javax.naming.directory.SearchResult; | ||
|
||
public interface LdapClient | ||
{ | ||
<T> T executeLdapQuery(String userName, String password, LdapQuery ldapQuery, LdapSearchResultProcessor<T> resultProcessor) | ||
throws NamingException; | ||
|
||
interface LdapSearchResultProcessor<T> | ||
{ | ||
T process(NamingEnumeration<SearchResult> searchResults) | ||
throws NamingException; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/LdapClientModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.plugin.base.ldap; | ||
|
||
import com.google.inject.Binder; | ||
import com.google.inject.Module; | ||
import com.google.inject.Scopes; | ||
|
||
import static io.airlift.configuration.ConfigBinder.configBinder; | ||
|
||
public class LdapClientModule | ||
implements Module | ||
{ | ||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
configBinder(binder).bindConfig(LdapClientConfig.class); | ||
binder.bind(LdapClient.class).to(JdkLdapClient.class).in(Scopes.SINGLETON); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ldap/LdapQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.plugin.base.ldap; | ||
|
||
import java.util.Arrays; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class LdapQuery | ||
{ | ||
private final String searchBase; | ||
private final String searchFilter; | ||
private final String[] attributes; | ||
|
||
private LdapQuery(String searchBase, String searchFilter, String[] attributes) | ||
{ | ||
this.searchBase = requireNonNull(searchBase, "searchBase is null"); | ||
this.searchFilter = requireNonNull(searchFilter, "searchFilter is null"); | ||
requireNonNull(attributes, "attributes is null"); | ||
this.attributes = Arrays.copyOf(attributes, attributes.length); | ||
} | ||
|
||
public String getSearchBase() | ||
{ | ||
return searchBase; | ||
} | ||
|
||
public String getSearchFilter() | ||
{ | ||
return searchFilter; | ||
} | ||
|
||
public String[] getAttributes() | ||
{ | ||
return attributes; | ||
} | ||
|
||
public static class LdapQueryBuilder | ||
{ | ||
private String searchBase; | ||
private String searchFilter; | ||
private String[] attributes = new String[0]; | ||
|
||
public LdapQueryBuilder withSearchBase(String searchBase) | ||
{ | ||
this.searchBase = requireNonNull(searchBase, "searchBase is null"); | ||
return this; | ||
} | ||
|
||
public LdapQueryBuilder withSearchFilter(String searchFilter) | ||
{ | ||
this.searchFilter = requireNonNull(searchFilter, "searchFilter is null"); | ||
return this; | ||
} | ||
|
||
public LdapQueryBuilder withAttributes(String... attributes) | ||
{ | ||
this.attributes = requireNonNull(attributes, "attributes is null"); | ||
return this; | ||
} | ||
|
||
public LdapQuery build() | ||
{ | ||
return new LdapQuery(searchBase, searchFilter, attributes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.