directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r664295 [5/5] - in /directory/apacheds/branches/bigbang: ./ apacheds-jdbm/src/examples/ apacheds-jdbm/src/main/java/jdbm/ apacheds-jdbm/src/main/java/jdbm/btree/ bootstrap-extract/src/main/java/org/apache/directory/server/schema/bootstrap/p...
Date Sat, 07 Jun 2008 07:48:20 GMT
Modified: directory/apacheds/branches/bigbang/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java
(original)
+++ directory/apacheds/branches/bigbang/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java
Sat Jun  7 00:48:16 2008
@@ -99,9 +99,9 @@
         {
             this.directoryService = new DefaultDirectoryService();
         }
-		else
-		{        
-        	this.directoryService = directoryService;
+        else
+        {        
+            this.directoryService = directoryService;
         }
         
         this.ldapServer = ldapServer;

Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
(original)
+++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
Sat Jun  7 00:48:16 2008
@@ -657,14 +657,11 @@
         if ( ldifReader.containsEntries() )
         {
             // Parse the file and inject every entry
-            Iterator<LdifEntry> entries = ldifReader.iterator();
             long t0 = System.currentTimeMillis();
             int nbAdd = 0;
 
-            while ( entries.hasNext() )
+            for ( LdifEntry entry:ldifReader )
             {
-                LdifEntry entry = entries.next();
-
                 // Check if we have had some error, has next() does not throw any exception
                 if ( ldifReader.hasError() )
                 {
@@ -709,14 +706,11 @@
         else
         {
             // Parse the file and inject every modification
-            Iterator<LdifEntry> entries = ldifReader.iterator();
             long t0 = System.currentTimeMillis();
             int nbMod = 0;
 
-            while ( entries.hasNext() )
+            for ( LdifEntry entry:ldifReader )
             {
-                LdifEntry entry = entries.next();
-
                 // Check if we have had some error, has next() does not throw any exception
                 if ( ldifReader.hasError() )
                 {

Modified: directory/apacheds/branches/bigbang/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/main/java/org/apache/directory/server/unit/AbstractServerTest.java
Sat Jun  7 00:48:16 2008
@@ -20,36 +20,51 @@
 package org.apache.directory.server.unit;
 
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.DefaultDirectoryService;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.jndi.CoreContextFactory;
 import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.ldap.handlers.bind.CramMd5MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.DigestMd5MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.GssapiMechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.SimpleMechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
 import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
 import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
-import org.apache.directory.server.ldap.handlers.bind.*;
-import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
 import org.apache.directory.server.protocol.shared.SocketAcceptor;
+import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
+import org.apache.directory.shared.ldap.exception.LdapConfigurationException;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
 import org.apache.mina.util.AvailablePortFinder;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.ldap.InitialLdapContext;
-import javax.naming.ldap.LdapContext;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.*;
 
 
@@ -126,9 +141,9 @@
         
         LdifReader ldifReader = new LdifReader( in );
         List<LdifEntry> entries = new ArrayList<LdifEntry>();
-        while ( ldifReader.hasNext() )
+
+        for ( LdifEntry entry:ldifReader )
         {
-            LdifEntry entry = ldifReader.next();
             rootDSE.createSubcontext( entry.getDn(), entry.getAttributes() );
             
             if ( verifyEntries )
@@ -170,7 +185,7 @@
                 if ( ! readAttribute.contains( origAttribute.get( ii ) ) )
                 {
                     LOG.error( "Failed to verify entry addition of {}. {} attribute in original
" +
-                    		"entry missing from read entry.", entry.getDn(), id );
+                            "entry missing from read entry.", entry.getDn(), id );
                     throw new AssertionFailedError( "Failed to verify entry addition of "
+ entry.getDn()  );
                 }
             }
@@ -266,7 +281,7 @@
     {
         Map<String, MechanismHandler> mechanismHandlerMap = new HashMap<String,MechanismHandler>();
 
-        mechanismHandlerMap.put( SupportedSaslMechanisms.SIMPLE, new SimpleMechanismHandler()
);
+        mechanismHandlerMap.put( SupportedSaslMechanisms.PLAIN, new SimpleMechanismHandler()
);
 
         CramMd5MechanismHandler cramMd5MechanismHandler = new CramMd5MechanismHandler();
         cramMd5MechanismHandler.setDirectoryService( directoryService );
@@ -400,7 +415,7 @@
         }
     }
 
-
+    
     /**
      * Imports the LDIF entries packaged with the Eve JNDI provider jar into
      * the newly created system partition to prime it up for operation.  Note
@@ -411,15 +426,22 @@
      * adding those entries to the system partition
      * @param in the input stream with the ldif
      */
-    protected void importLdif( InputStream in ) throws Exception
+    protected void importLdif( InputStream in ) throws NamingException
     {
-        Iterator<LdifEntry> iterator = new LdifReader( in );
-
-        while ( iterator.hasNext() )
+        try
+        {
+            for ( LdifEntry ldifEntry:new LdifReader( in ) )
+            {
+                LdapDN dn = new LdapDN( ldifEntry.getDn() );
+                rootDSE.createSubcontext( dn, ldifEntry.getAttributes() );
+            }
+        }
+        catch ( Exception e )
         {
-            LdifEntry entry = iterator.next();
-            LdapDN dn = new LdapDN( entry.getDn() );
-            rootDSE.createSubcontext( dn, entry.getAttributes() );
+            String msg = "failed while trying to parse system ldif file";
+            NamingException ne = new LdapConfigurationException( msg );
+            ne.setRootCause( e );
+            throw ne;
         }
     }
 

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java
Sat Jun  7 00:48:16 2008
@@ -33,9 +33,9 @@
 
 public class DITUtilitiesSP
 {
-	private static final Logger log = LoggerFactory.getLogger( DITUtilitiesSP.class );
-	
-	/**
+    private static final Logger log = LoggerFactory.getLogger( DITUtilitiesSP.class );
+    
+    /**
      * Recursively deletes a subtree including the apex given.
      * 
      * If you do not want to wait for the developers to implement the

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DeleteIllegalDNITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DeleteIllegalDNITest.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DeleteIllegalDNITest.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DeleteIllegalDNITest.java
Sat Jun  7 00:48:16 2008
@@ -60,11 +60,11 @@
         } 
         catch ( NamingException ne )
         {
-        	fail();
+            fail();
         }
         catch( Exception e )
         {
-        	fail();
+            fail();
         }
         
         try
@@ -73,18 +73,18 @@
             controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
             controls.setTimeLimit( 10 );
             
-        	NamingEnumeration<SearchResult> result = ctx.search( "ou=system", "(objectClass=*)",
controls );
+            NamingEnumeration<SearchResult> result = ctx.search( "ou=system", "(objectClass=*)",
controls );
 
             assertTrue( result.hasMore() ); 
         } 
         catch ( InvalidNameException ine ) 
         {
-        	fail();
+            fail();
             // Expected.
         } 
         catch ( NamingException ne )
         {
-        	fail();
+            fail();
         }
     }
 }

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java
Sat Jun  7 00:48:16 2008
@@ -48,6 +48,12 @@
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.PersistentSearchControl;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -86,6 +92,7 @@
     /**
      * Create context and a person entry.
      */
+    @Before
     public void setUp() throws Exception
     {
         super.setUp();
@@ -110,6 +117,7 @@
     /**
      * Remove person entry and close context.
      */
+    @After
     public void tearDown() throws Exception
     {
         try
@@ -128,6 +136,7 @@
     /**
      * Shows correct notifications for modify(4) changes.
      */
+    @Test
     public void testPsearchModify() throws Exception
     {
         PSearchListener listener = new PSearchListener();
@@ -162,6 +171,7 @@
     /**
      * Shows correct notifications for moddn(8) changes.
      */
+    @Test
     public void testPsearchModifyDn() throws Exception
     {
         PSearchListener listener = new PSearchListener();
@@ -194,6 +204,7 @@
     /**
      * Shows correct notifications for delete(2) changes.
      */
+    @Test
     public void testPsearchDelete() throws Exception
     {
         PSearchListener listener = new PSearchListener();
@@ -226,6 +237,7 @@
     /**
      * Shows correct notifications for add(1) changes.
      */
+    @Test
     public void testPsearchAdd() throws Exception
     {
         PSearchListener listener = new PSearchListener();
@@ -259,6 +271,7 @@
      * Shows correct notifications for modify(4) changes with returned 
      * EntryChangeControl.
      */
+    @Test
     public void testPsearchModifyWithEC() throws Exception
     {
         PersistentSearchControl control = new PersistentSearchControl();
@@ -295,6 +308,7 @@
      * Shows correct notifications for moddn(8) changes with returned 
      * EntryChangeControl.
      */
+    @Test
     public void testPsearchModifyDnWithEC() throws Exception
     {
         PersistentSearchControl control = new PersistentSearchControl();
@@ -332,6 +346,7 @@
      * Shows correct notifications for delete(2) changes with returned 
      * EntryChangeControl.
      */
+    @Test
     public void testPsearchDeleteWithEC() throws Exception
     {
         PersistentSearchControl control = new PersistentSearchControl();
@@ -368,6 +383,7 @@
      * Shows correct notifications for add(1) changes with returned 
      * EntryChangeControl.
      */
+    @Test
     public void testPsearchAddWithEC() throws Exception
     {
         PersistentSearchControl control = new PersistentSearchControl();
@@ -404,6 +420,7 @@
      * Shows correct notifications for only add(1) and modify(4) registered changes with
returned 
      * EntryChangeControl.
      */
+    @Test
     public void testPsearchAddModifyEnabledWithEC() throws Exception
     {
         PersistentSearchControl control = new PersistentSearchControl();
@@ -516,6 +533,7 @@
      * Shows notifications functioning with the JNDI notification API of the SUN
      * provider.
      */
+    @Test
     public void testPsearchUsingJndiNotifications() throws Exception
     {
         Hashtable<String, Object> env = new Hashtable<String, Object>();
@@ -554,7 +572,8 @@
     /**
      * Shows notifications functioning with the JNDI notification API of the SUN
      * provider.
-     */
+     *
+    @Test
     public void testPsearchAbandon() throws Exception
     {
         PersistentSearchControl control = new PersistentSearchControl();
@@ -584,7 +603,9 @@
         assertNotNull( listener.result );
         assertEquals( "cn=Jack Black", listener.result.getName() );
         assertEquals( listener.result.control.getChangeType(), ChangeType.ADD );
-        listener.result = null;
+        
+        listener = new PSearchListener( control );
+
         t = new Thread( listener );
         t.start();
 
@@ -602,6 +623,10 @@
 
         // there seems to be a race condition here
         // assertNull( listener.result );
+        assertNotNull( listener.result );
+        assertEquals( "cn=Jack Black", listener.result.getName() );
+        assertEquals( ChangeType.DELETE, listener.result.control.getChangeType() );
+        listener.result = null;
 
         // thread is still waiting for notifications try a modify
         ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, new AttributesImpl( "description",
PERSON_DESCRIPTION,
@@ -616,10 +641,10 @@
             }
         }
 
-        assertNotNull( listener.result );
-        assertEquals( RDN, listener.result.getName() );
-        assertEquals( listener.result.control.getChangeType(), ChangeType.MODIFY );
-    }
+        assertNull( listener.result );
+        //assertEquals( RDN, listener.result.getName() );
+        //assertEquals( listener.result.control.getChangeType(), ChangeType.MODIFY );
+    }*/
 
     class JndiNotificationListener implements NamespaceChangeListener, ObjectChangeListener
     {

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SaslBindITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SaslBindITest.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SaslBindITest.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SaslBindITest.java
Sat Jun  7 00:48:16 2008
@@ -20,6 +20,18 @@
 package org.apache.directory.server;
 
 
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.net.SocketClient;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
@@ -28,10 +40,10 @@
 import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
-import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmAuthenticationResult;
 import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
 import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmProvider;
 import org.apache.directory.server.unit.AbstractServerTest;
+import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.BindRequestImpl;
@@ -41,22 +53,14 @@
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector;
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
+import org.apache.mina.common.IoSession;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Set;
-
 
 /**
  * An {@link AbstractServerTest} testing SASL DIGEST-MD5 and CRAM-MD5
@@ -67,7 +71,6 @@
  */
 public class SaslBindITest extends AbstractServerTest
 {
-    private static final Logger LOG = LoggerFactory.getLogger( SaslBindITest.class );
     private DirContext ctx;
     private BogusNtlmProvider provider;
 
@@ -76,6 +79,7 @@
      * Set up a partition for EXAMPLE.COM and add a user to
      * test authentication with.
      */
+    @Before
     public void setUp() throws Exception
     {
         provider = new BogusNtlmProvider();
@@ -144,6 +148,7 @@
     /**
      * Tear down.
      */
+    @After
     public void tearDown() throws Exception
     {
         ctx.close();
@@ -191,13 +196,14 @@
     /**
      * Tests to make sure the server properly returns the supportedSASLMechanisms.
      */
+    @Test
     public void testSupportedSASLMechanisms()
     {
         try
         {
-            DirContext ctx = new InitialDirContext();
+            DirContext context = new InitialDirContext();
 
-            Attributes attrs = ctx.getAttributes( "ldap://localhost:" + port, new String[]
+            Attributes attrs = context.getAttributes( "ldap://localhost:" + port, new String[]
                 { "supportedSASLMechanisms" } );
 
             NamingEnumeration<? extends Attribute> answer = attrs.getAll();
@@ -207,7 +213,7 @@
             assertTrue( result.contains( SupportedSaslMechanisms.DIGEST_MD5 ) );
             assertTrue( result.contains( SupportedSaslMechanisms.CRAM_MD5 ) );
             assertTrue( result.contains( SupportedSaslMechanisms.NTLM ) );
-            assertTrue( result.contains( SupportedSaslMechanisms.SIMPLE ) );
+            assertTrue( result.contains( SupportedSaslMechanisms.PLAIN ) );
             assertTrue( result.contains( SupportedSaslMechanisms.GSS_SPNEGO ) );
         }
         catch ( NamingException e )
@@ -221,6 +227,7 @@
      * Tests to make sure we still have anonymous access to the RootDSE.  The
      * configuration for this testcase MUST disable anonymous access.
      */
+    @Test
     public void testAnonymousRootDSE()
     {
         try
@@ -229,12 +236,12 @@
             env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"
);
             env.put( Context.PROVIDER_URL, "ldap://localhost:" + port );
 
-            DirContext ctx = new InitialDirContext( env );
+            DirContext context = new InitialDirContext( env );
 
             String[] attrIDs =
                 { "vendorName" };
 
-            Attributes attrs = ctx.getAttributes( "", attrIDs );
+            Attributes attrs = context.getAttributes( "", attrIDs );
 
             String vendorName = null;
 
@@ -255,6 +262,7 @@
     /**
      * Tests to make sure binds below the RootDSE require authentication.
      */
+    @Test
     public void testAnonymousBelowRootDSE()
     {
         try
@@ -263,12 +271,12 @@
             env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"
);
             env.put( Context.PROVIDER_URL, "ldap://localhost:" + port );
 
-            DirContext ctx = new InitialDirContext( env );
+            DirContext context = new InitialDirContext( env );
 
             String[] attrIDs =
                 { "vendorName" };
 
-            ctx.getAttributes( "dc=example,dc=com", attrIDs );
+            context.getAttributes( "dc=example,dc=com", attrIDs );
 
             fail( "Should not have gotten here." );
         }
@@ -282,6 +290,7 @@
     /**
      * Tests to make sure SIMPLE binds below the RootDSE work.
      */
+    @Test
     public void testSimpleBindBelowRootDSE()
     {
         try
@@ -294,12 +303,12 @@
             env.put( Context.SECURITY_PRINCIPAL, "uid=hnelson,ou=users,dc=example,dc=com"
);
             env.put( Context.SECURITY_CREDENTIALS, "secret" );
 
-            DirContext ctx = new InitialDirContext( env );
+            DirContext context = new InitialDirContext( env );
 
             String[] attrIDs =
                 { "uid" };
 
-            Attributes attrs = ctx.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com",
attrIDs );
+            Attributes attrs = context.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com",
attrIDs );
 
             String uid = null;
 
@@ -320,6 +329,7 @@
     /**
      * Tests to make sure SIMPLE binds below the RootDSE fail if the password is bad.
      */
+    @Test
     public void testSimpleBindBadPassword()
     {
         try
@@ -332,12 +342,12 @@
             env.put( Context.SECURITY_PRINCIPAL, "uid=hnelson,ou=users,dc=example,dc=com"
);
             env.put( Context.SECURITY_CREDENTIALS, "badsecret" );
 
-            DirContext ctx = new InitialDirContext( env );
+            DirContext context = new InitialDirContext( env );
 
             String[] attrIDs =
                 { "uid" };
 
-            ctx.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );
+            context.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );
 
             fail( "Should not have gotten here." );
         }
@@ -351,6 +361,7 @@
     /**
      * Tests to make sure DIGEST-MD5 binds below the RootDSE work.
      */
+    @Test
     public void testSaslDigestMd5Bind() throws Exception
     {
         Hashtable<String, String> env = new Hashtable<String, String>();
@@ -367,12 +378,12 @@
         // Request privacy protection
         env.put( "javax.security.sasl.qop", "auth-conf" );
 
-        DirContext ctx = new InitialDirContext( env );
+        DirContext context = new InitialDirContext( env );
 
         String[] attrIDs =
             { "uid" };
 
-        Attributes attrs = ctx.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs
);
+        Attributes attrs = context.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com",
attrIDs );
 
         String uid = null;
 
@@ -388,6 +399,7 @@
     /**
      * Tests to make sure DIGEST-MD5 binds below the RootDSE fail if the realm is bad.
      */
+    @Test
     public void testSaslDigestMd5BindBadRealm()
     {
         try
@@ -406,12 +418,12 @@
             // Request privacy protection
             env.put( "javax.security.sasl.qop", "auth-conf" );
 
-            DirContext ctx = new InitialDirContext( env );
+            DirContext context = new InitialDirContext( env );
 
             String[] attrIDs =
                 { "uid" };
 
-            ctx.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );
+            context.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );
 
             fail( "Should have thrown exception." );
         }
@@ -425,6 +437,7 @@
     /**
      * Tests to make sure DIGEST-MD5 binds below the RootDSE fail if the password is bad.
      */
+    @Test
     public void testSaslDigestMd5BindBadPassword()
     {
         try
@@ -437,12 +450,12 @@
             env.put( Context.SECURITY_PRINCIPAL, "hnelson" );
             env.put( Context.SECURITY_CREDENTIALS, "badsecret" );
 
-            DirContext ctx = new InitialDirContext( env );
+            DirContext context = new InitialDirContext( env );
 
             String[] attrIDs =
                 { "uid" };
 
-            ctx.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );
+            context.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );
 
             fail( "Should have thrown exception." );
         }
@@ -456,6 +469,7 @@
     /**
      * Tests to make sure CRAM-MD5 binds below the RootDSE work.
      */
+    @Test
     public void testSaslCramMd5Bind()
     {
         try
@@ -468,12 +482,12 @@
             env.put( Context.SECURITY_PRINCIPAL, "hnelson" );
             env.put( Context.SECURITY_CREDENTIALS, "secret" );
 
-            DirContext ctx = new InitialDirContext( env );
+            DirContext context = new InitialDirContext( env );
 
             String[] attrIDs =
                 { "uid" };
 
-            Attributes attrs = ctx.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com",
attrIDs );
+            Attributes attrs = context.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com",
attrIDs );
 
             String uid = null;
 
@@ -494,6 +508,7 @@
     /**
      * Tests to make sure CRAM-MD5 binds below the RootDSE fail if the password is bad.
      */
+    @Test
     public void testSaslCramMd5BindBadPassword()
     {
         try
@@ -506,12 +521,12 @@
             env.put( Context.SECURITY_PRINCIPAL, "hnelson" );
             env.put( Context.SECURITY_CREDENTIALS, "badsecret" );
 
-            DirContext ctx = new InitialDirContext( env );
+            DirContext context = new InitialDirContext( env );
 
             String[] attrIDs =
                 { "uid" };
 
-            ctx.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );
+            context.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );
 
             fail( "Should have thrown exception." );
         }
@@ -525,6 +540,7 @@
     /**
      * Tests that the plumbing for NTLM bind works.
      */
+    @Test
     public void testNtlmBind() throws Exception
     {
         NtlmSaslBindClient client = new NtlmSaslBindClient( SupportedSaslMechanisms.NTLM
);
@@ -538,13 +554,13 @@
         assertEquals( 2, finalResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, finalResponse.getLdapResult().getResultCode()
);
         assertTrue( ArrayUtils.isEquals( "type3_test".getBytes(), provider.getType3Response()
) );
-        assertTrue( ArrayUtils.isEquals( "results".getBytes(), finalResponse.getServerSaslCreds()
) );
     }
 
 
     /**
      * Tests that the plumbing for NTLM bind works.
      */
+    @Test
     public void testGssSpnegoBind() throws Exception
     {
         NtlmSaslBindClient client = new NtlmSaslBindClient( SupportedSaslMechanisms.GSS_SPNEGO
);
@@ -558,7 +574,6 @@
         assertEquals( 2, finalResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, finalResponse.getLdapResult().getResultCode()
);
         assertTrue( ArrayUtils.isEquals( "type3_test".getBytes(), provider.getType3Response()
) );
-        assertTrue( ArrayUtils.isEquals( "results".getBytes(), finalResponse.getServerSaslCreds()
) );
     }
 
 
@@ -568,14 +583,14 @@
         private byte[] type3response;
         
         
-        public NtlmAuthenticationResult authenticate( byte[] type3response ) throws Exception
+        public boolean authenticate( IoSession session, byte[] type3response ) throws Exception
         {
             this.type3response = type3response;
-            return new NtlmAuthenticationResult( "results".getBytes(), true );
+            return true;
         }
 
 
-        public byte[] generateChallenge( byte[] type1reponse ) throws Exception
+        public byte[] generateChallenge( IoSession session, byte[] type1reponse ) throws
Exception
         {
             this.type1response = type1reponse;
             return "challenge".getBytes();
@@ -597,6 +612,8 @@
 
     class NtlmSaslBindClient extends SocketClient
     {
+        private final Logger LOG = LoggerFactory.getLogger( NtlmSaslBindClient.class );
+        
         private final String mechanism;
         
         

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
Sat Jun  7 00:48:16 2008
@@ -187,7 +187,7 @@
     {
         ctx.unbind( RDN );
         ctx.close();
-    	
+        
         ctx = null;
         super.tearDown();
     }
@@ -1036,7 +1036,7 @@
         }
         catch ( NamingException ne )
         {
-        	assertTrue( true );
+            assertTrue( true );
         }
     }
     
@@ -1158,4 +1158,23 @@
 
         result.close();
     }
+    
+    
+    /**
+     * Test for DIRSERVER-1183.
+     * 
+     * @see https://issues.apache.org/jira/browse/DIRSERVER-1183
+     * @throws Exception
+     */
+    public void testDIRSERVER_1183() throws Exception
+    {
+    	Attributes attrs = new AttributesImpl( "objectClass", "inetOrgPerson", true );
+    	attrs.get( "objectClass" ).add( "organizationalPerson" );
+    	attrs.get( "objectClass" ).add( "person" );
+    	attrs.put( "givenName", "Jim" );
+    	attrs.put( "sn", "Bean" );
+    	attrs.put( "cn", "\"Jim, Bean\"" );
+    	
+    	ctx.createSubcontext( "cn=\"Jim, Bean\"", attrs );
+    }
 }

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ssl/StartTlsITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ssl/StartTlsITest.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ssl/StartTlsITest.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ssl/StartTlsITest.java
Sat Jun  7 00:48:16 2008
@@ -20,10 +20,22 @@
 package org.apache.directory.server.ssl;
 
 
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.security.KeyStore;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.List;
 
 import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 import javax.naming.ldap.StartTlsRequest;
@@ -32,13 +44,13 @@
 import javax.net.ssl.SSLSession;
 
 import org.apache.directory.server.unit.AbstractServerTest;
-import org.apache.directory.shared.ldap.util.DummySSLSocketFactory;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
 /**
- * Test case for StartTls.
+ * Test case for StartTls.  
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -46,40 +58,166 @@
 public class StartTlsITest extends AbstractServerTest
 {
     private static final Logger LOG = LoggerFactory.getLogger( StartTlsITest.class );
+    private static final int CONNECT_ITERATIONS = 10;
+    private static final boolean VERBOSE = false;
+    private File ksFile;
+    
+    
+    /**
+     * Sets up the key store and installs the self signed certificate for the 
+     * server (created on first startup) which is to be used by the StartTLS 
+     * JDNDI client that will connect.  The key store is created from scratch
+     * programmatically and whipped on each run.  The certificate is acquired 
+     * by pulling down the bytes for administrator's userCertificate from 
+     * uid=admin,ou=system.
+     */
+    public void setUp() throws Exception
+    {
+    	super.setUp();
+    	
+    	if ( ksFile != null && ksFile.exists() )
+    	{
+    		ksFile.delete();
+    	}
+    	
+    	ksFile = File.createTempFile( "testStore", "ks" );
+
+    	Hashtable<String, Object> env = new Hashtable<String,Object>();
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+        env.put( "java.naming.security.credentials", "secret" );
+        env.put( "java.naming.security.authentication", "simple" );
+        
+        // Must use the name of the server that is found in its certificate?
+        env.put( Context.PROVIDER_URL, "ldap://localhost:" + port + "/ou=system" );
+        LdapContext ctx = new InitialLdapContext( env, null );
+
+        Attributes adminEntry = ctx.getAttributes( "uid=admin" );
+    	Attribute userCertificateAttr = adminEntry.get( "userCertificate" );
+    	
+    	assertNotNull( userCertificateAttr );
+    	byte[] userCertificate = ( byte[] ) userCertificateAttr.get();
+    	assertNotNull( userCertificate );
+    	ByteArrayInputStream in = new ByteArrayInputStream( userCertificate );
+    	
+    	CertificateFactory factory = CertificateFactory.getInstance( "X.509" );
+    	Certificate cert = factory.generateCertificate( in );
+    	KeyStore ks = KeyStore.getInstance( KeyStore.getDefaultType() );
+    	ks.load( null, null );
+    	ks.setCertificateEntry( "apacheds", cert );
+    	ks.store( new FileOutputStream( ksFile ), "changeit".toCharArray() );
+    	
+    	ctx.close();
+    	ctx = null;
+    	env = null;
+    }
+    
+    
+    /**
+     * Just deletes the generated key store file.
+     */
+    public void tearDown() throws Exception
+    {
+    	if ( ksFile != null && ksFile.exists() )
+    	{
+    		ksFile.delete();
+    	}
+    	
+    	super.tearDown();
+    }
+    
+    
+    private void search( int ii, LdapContext securedContext ) throws Exception
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+    	
+    	if ( VERBOSE )
+    	{
+    		System.out.println( "Searching on " + ii + "-th iteration:" );
+    	}
+    	
+    	List<String> results = new ArrayList<String>();
+        NamingEnumeration<SearchResult> ne = securedContext.search( "ou=system", "(objectClass=*)",
controls );
+        while ( ne.hasMore() )
+        {
+        	String dn = ne.next().getNameInNamespace();
+        	results.add( dn );
+        	
+        	if ( VERBOSE )
+        	{
+        		System.out.println( "\tSearch Result = " + dn );
+        	}
+        }
+        ne.close();
+        
+    	assertEquals( "ou=system", results.get( 0 ) );
+    	assertEquals( "uid=admin,ou=system", results.get( 1 ) );
+    	assertEquals( "ou=users,ou=system", results.get( 2 ) );
+    	assertEquals( "ou=groups,ou=system", results.get( 3 ) );
+    	assertEquals( "cn=Administrators,ou=groups,ou=system", results.get( 4 ) );
+    	assertEquals( "ou=configuration,ou=system", results.get( 5 ) );
+    	assertEquals( "ou=partitions,ou=configuration,ou=system", results.get( 6 ) );
+    	assertEquals( "ou=services,ou=configuration,ou=system", results.get( 7 ) );
+    	assertEquals( "ou=interceptors,ou=configuration,ou=system", results.get( 8 ) );
+    	assertEquals( "prefNodeName=sysPrefRoot,ou=system", results.get( 9 ) );
+    }
     
     
+    /**
+     * Tests StartTLS by creating a JNDI connection using the generated key 
+     * store with the installed self signed certificate.  It then searches 
+     * the server and verifies the presence of the expected entries and closes
+     * the connection.  This process repeats for a number of iterations.  
+     * Modify the CONNECT_ITERATIONS constant to change the number of 
+     * iterations.  Modify the VERBOSE constant to print out information while
+     * performing searches.
+     */
     public void testStartTls() throws Exception
     {
-//        // Set up environment for creating initial context
-//        Hashtable<String, Object> env = new Hashtable<String,Object>();
-//        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
-//        env.put( "java.naming.ldap.factory.socket", DummySSLSocketFactory.class.getName()
);
-//        
-//        // Must use the name of the server that is found in its certificate
-//        env.put( Context.PROVIDER_URL, "ldap://localhost:" + port );
-//
-//        // Create initial context
-//        LOG.error( "About to get initial context" );
-//        LdapContext ctx = new InitialLdapContext( env, null );
-//
-//        // Start TLS
-//        LOG.error( "About send startTls extended operation" );
-//        StartTlsResponse tls = ( StartTlsResponse ) ctx.extendedOperation( new StartTlsRequest()
);
-//        LOG.error( "Extended operation issued" );
-//        tls.setHostnameVerifier( new HostnameVerifier() {
-//            public boolean verify( String hostname, SSLSession session )
-//            {
-//                return true;
-//            } 
-//        } );
-//        LOG.error( "TLS negotion about to begin" );
-//        SSLSession session = tls.negotiate( new DummySSLSocketFactory() );
-//        
-//        ctx.addToEnvironment( "java.naming.security.principal", "uid=admin,ou=system" );
-//        ctx.addToEnvironment( "java.naming.security.credentials", "secret" );
-//        ctx.addToEnvironment( "java.naming.security.authentication", "simple" );
-//
-//        Attributes attrs = ctx.getAttributes( "ou=system" ); 
-//        System.out.println( attrs.toString() );
+    	for ( int ii = 0; ii < CONNECT_ITERATIONS; ii++ )
+    	{
+        	if ( VERBOSE )
+        	{
+        		System.out.println( "Performing " + ii + "-th iteration to connect via StartTLS."
);
+        	}
+
+        	System.setProperty ( "javax.net.ssl.trustStore", ksFile.getAbsolutePath() );
+	    	System.setProperty ( "javax.net.ssl.keyStore", ksFile.getAbsolutePath() );
+	    	System.setProperty ( "javax.net.ssl.keyStorePassword", "changeit" );
+	    	LOG.debug( "testStartTls() test starting ... " );
+	    	
+	    	// Set up environment for creating initial context
+	    	Hashtable<String, Object> env = new Hashtable<String,Object>();
+	        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
+	        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+	        env.put( "java.naming.security.credentials", "secret" );
+	        env.put( "java.naming.security.authentication", "simple" );
+	        
+	        // Must use the name of the server that is found in its certificate?
+	        env.put( Context.PROVIDER_URL, "ldap://localhost:" + port );
+	
+	        // Create initial context
+	        LOG.debug( "About to get initial context" );
+	        LdapContext ctx = new InitialLdapContext( env, null );
+	
+	        // Start TLS
+	        LOG.debug( "About send startTls extended operation" );
+	        StartTlsResponse tls = ( StartTlsResponse ) ctx.extendedOperation( new StartTlsRequest()
);
+	        LOG.debug( "Extended operation issued" );
+	        tls.setHostnameVerifier( new HostnameVerifier() {
+	            public boolean verify( String hostname, SSLSession session )
+	            {
+	                return true;
+	            } 
+	        } );
+	        LOG.debug( "TLS negotion about to begin" );
+	        tls.negotiate();
+
+	        search( ii, ctx );
+	        
+	        tls.close();
+	        ctx.close();
+    	}
     }
 }

Modified: directory/apacheds/branches/bigbang/utils/src/main/java/org/apache/directory/server/utils/AttributesFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/utils/src/main/java/org/apache/directory/server/utils/AttributesFactory.java?rev=664295&r1=664294&r2=664295&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/utils/src/main/java/org/apache/directory/server/utils/AttributesFactory.java
(original)
+++ directory/apacheds/branches/bigbang/utils/src/main/java/org/apache/directory/server/utils/AttributesFactory.java
Sat Jun  7 00:48:16 2008
@@ -421,7 +421,7 @@
     
     private final void injectCommon( SchemaObject object, ServerEntry entry, Registries registries
) throws NamingException
     {
-        injectNames( object.getNames(), entry, registries );
+        injectNames( object.getNamesRef(), entry, registries );
         entry.put( MetaSchemaConstants.M_OBSOLETE_AT, getBoolean( object.isObsolete() ) );
         entry.put( MetaSchemaConstants.M_OID_AT, object.getOid() );
         



Mime
View raw message