diff --git a/server/container/guice/data-ldap/src/test/java/org/apache/james/data/DockerLdapRule.java b/server/container/guice/data-ldap/src/test/java/org/apache/james/data/DockerLdapRule.java index 5fbc002e3a2..d45f2437e5b 100644 --- a/server/container/guice/data-ldap/src/test/java/org/apache/james/data/DockerLdapRule.java +++ b/server/container/guice/data-ldap/src/test/java/org/apache/james/data/DockerLdapRule.java @@ -19,7 +19,9 @@ package org.apache.james.data; +import java.net.URI; import java.util.List; +import java.util.stream.Collectors; import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.james.GuiceModuleTestRule; @@ -28,6 +30,7 @@ import org.junit.runner.Description; import org.junit.runners.model.Statement; +import com.github.fge.lambdas.Throwing; import com.google.inject.Module; public class DockerLdapRule implements GuiceModuleTestRule { @@ -44,9 +47,12 @@ public Statement apply(Statement statement, Description description) { } private LdapRepositoryConfiguration computeConfiguration(List ldapIps) { + List uris = ldapIps.stream() + .map(Throwing.function(URI::new)) + .collect(Collectors.toUnmodifiableList()); try { return LdapRepositoryConfiguration.builder() - .ldapHosts(ldapIps) + .ldapHosts(uris) .principal("cn=admin,dc=james,dc=org") .credentials("mysecretpassword") .userBase("ou=People,dc=james,dc=org") diff --git a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/LdapRepositoryConfiguration.java b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/LdapRepositoryConfiguration.java index 47a980958f0..8afd9b0089b 100644 --- a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/LdapRepositoryConfiguration.java +++ b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/LdapRepositoryConfiguration.java @@ -19,6 +19,7 @@ package org.apache.james.user.ldap; +import java.net.URI; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -30,8 +31,10 @@ import org.apache.james.core.Domain; import org.apache.james.core.Username; +import com.github.fge.lambdas.Throwing; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; public class LdapRepositoryConfiguration { @@ -46,7 +49,7 @@ public class LdapRepositoryConfiguration { private static final int DEFAULT_POOL_SIZE = 4; public static class Builder { - private Optional> ldapHosts; + private Optional> ldapHosts; private Optional principal; private Optional credentials; private Optional userBase; @@ -68,7 +71,7 @@ public Builder() { perDomainBaseDN = ImmutableMap.builder(); } - public Builder ldapHosts(List ldapHosts) { + public Builder ldapHosts(List ldapHosts) { this.ldapHosts = Optional.of(ldapHosts); return this; } @@ -145,10 +148,14 @@ public static Builder builder() { } public static LdapRepositoryConfiguration from(HierarchicalConfiguration configuration) throws ConfigurationException { - List ldapHosts = Splitter.on(",") + List ldapHosts = Splitter.on(",") .splitToList(Optional.ofNullable(configuration.getString("[@ldapHosts]", null)) .orElse(configuration.getString("[@ldapHost]", "")) - .trim()); + .trim()) + .stream() + .map(Throwing.function(URI::new)) + .collect(ImmutableList.toImmutableList()); + String principal = configuration.getString("[@principal]", ""); String credentials = configuration.getString("[@credentials]", ""); String userBase = configuration.getString("[@userBase]"); @@ -214,7 +221,7 @@ public static LdapRepositoryConfiguration from(HierarchicalConfiguration ldapHosts; + private final List ldapHosts; /** * The user with which to initially bind to the LDAP server. The value of @@ -286,7 +293,7 @@ public static LdapRepositoryConfiguration from(HierarchicalConfiguration perDomainBaseDN; - private LdapRepositoryConfiguration(List ldapHosts, String principal, String credentials, String userBase, String userIdAttribute, + private LdapRepositoryConfiguration(List ldapHosts, String principal, String credentials, String userBase, String userIdAttribute, String userObjectClass, int connectionTimeout, int readTimeout, boolean supportsVirtualHosting, int poolSize, ReadOnlyLDAPGroupRestriction restriction, String filter, Optional administratorId, boolean trustAllCerts, @@ -322,7 +329,7 @@ private void checkState() throws ConfigurationException { } } - public List getLdapHosts() { + public List getLdapHosts() { return ldapHosts; } diff --git a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java index b7c8dd1ae9c..d1c0fa5e20e 100644 --- a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java +++ b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java @@ -179,11 +179,8 @@ private SocketFactory supportLDAPS(URI uri) throws KeyManagementException, NoSuc } } - private ThrowingFunction toSingleServerSet(LDAPConnectionOptions connectionOptions, BindRequest bindRequest) { - return Throwing.function(uriString -> { - URI uri = new URI(uriString); - return new SingleServerSet(uri.getHost(), uri.getPort(), supportLDAPS(uri), connectionOptions, bindRequest, null); - }); + private ThrowingFunction toSingleServerSet(LDAPConnectionOptions connectionOptions, BindRequest bindRequest) { + return Throwing.function(uri -> new SingleServerSet(uri.getHost(), uri.getPort(), supportLDAPS(uri), connectionOptions, bindRequest, null)); } @PreDestroy