|
| 1 | +package org.springframework.ldap.core; |
| 2 | + |
| 3 | +import java.util.function.Consumer; |
| 4 | +import java.util.function.Supplier; |
| 5 | + |
| 6 | +import javax.naming.directory.SearchControls; |
| 7 | + |
| 8 | +class DefaultLdapClientBuilder implements LdapClient.Builder { |
| 9 | + private ContextSource contextSource; |
| 10 | + |
| 11 | + private Supplier<SearchControls> searchControlsSupplier = () -> { |
| 12 | + SearchControls controls = new SearchControls(); |
| 13 | + controls.setSearchScope(SearchControls.SUBTREE_SCOPE); |
| 14 | + controls.setCountLimit(0); |
| 15 | + controls.setTimeLimit(0); |
| 16 | + return controls; |
| 17 | + }; |
| 18 | + |
| 19 | + private boolean ignorePartialResultException = false; |
| 20 | + |
| 21 | + private boolean ignoreNameNotFoundException = false; |
| 22 | + |
| 23 | + private boolean ignoreSizeLimitExceededException = true; |
| 24 | + |
| 25 | + DefaultLdapClientBuilder() {} |
| 26 | + |
| 27 | + DefaultLdapClientBuilder(ContextSource contextSource, |
| 28 | + Supplier<SearchControls> searchControlsSupplier) { |
| 29 | + this.contextSource = contextSource; |
| 30 | + this.searchControlsSupplier = searchControlsSupplier; |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public DefaultLdapClientBuilder contextSource(ContextSource contextSource) { |
| 35 | + this.contextSource = contextSource; |
| 36 | + return this; |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public DefaultLdapClientBuilder defaultSearchControls(Supplier<SearchControls> searchControlsSupplier) { |
| 41 | + this.searchControlsSupplier = searchControlsSupplier; |
| 42 | + return this; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * {@inheritDoc} |
| 47 | + */ |
| 48 | + @Override |
| 49 | + public DefaultLdapClientBuilder ignorePartialResultException(boolean ignore) { |
| 50 | + this.ignorePartialResultException = ignore; |
| 51 | + return this; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * {@inheritDoc} |
| 56 | + */ |
| 57 | + @Override |
| 58 | + public DefaultLdapClientBuilder ignoreNameNotFoundException(boolean ignore) { |
| 59 | + this.ignoreNameNotFoundException = ignore; |
| 60 | + return this; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * {@inheritDoc} |
| 65 | + */ |
| 66 | + @Override |
| 67 | + public DefaultLdapClientBuilder ignoreSizeLimitExceededException(boolean ignore) { |
| 68 | + this.ignoreSizeLimitExceededException = ignore; |
| 69 | + return this; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public DefaultLdapClientBuilder apply(Consumer<LdapClient.Builder> builderConsumer) { |
| 74 | + builderConsumer.accept(this); |
| 75 | + return this; |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public DefaultLdapClientBuilder clone() { |
| 80 | + return new DefaultLdapClientBuilder(this.contextSource, this.searchControlsSupplier); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public LdapClient build() { |
| 85 | + DefaultLdapClient client = new DefaultLdapClient(this.contextSource, this.searchControlsSupplier); |
| 86 | + client.setIgnorePartialResultException(this.ignorePartialResultException); |
| 87 | + client.setIgnoreSizeLimitExceededException(this.ignoreSizeLimitExceededException); |
| 88 | + client.setIgnoreNameNotFoundException(this.ignoreNameNotFoundException); |
| 89 | + return client; |
| 90 | + } |
| 91 | +} |
0 commit comments