Skip to content

Add LdapClient #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2023
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.springframework.ldap.core;

import java.util.function.Consumer;
import java.util.function.Supplier;

import javax.naming.directory.SearchControls;

class DefaultLdapClientBuilder implements LdapClient.Builder {
private ContextSource contextSource;

private Supplier<SearchControls> searchControlsSupplier = () -> {
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
controls.setCountLimit(0);
controls.setTimeLimit(0);
return controls;
};

private boolean ignorePartialResultException = false;

private boolean ignoreNameNotFoundException = false;

private boolean ignoreSizeLimitExceededException = true;

DefaultLdapClientBuilder() {}

DefaultLdapClientBuilder(ContextSource contextSource,
Supplier<SearchControls> searchControlsSupplier) {
this.contextSource = contextSource;
this.searchControlsSupplier = searchControlsSupplier;
}

@Override
public DefaultLdapClientBuilder contextSource(ContextSource contextSource) {
this.contextSource = contextSource;
return this;
}

@Override
public DefaultLdapClientBuilder defaultSearchControls(Supplier<SearchControls> searchControlsSupplier) {
this.searchControlsSupplier = searchControlsSupplier;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public DefaultLdapClientBuilder ignorePartialResultException(boolean ignore) {
this.ignorePartialResultException = ignore;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public DefaultLdapClientBuilder ignoreNameNotFoundException(boolean ignore) {
this.ignoreNameNotFoundException = ignore;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public DefaultLdapClientBuilder ignoreSizeLimitExceededException(boolean ignore) {
this.ignoreSizeLimitExceededException = ignore;
return this;
}

@Override
public DefaultLdapClientBuilder apply(Consumer<LdapClient.Builder> builderConsumer) {
builderConsumer.accept(this);
return this;
}

@Override
public DefaultLdapClientBuilder clone() {
return new DefaultLdapClientBuilder(this.contextSource, this.searchControlsSupplier);
}

@Override
public LdapClient build() {
DefaultLdapClient client = new DefaultLdapClient(this.contextSource, this.searchControlsSupplier);
client.setIgnorePartialResultException(this.ignorePartialResultException);
client.setIgnoreSizeLimitExceededException(this.ignoreSizeLimitExceededException);
client.setIgnoreNameNotFoundException(this.ignoreNameNotFoundException);
return client;
}
}
Loading