directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r190361 - in /directory/apacheds/branches/direve-158/main/src: main/java/org/apache/ldap/server/jndi/ServerContextFactory.java test/org/apache/ldap/server/AbstractServerTest.java test/org/apache/ldap/server/DisableAnonBindTest.java test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java
Date Mon, 13 Jun 2005 06:45:36 GMT
Author: trustin
Date: Sun Jun 12 23:45:35 2005
New Revision: 190361

URL: http://svn.apache.org/viewcvs?rev=190361&view=rev
Log:
Caught up with the recent changes in core

Modified:
    directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
    directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java
    directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
    directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java

Modified: directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java?rev=190361&r1=190360&r2=190361&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
(original)
+++ directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
Sun Jun 12 23:45:35 2005
@@ -65,106 +65,48 @@
     // Members
     // ------------------------------------------------------------------------
 
-
-    /**
-     * Checks first for a shutdown operation and if so stops the server.  Otherwise
-     * it initializes the networking subsystem starting up the mina registery and
-     * other protocol provider services if enabled including the LDAP provider.
-     *
-     * @param env the JNDI environment parameters
-     * @return the new LDAP context to be wrapped by InitialContext
-     * @throws NamingException if there are problems starting or stopping the server
-     */
-    public Context getInitialContext( Hashtable env ) throws NamingException
+    protected void afterShutdown( ContextFactoryContext ctx )
     {
-        Context ctx = null;
-        Configuration cfg0 = Configuration.toConfiguration( env );
-        if ( cfg0 instanceof ShutdownConfiguration )
+        if ( minaRegistry != null )
         {
-            if ( this.provider == null )
+            if ( ldapService != null )
             {
-                return new DeadContext();
+                minaRegistry.unbind( ldapService );
+                ldapService = null;
             }
 
-            try
-            {
-                this.provider.shutdown();
-
-                if ( minaRegistry != null )
-                {
-                    if ( ldapService != null )
-                    {
-                        minaRegistry.unbind( ldapService );
-                        ldapService = null;
-                    }
-
-                    if ( kerberosService != null )
-                    {
-                        minaRegistry.unbind( kerberosService );
-                        kerberosService = null;
-                    }
-                }
-            }
-            catch( NamingException ne )
-            {
-                throw ne;
-            }
-            catch( Throwable t )
+            if ( kerberosService != null )
             {
-                NamingException ne = new NamingException( "Failed to shutdown." );
-                ne.setRootCause( t );
-                throw ne;
+                minaRegistry.unbind( kerberosService );
+                kerberosService = null;
             }
-            finally
-            {
-                ctx = new DeadContext();
-                provider = null;
-                initialEnv = null;
-                configuration = null;
-            }
-
-            return ctx;
         }
+    }
+    
+    protected void afterStartup( ContextFactoryContext ctx ) throws NamingException
+    {
+        ServerStartupConfiguration cfg =
+            ( ServerStartupConfiguration ) ctx.getConfiguration();
+        Hashtable env = ctx.getEnvironment();
 
-        boolean firstRun = provider == null;
-        ctx = super.getInitialContext( env );
-
-        // fire up the front end if we have not explicitly disabled it
-        if( ctx == null || ctx instanceof DeadContext ||
-                !( cfg0 instanceof ServerStartupConfiguration ) )
+        if ( cfg.isEnableNetworking() )
         {
-            return ctx;
-        }
-        
-        if( firstRun )
-        {
-            ServerStartupConfiguration cfg =
-                ( ServerStartupConfiguration ) cfg0;
-            if ( cfg.isEnableNetworking() )
-            {
-                setupRegistry();
-                startLdapProtocol();
+            setupRegistry( cfg );
+            startLdapProtocol( cfg, env );
 
-                if ( cfg.isEnableKerberos() )
-                {
-                    startKerberosProtocol();
-                }
+            if ( cfg.isEnableKerberos() )
+            {
+                startKerberosProtocol( env );
             }
         }
-
-        return ctx;
     }
 
-
     /**
      * Starts up the MINA registry so various protocol providers can be started.
      */
-    private void setupRegistry()
+    private void setupRegistry( ServerStartupConfiguration cfg )
     {
-        ServerStartupConfiguration configuration =
-            ( ServerStartupConfiguration ) this.configuration;
-
-        minaRegistry = configuration.getMinaServiceRegistry();
+        minaRegistry = cfg.getMinaServiceRegistry();
     }
 
 
@@ -173,7 +115,7 @@
      *
      * @throws NamingException if there are problems starting up the Kerberos provider
      */
-    private void startKerberosProtocol() throws NamingException
+    private void startKerberosProtocol( Hashtable env ) throws NamingException
     {
         /*
          * Looks like KdcConfiguration takes properties and we use Hashtable for JNDI
@@ -181,26 +123,24 @@
          */
 
         Properties props = new Properties();
-
-        Iterator list = initialEnv.keySet().iterator();
-
+        Iterator list = env.keySet().iterator();
         while ( list.hasNext() )
         {
             String key = ( String ) list.next();
 
-            if ( initialEnv.get( key ) instanceof String )
+            if ( env.get( key ) instanceof String )
             {
-                props.setProperty( key, ( String ) initialEnv.get( key ) );
+                props.setProperty( key, ( String ) env.get( key ) );
             }
         }
 
         KdcConfiguration config = new KdcConfiguration( props );
 
-        int port = PropertiesUtils.get( initialEnv, KdcConfiguration.KERBEROS_PORT_KEY, KdcConfiguration.DEFAULT_KERBEROS_PORT
);
+        int port = PropertiesUtils.get( env, KdcConfiguration.KERBEROS_PORT_KEY, KdcConfiguration.DEFAULT_KERBEROS_PORT
);
 
         Service service= new Service( "kerberos", TransportType.DATAGRAM, new InetSocketAddress(
port ) );
 
-        InitialLdapContext ctx = new InitialLdapContext( initialEnv, new Control[]{} );
+        InitialLdapContext ctx = new InitialLdapContext( env, new Control[]{} );
 
         PrincipalStore store = new JndiPrincipalStoreImpl( ctx, new LdapName( "ou=Users"
) );
 
@@ -222,17 +162,15 @@
      *
      * @throws NamingException if there are problems starting the LDAP provider
      */
-    private void startLdapProtocol() throws NamingException
+    private void startLdapProtocol( ServerStartupConfiguration cfg, Hashtable env ) throws
NamingException
     {
-        ServerStartupConfiguration configuration =
-            ( ServerStartupConfiguration ) this.configuration;
-        int port = configuration.getLdapPort();
+        int port = cfg.getLdapPort();
 
         Service service = new Service( "ldap", TransportType.SOCKET, new InetSocketAddress(
port ) );
 
         try
         {
-            minaRegistry.bind( service, new LdapProtocolProvider( ( Hashtable ) initialEnv.clone()
) );
+            minaRegistry.bind( service, new LdapProtocolProvider( ( Hashtable ) env.clone()
) );
 
             ldapService = service;
         }

Modified: directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java?rev=190361&r1=190360&r2=190361&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java
(original)
+++ directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java
Sun Jun 12 23:45:35 2005
@@ -41,6 +41,7 @@
 import org.apache.ldap.common.name.LdapName;
 import org.apache.ldap.server.configuration.MutableServerStartupConfiguration;
 import org.apache.ldap.server.configuration.ShutdownConfiguration;
+import org.apache.ldap.server.jndi.ServerContextFactory;
 import org.apache.mina.util.AvailablePortFinder;
 
 
@@ -114,8 +115,8 @@
         Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
 
         env.put( Context.SECURITY_PRINCIPAL, user );
-
         env.put( Context.SECURITY_CREDENTIALS, passwd );
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
 
         return setSysRoot( env );
     }
@@ -134,7 +135,7 @@
     {
         Hashtable envFinal = new Hashtable( env );
         envFinal.put( Context.PROVIDER_URL, "ou=system" );
-        envFinal.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory"
);
+        envFinal.put( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName()
);
 
         return sysRoot = new InitialLdapContext( envFinal, null );
     }

Modified: directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java?rev=190361&r1=190360&r2=190361&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
(original)
+++ directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
Sun Jun 12 23:45:35 2005
@@ -48,10 +48,7 @@
      */
     public void setUp() throws Exception
     {
-        if ( getName().equals( "testDisableAnonymousBinds" ) )
-        {
-            configuration.setAllowAnonymousAccess( false );
-        }
+        configuration.setAllowAnonymousAccess( false );
         super.setUp();
     }
 
@@ -69,9 +66,7 @@
         final Hashtable env = new Hashtable();
 
         env.put( Context.PROVIDER_URL, "ldap://localhost:" + port + "/ou=system" );
-
         env.put( Context.SECURITY_AUTHENTICATION, "none" );
-
         env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
 
         try

Modified: directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java?rev=190361&r1=190360&r2=190361&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java
(original)
+++ directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java
Sun Jun 12 23:45:35 2005
@@ -30,7 +30,7 @@
 import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 
-import org.apache.ldap.server.AbstractCoreTest;
+import org.apache.ldap.server.AbstractAdminTestCase;
 import org.apache.ldap.server.configuration.MutableContextPartitionConfiguration;
 
 
@@ -40,7 +40,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ServerContextFactoryTest extends AbstractCoreTest
+public class ServerContextFactoryTest extends AbstractAdminTestCase
 {
     public ServerContextFactoryTest()
     {
@@ -184,11 +184,9 @@
         Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
 
         env.put( Context.PROVIDER_URL, "dc=example" );
-
         env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
-
         env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
         env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory"
);
 
         InitialContext initialContext = new InitialContext( env );
@@ -218,11 +216,9 @@
         Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
 
         env.put( Context.PROVIDER_URL, "ou=testing" );
-
         env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
-
         env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
         env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory"
);
 
         InitialContext initialContext = new InitialContext( env );
@@ -252,11 +248,9 @@
         Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
 
         env.put( Context.PROVIDER_URL, "dc=MixedCase" );
-
         env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
-
         env.put( Context.SECURITY_CREDENTIALS, "secret" );
-
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
         env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory"
);
 
         InitialContext initialContext = new InitialContext( env );



Mime
View raw message