You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2020/05/22 04:42:54 UTC

[directory-server] branch master updated: Fix: Insert interceptor after the one with the given name

This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-server.git


The following commit(s) were added to refs/heads/master by this push:
     new c135031  Fix: Insert interceptor after the one with the given name
     new 7cda287  Merge pull request #37 from christopher-cudennec/fix-default-directory-service
c135031 is described below

commit c135031fc6953030b0df2796405108848a46b9db
Author: Christopher Cudennec <ch...@sda-se.com>
AuthorDate: Mon May 11 13:19:11 2020 +0200

    Fix: Insert interceptor after the one with the given name
---
 .../server/core/DefaultDirectoryService.java       |  2 +-
 .../server/core/DefaultDirectoryServiceTest.java   | 53 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java b/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
index f42c3c5..3edf779 100644
--- a/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
+++ b/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
@@ -2248,7 +2248,7 @@ public class DefaultDirectoryService implements DirectoryService
             }
             else
             {
-                interceptors.add( position, interceptor );
+                interceptors.add( position + 1, interceptor );
             }
         }
         finally
diff --git a/core/src/test/java/org/apache/directory/server/core/DefaultDirectoryServiceTest.java b/core/src/test/java/org/apache/directory/server/core/DefaultDirectoryServiceTest.java
new file mode 100644
index 0000000..34f9a78
--- /dev/null
+++ b/core/src/test/java/org/apache/directory/server/core/DefaultDirectoryServiceTest.java
@@ -0,0 +1,53 @@
+package org.apache.directory.server.core;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.server.core.api.InterceptorEnum;
+import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.api.interceptor.Interceptor;
+import org.junit.Test;
+
+public class DefaultDirectoryServiceTest {
+
+  @Test
+  public void testAddAfterExistingInterceptor() throws LdapException {
+    // given
+    final String existingInterceptorName = InterceptorEnum.AUTHENTICATION_INTERCEPTOR.getName();
+    DefaultDirectoryService service = new DefaultDirectoryService();
+
+    // when
+    service.addAfter(existingInterceptorName, new FooInterceptor());
+
+    // then
+    for (int i = 0; i < service.getInterceptors().size(); i++) {
+      Interceptor interceptor = service.getInterceptors().get(i);
+      if (existingInterceptorName.equals(interceptor.getName())) {
+        final Interceptor nextInterceptor = service.getInterceptors().get(i + 1);
+        assertEquals("foo", nextInterceptor.getName());
+      }
+    }
+  }
+
+  @Test
+  public void testAddAfterForUnknownPredecessor() throws LdapException {
+    // given
+    DefaultDirectoryService service = new DefaultDirectoryService();
+
+    // when
+    service.addAfter("-unknown-", new FooInterceptor());
+
+    // then
+    final Interceptor lastInterceptor = service.getInterceptors()
+        .get(service.getInterceptors().size() - 1);
+    assertEquals("foo", lastInterceptor.getName());
+  }
+
+  static class FooInterceptor extends BaseInterceptor {
+
+    @Override
+    public String getName() {
+      return "foo";
+    }
+  }
+}
\ No newline at end of file