You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/06/30 03:25:01 UTC

[4/5] james-project git commit: JAMES-2070 LDAP users repository should survive restarts

JAMES-2070 LDAP users repository should survive restarts


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/67629712
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/67629712
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/67629712

Branch: refs/heads/master
Commit: 67629712e3780a3dcaecd43882b4de6a879cf336
Parents: eca1bbf
Author: benwa <bt...@linagora.com>
Authored: Tue Jun 27 10:33:28 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Jun 30 10:15:45 2017 +0700

----------------------------------------------------------------------
 .../util/retry/naming/RetryingContext.java      |  4 +++-
 .../ldap/ReadOnlyUsersLDAPRepositoryTest.java   | 22 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/67629712/server/container/util/src/main/java/org/apache/james/util/retry/naming/RetryingContext.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/main/java/org/apache/james/util/retry/naming/RetryingContext.java b/server/container/util/src/main/java/org/apache/james/util/retry/naming/RetryingContext.java
index f355209..e67d366 100644
--- a/server/container/util/src/main/java/org/apache/james/util/retry/naming/RetryingContext.java
+++ b/server/container/util/src/main/java/org/apache/james/util/retry/naming/RetryingContext.java
@@ -30,6 +30,7 @@ import javax.naming.NameClassPair;
 import javax.naming.NameParser;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
 import javax.naming.ServiceUnavailableException;
 
 import org.apache.james.util.retry.api.ExceptionRetryingProxy;
@@ -48,7 +49,8 @@ abstract public class RetryingContext implements Context, ExceptionRetryingProxy
 
     static public final Class<?>[] DEFAULT_EXCEPTION_CLASSES = new Class<?>[] {
             CommunicationException.class,
-            ServiceUnavailableException.class };
+            ServiceUnavailableException.class,
+            NoInitialContextException.class };
 
     private Context _delegate = null;
     private RetrySchedule _schedule = null;

http://git-wip-us.apache.org/repos/asf/james-project/blob/67629712/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
index 17b7ad8..cfc810d 100644
--- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
+++ b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
@@ -46,6 +46,10 @@ public class ReadOnlyUsersLDAPRepositoryTest {
 
     @Before
     public void setup() throws Exception {
+        startLdapContainer();
+    }
+
+    private void startLdapContainer() {
         ldapContainer = LdapGenericContainer.builder()
                 .domain(DOMAIN)
                 .password(ADMIN_PASSWORD)
@@ -121,6 +125,7 @@ public class ReadOnlyUsersLDAPRepositoryTest {
         startUsersRepository(ldapRepositoryConfiguration());
         assertThat(ldapRepository.test(UNKNOWN, PASSWORD)).isFalse();
     }
+
     @Test
     public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrectWithVirtualHosting() throws Exception {
         startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
@@ -128,6 +133,23 @@ public class ReadOnlyUsersLDAPRepositoryTest {
     }
 
     @Test
+    public void testShouldStillWorksAfterRestartingLDAP() throws Exception {
+        startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
+        ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
+
+        ldapContainer.stop();
+        try {
+            ldapRepository.test(JAMES_USER_MAIL, PASSWORD);
+        } catch (Exception e) {
+            LOGGER.info("This exception is expected as we shut down the LDAP and forced its use", e);
+        }
+        startLdapContainer();
+
+        assertThat(ldapRepository.test(JAMES_USER_MAIL, PASSWORD)).isTrue();
+    }
+
+
+    @Test
     public void knownUserShouldNotBeAbleToLogInWhenPasswordIsNotCorrectWithVirtualHosting() throws Exception {
         startUsersRepository(ldapRepositoryConfigurationWithVirtualHosting());
         assertThat(ldapRepository.test(JAMES_USER, BAD_PASSWORD)).isFalse();


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org