directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1479610 - in /directory/apacheds/trunk/core-annotations/src: main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
Date Mon, 06 May 2013 15:45:35 GMT
Author: elecharny
Date: Mon May  6 15:45:35 2013
New Revision: 1479610

URL: http://svn.apache.org/r1479610
Log:
Applied patch for DIRSERVER-1730

Modified:
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
    directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java?rev=1479610&r1=1479609&r2=1479610&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
Mon May  6 15:45:35 2013
@@ -128,6 +128,9 @@ public class DSAnnotationProcessor
 
                 authenticators.add( auth );
             }
+
+            authenticationInterceptor.setAuthenticators( authenticators );
+            authenticationInterceptor.init( service );
         }
 
         service.setInterceptors( interceptorList );

Modified: directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java?rev=1479610&r1=1479609&r2=1479610&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
Mon May  6 15:45:35 2013
@@ -28,13 +28,22 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.directory.api.ldap.model.constants.AuthenticationLevel;
+import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.server.core.annotations.ContextEntry;
+import org.apache.directory.server.core.annotations.CreateAuthenticator;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.annotations.CreateIndex;
 import org.apache.directory.server.core.annotations.CreatePartition;
 import org.apache.directory.server.core.annotations.LoadSchema;
 import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.LdapPrincipal;
+import org.apache.directory.server.core.api.interceptor.Interceptor;
+import org.apache.directory.server.core.api.interceptor.context.BindOperationContext;
 import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.authn.AbstractAuthenticator;
+import org.apache.directory.server.core.authn.AuthenticationInterceptor;
+import org.apache.directory.server.core.authn.Authenticator;
 import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 import org.junit.Test;
 
@@ -182,4 +191,63 @@ public class DirectoryServiceAnnotationT
         FileUtils.deleteDirectory( service.getInstanceLayout().getInstanceDirectory() );
     }
 
+
+    @Test
+    @CreateDS(
+        name = "MethodDSWithAuthenticator",
+        authenticators =
+            { @CreateAuthenticator(type = DummyAuthenticator.class) })
+    public void testCustomAuthenticator() throws Exception
+    {
+        final DirectoryService service = DSAnnotationProcessor.getDirectoryService();
+        assertTrue( service.isStarted() );
+        assertEquals( "MethodDSWithAuthenticator", service.getInstanceId() );
+        final Set<Authenticator> authenticators = findAuthInterceptor( service ).getAuthenticators();
+        assertEquals(
+            "Expected interceptor to be configured with only one authenticator",
+            1,
+            authenticators.size() );
+        assertEquals(
+            "Expected the only interceptor to be the dummy interceptor",
+            DummyAuthenticator.class,
+            authenticators.iterator().next().getClass() );
+        service.getSession( new Dn( "uid=non-existant-user,ou=system" ), "wrong-password".getBytes()
);
+        assertTrue( "Expedted dummy authenticator to have been invoked", dummyAuthenticatorCalled
);
+        service.shutdown();
+        FileUtils.deleteDirectory( service.getInstanceLayout().getInstanceDirectory() );
+    }
+
+    private static volatile boolean dummyAuthenticatorCalled = false;
+
+    private static class DummyAuthenticator extends AbstractAuthenticator
+    {
+        protected DummyAuthenticator()
+        {
+            super( AuthenticationLevel.SIMPLE );
+        }
+
+
+        @Override
+        public LdapPrincipal authenticate( BindOperationContext ctx ) throws Exception
+        {
+            dummyAuthenticatorCalled = true;
+            return new LdapPrincipal(
+                super.getDirectoryService().getSchemaManager(),
+                ctx.getDn(),
+                AuthenticationLevel.SIMPLE );
+        }
+    }
+
+
+    private static AuthenticationInterceptor findAuthInterceptor( DirectoryService service
)
+    {
+        for ( Interceptor interceptor : service.getInterceptors() )
+        {
+            if ( interceptor instanceof AuthenticationInterceptor )
+            {
+                return ( AuthenticationInterceptor ) interceptor;
+            }
+        }
+        return null;
+    }
 }



Mime
View raw message