Repository: james-project Updated Branches: refs/heads/master c4d797e0d -> 42b574dcb
JAMES-1940 LDAP UsersRepository should offer to configure virtualHosting Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/42b574dc Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/42b574dc Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/42b574dc Branch: refs/heads/master Commit: 42b574dcb7c2b6044670af9f944fb825f6314197 Parents: c4d797e Author: Benoit Tellier <[email protected]> Authored: Tue Feb 14 08:51:03 2017 +0700 Committer: Benoit Tellier <[email protected]> Committed: Tue Feb 14 08:51:03 2017 +0700 ---------------------------------------------------------------------- server/data/data-ldap/pom.xml | 5 + .../user/ldap/ReadOnlyUsersLDAPRepository.java | 5 +- .../ldap/ReadOnlyUsersLDAPRepositoryTest.java | 102 +++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/42b574dc/server/data/data-ldap/pom.xml ---------------------------------------------------------------------- diff --git a/server/data/data-ldap/pom.xml b/server/data/data-ldap/pom.xml index bd711b5..cecdec7 100644 --- a/server/data/data-ldap/pom.xml +++ b/server/data/data-ldap/pom.xml @@ -63,6 +63,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>${assertj-1.version}</version> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/42b574dc/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java ---------------------------------------------------------------------- diff --git a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java index 056aa8b..6e07236 100644 --- a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java +++ b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java @@ -228,6 +228,7 @@ public class ReadOnlyUsersLDAPRepository implements UsersRepository, Configurabl private static final String PROPERTY_NAME_CONNECTION_POOL = "com.sun.jndi.ldap.connect.pool"; private static final String PROPERTY_NAME_CONNECT_TIMEOUT = "com.sun.jndi.ldap.connect.timeout"; private static final String PROPERTY_NAME_READ_TIMEOUT = "com.sun.jndi.ldap.read.timeout"; + public static final String SUPPORTS_VIRTUAL_HOSTING = "supportsVirtualHosting"; /** * The URL of the LDAP server against which users are to be authenticated. @@ -293,6 +294,7 @@ public class ReadOnlyUsersLDAPRepository implements UsersRepository, Configurabl * "principal" and "credentials". */ private LdapContext ldapContext; + private boolean supportsVirtualHosting; // Use a connection pool. Default is true. private boolean useConnectionPool = true; @@ -345,6 +347,7 @@ public class ReadOnlyUsersLDAPRepository implements UsersRepository, Configurabl // Default maximum retries is 1, which allows an alternate connection to // be found in a multi-homed environment maxRetries = configuration.getInt("[@maxRetries]", 1); + supportsVirtualHosting = configuration.getBoolean(SUPPORTS_VIRTUAL_HOSTING, false); // Default retry start interval is 0 second long retryStartInterval = configuration.getLong("[@retryStartInterval]", 0); // Default maximum retry interval is 60 seconds @@ -759,7 +762,7 @@ public class ReadOnlyUsersLDAPRepository implements UsersRepository, Configurabl * VirtualHosting not supported */ public boolean supportVirtualHosting() { - return false; + return supportsVirtualHosting; } http://git-wip-us.apache.org/repos/asf/james-project/blob/42b574dc/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java new file mode 100644 index 0000000..1457122 --- /dev/null +++ b/server/data/data-ldap/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java @@ -0,0 +1,102 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you 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 org.apache.james.user.ldap; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.ConversionException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.commons.configuration.plist.PropertyListConfiguration; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ReadOnlyUsersLDAPRepositoryTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(ReadOnlyUsersLDAPRepositoryTest.class); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void supportVirtualHostingShouldReturnFalseByDefault() throws Exception { + ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(); + usersLDAPRepository.setLog(LOGGER); + usersLDAPRepository.configure(ldapRepositoryConfiguration()); + + assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse(); + } + + @Test + public void supportVirtualHostingShouldReturnTrueWhenReportedInConfig() throws Exception { + HierarchicalConfiguration configuration = ldapRepositoryConfiguration(); + configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "true"); + + ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(); + usersLDAPRepository.setLog(LOGGER); + usersLDAPRepository.configure(configuration); + + assertThat(usersLDAPRepository.supportVirtualHosting()).isTrue(); + } + + @Test + public void supportVirtualHostingShouldReturnFalseWhenReportedInConfig() throws Exception { + HierarchicalConfiguration configuration = ldapRepositoryConfiguration(); + configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "false"); + + ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(); + usersLDAPRepository.setLog(LOGGER); + usersLDAPRepository.configure(configuration); + + assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse(); + } + + @Test + public void configureShouldThrowOnNonBooleanValueForSupportsVirtualHosting() throws Exception { + HierarchicalConfiguration configuration = ldapRepositoryConfiguration(); + configuration.addProperty(ReadOnlyUsersLDAPRepository.SUPPORTS_VIRTUAL_HOSTING, "bad"); + + ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(); + usersLDAPRepository.setLog(LOGGER); + + expectedException.expect(ConversionException.class); + + usersLDAPRepository.configure(configuration); + } + + private HierarchicalConfiguration ldapRepositoryConfiguration() throws ConfigurationException { + PropertyListConfiguration configuration = new PropertyListConfiguration(); + configuration.addProperty("[@ldapHost]", "ldap://127.0.0.1"); + configuration.addProperty("[@principal]", "cn=admin\\,dc=james\\,dc=org"); + configuration.addProperty("[@credentials]", "secret"); + configuration.addProperty("[@userBase]", "ou=People\\,dc=james\\,dc=org"); + configuration.addProperty("[@userIdAttribute]", "uid"); + configuration.addProperty("[@userObjectClass]", "inetOrgPerson"); + configuration.addProperty("[@maxRetries]", "4"); + configuration.addProperty("[@retryStartInterval]", "0"); + configuration.addProperty("[@retryMaxInterval]", "8"); + configuration.addProperty("[@retryIntervalScale]", "1000"); + return configuration; + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
