directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r189935 - in /directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration: Configuration.java ConfigurationUtil.java ContextPartitionConfiguration.java MutableContextPartitionConfiguration.java MutableStartupConfiguration.java StartupConfiguration.java
Date Fri, 10 Jun 2005 09:37:56 GMT
Author: trustin
Date: Fri Jun 10 02:37:55 2005
New Revision: 189935

URL: http://svn.apache.org/viewcvs?rev=189935&view=rev
Log:
Finished implementing configuration package.

Added:
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationUtil.java
  (with props)
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableStartupConfiguration.java
  (with props)
Modified:
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java

Modified: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java?rev=189935&r1=189934&r2=189935&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java
(original)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java
Fri Jun 10 02:37:55 2005
@@ -54,6 +54,15 @@
     }
 
     /**
+     * Valids this configuration.
+     * 
+     * @throws ConfigurationException if this configuration is invalid
+     */
+    public void validate()
+    {
+    }
+    
+    /**
      * Converts this configuration to JNDI environment {@link Hashtable}.
      * This method simple returns a {@link Hashtable} that contains an entry
      * whose key is {@link #JNDI_KEY} and whose value is <tt>this</tt>.

Added: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationUtil.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationUtil.java?rev=189935&view=auto
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationUtil.java
(added)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationUtil.java
Fri Jun 10 02:37:55 2005
@@ -0,0 +1,78 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.server.configuration;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A utility class that provides common functionality while validating configuration.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+class ConfigurationUtil
+{
+    /**
+     * Checks all elements of the specified set is of the specified type,
+     * and returns cloned set.
+     * 
+     * @throws ConfigurationException if the specified set has an element of wrong type
+     */
+    static Set getTypeSafeSet( Set set, Class type )
+    {
+        Set newSet = new HashSet();
+        Iterator i = set.iterator();
+        while( i.hasNext() )
+        {
+            Object e = i.next();
+            if( !type.isAssignableFrom( e.getClass() ) )
+            {
+                throw new ConfigurationException(
+                        "Invalid element type: " + e.getClass() +
+                        " (expected " + type );
+            }
+            set.add( e );
+        }
+        return newSet;
+    }
+    
+    /**
+     * Returns the clone of the specified set.
+     */
+    static Set getClonedSet( Set set )
+    {
+        Set newSet = new HashSet();
+        newSet.addAll( set );
+        return newSet;
+    }
+    
+    static void validatePortNumber( int port )
+    {
+        if( port < 0 || port > 65535 )
+        {
+            throw new ConfigurationException( "Invalid port number: " + port );
+        }
+    }
+    
+    private ConfigurationUtil()
+    {
+    }
+}

Propchange: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationUtil.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java?rev=189935&r1=189934&r2=189935&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java
(original)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java
Fri Jun 10 02:37:55 2005
@@ -40,7 +40,7 @@
     private String suffix;
     private Set indexedAttributes = new HashSet(); // Set<String>
     private Attributes rootEntry = new BasicAttributes();
-    private ContextPartition partition;
+    private ContextPartition contextPartition;
     
     /**
      * Creates a new instance.
@@ -51,39 +51,32 @@
 
     public Set getIndexedAttributes()
     {
-        Set result = new HashSet();
-        result.addAll( indexedAttributes );
-        return result;
+        return ConfigurationUtil.getClonedSet( indexedAttributes );
     }
     
     protected void setIndexedAttributes( Set indexedAttributes )
     {
-        Set newIndexedAttributes = new HashSet();
+        Set newIndexedAttributes = ConfigurationUtil.getTypeSafeSet(
+                indexedAttributes, String.class );
 
-        Iterator i = indexedAttributes.iterator();
+        Iterator i = newIndexedAttributes.iterator();
         while( i.hasNext() )
         {
-            Object e = i.next();
-            if( !(e instanceof String) )
-            {
-                throw new ConfigurationException( "All elements of indexedAttributes must
be strings." );
-            }
-            
+            String attribute = ( String ) i.next();
             // TODO Attribute name must be normalized and validated
-            String attr = ( ( String ) e ).trim();
-            newIndexedAttributes.add( attr );
+            newIndexedAttributes.add( attribute );
         }
         this.indexedAttributes = newIndexedAttributes;
     }
     
-    public ContextPartition getPartition()
+    public ContextPartition getContextPartition()
     {
-        return partition;
+        return contextPartition;
     }
     
-    protected void setPartition( ContextPartition partition )
+    protected void setContextPartition( ContextPartition partition )
     {
-        this.partition = partition;
+        this.contextPartition = partition;
     }
     
     public Attributes getRootEntry()
@@ -105,5 +98,24 @@
     {
         // TODO Suffix should be normalized before being set
         this.suffix = suffix.trim();
+    }
+    
+    
+    /**
+     * Validates this configuration.
+     * 
+     * @throws ConfigurationException if this configuration is not valid
+     */
+    public void validate()
+    {
+        if( getSuffix() == null )
+        {
+            throw new ConfigurationException( "Suffix is not specified." );
+        }
+        
+        if( getContextPartition() == null )
+        {
+            throw new ConfigurationException( "Partition is not specified." );
+        }
     }
 }

Modified: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java?rev=189935&r1=189934&r2=189935&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java
(original)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java
Fri Jun 10 02:37:55 2005
@@ -45,9 +45,9 @@
         super.setIndexedAttributes( indexedAttributes );
     }
 
-    public void setPartition( ContextPartition partition )
+    public void setContextPartition( ContextPartition partition )
     {
-        super.setPartition( partition );
+        super.setContextPartition( partition );
     }
 
     public void setRootEntry( Attributes rootEntry )
@@ -58,23 +58,5 @@
     public void setSuffix( String suffix )
     {
         super.setSuffix( suffix );
-    }
-    
-    /**
-     * Validates this configuration.
-     * 
-     * @throws ConfigurationException if this configuration is not valid
-     */
-    public void validate()
-    {
-        if( getSuffix() == null )
-        {
-            throw new ConfigurationException( "Suffix is not specified." );
-        }
-        
-        if( getPartition() == null )
-        {
-            throw new ConfigurationException( "Partition is not specified." );
-        }
     }
 }

Added: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableStartupConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableStartupConfiguration.java?rev=189935&view=auto
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableStartupConfiguration.java
(added)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableStartupConfiguration.java
Fri Jun 10 02:37:55 2005
@@ -0,0 +1,95 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.server.configuration;
+
+import java.io.File;
+import java.util.Set;
+
+import org.apache.ldap.server.interceptor.InterceptorChain;
+import org.apache.mina.registry.ServiceRegistry;
+
+/**
+ * A mutable version of {@link StartupConfiguration}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class MutableStartupConfiguration extends StartupConfiguration
+{
+    private static final long serialVersionUID = -987437370955222007L;
+
+    public MutableStartupConfiguration()
+    {
+    }
+
+    public void setAuthenticators( Set authenticators )
+    {
+        super.setAuthenticators( authenticators );
+    }
+
+    public void setBootstrapSchemas( Set bootstrapSchemas )
+    {
+        super.setBootstrapSchemas( bootstrapSchemas );
+    }
+
+    public void setContextPartitionConfigurations( Set contextParitionConfigurations )
+    {
+        super.setContextPartitionConfigurations( contextParitionConfigurations );
+    }
+
+    public void setAllowAnonymousAccess( boolean enableAnonymousAccess )
+    {
+        super.setAllowAnonymousAccess( enableAnonymousAccess );
+    }
+
+    public void setEnableKerberos( boolean enableKerberos )
+    {
+        super.setEnableKerberos( enableKerberos );
+    }
+
+    public void setInterceptors( InterceptorChain interceptors )
+    {
+        super.setInterceptors( interceptors );
+    }
+
+    public void setLdapPort( int ldapPort )
+    {
+        super.setLdapPort( ldapPort );
+    }
+
+    public void setLdapsPort( int ldapsPort )
+    {
+        super.setLdapsPort( ldapsPort );
+    }
+
+    public void setMinaServiceRegistry( ServiceRegistry minaServiceRegistry )
+    {
+        super.setMinaServiceRegistry( minaServiceRegistry );
+    }
+
+    public void setTestEntries( Set testEntries )
+    {
+        super.setTestEntries( testEntries );
+    }
+
+    public void setWorkingDirectory( File workingDirectory )
+    {
+        super.setWorkingDirectory( workingDirectory );
+    }
+}

Propchange: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableStartupConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java?rev=189935&r1=189934&r2=189935&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java
(original)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/StartupConfiguration.java
Fri Jun 10 02:37:55 2005
@@ -19,10 +19,24 @@
 package org.apache.ldap.server.configuration;
 
 import java.io.File;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
 
+import javax.naming.directory.Attributes;
+
+import org.apache.ldap.server.authn.Authenticator;
+import org.apache.ldap.server.authn.SimpleAuthenticator;
 import org.apache.ldap.server.interceptor.InterceptorChain;
+import org.apache.ldap.server.schema.bootstrap.ApacheSchema;
+import org.apache.ldap.server.schema.bootstrap.BootstrapSchema;
+import org.apache.ldap.server.schema.bootstrap.CoreSchema;
+import org.apache.ldap.server.schema.bootstrap.CosineSchema;
+import org.apache.ldap.server.schema.bootstrap.InetorgpersonSchema;
+import org.apache.ldap.server.schema.bootstrap.JavaSchema;
+import org.apache.ldap.server.schema.bootstrap.SystemSchema;
 import org.apache.mina.registry.ServiceRegistry;
+import org.apache.mina.registry.SimpleServiceRegistry;
 
 /**
  * A {@link Configuration} that starts up ApacheDS.
@@ -34,21 +48,255 @@
 {
     private static final long serialVersionUID = 4826762196566871677L;
 
-    protected File homeDirectory;
     protected File workingDirectory;
-    protected boolean enableAnonymousAccess;
-    protected Set authenticators; // Set<Authenticator> and their properties>?
-    protected InterceptorChain interceptors; // and their properties?
-    protected ServiceRegistry minaServiceRegistry;
+    protected boolean allowAnonymousAccess;
+    protected Set authenticators = new HashSet(); // Set<Authenticator> and their properties>?
+    protected InterceptorChain interceptors = InterceptorChain.newDefaultChain();
+    protected ServiceRegistry minaServiceRegistry = new SimpleServiceRegistry();
     protected int ldapPort = 389;
     protected int ldapsPort = 636;
     protected boolean enableKerberos;
     
-    protected Set bootstrapSchemas; // Set<BootstrapSchema>
-    protected Set contextParitions; // Set<suffix, partition, indices, attributes, and
properties>?
-    protected Set testEntries; // Set<Attributes?>
+    protected Set bootstrapSchemas = new HashSet(); // Set<BootstrapSchema>
+    protected Set contextPartitionConfigurations; // Set<ContextPartitionConfiguration>
+    protected Set testEntries = new HashSet(); // Set<Attributes>
     
     protected StartupConfiguration()
     {
+        // Set default authenticators
+        authenticators.add( new SimpleAuthenticator() );
+        
+        // Set default bootstrap schemas
+        bootstrapSchemas.add( new CoreSchema() );
+        bootstrapSchemas.add( new CosineSchema() );        
+        bootstrapSchemas.add( new ApacheSchema() );        
+        bootstrapSchemas.add( new InetorgpersonSchema() );        
+        bootstrapSchemas.add( new JavaSchema() );        
+        bootstrapSchemas.add( new SystemSchema() );        
+    }
+
+    /**
+     * Returns {@link Authenticator}s to use for authenticating clients.
+     */
+    public Set getAuthenticators()
+    {
+        return ConfigurationUtil.getClonedSet( authenticators );
+    }
+
+    /**
+     * Sets {@link Authenticator}s to use for authenticating clients.
+     */
+    protected void setAuthenticators( Set authenticators )
+    {
+        this.authenticators = ConfigurationUtil.getTypeSafeSet(
+                authenticators, Authenticator.class );
+    }
+
+    /**
+     * Returns {@link BootstrapSchema}s to load while bootstrapping.
+     */
+    public Set getBootstrapSchemas()
+    {
+        return ConfigurationUtil.getClonedSet( bootstrapSchemas );
+    }
+
+    /**
+     * Sets {@link BootstrapSchema}s to load while bootstrapping.
+     */
+    protected void setBootstrapSchemas( Set bootstrapSchemas )
+    {
+        this.bootstrapSchemas = ConfigurationUtil.getTypeSafeSet(
+                bootstrapSchemas, BootstrapSchema.class );
+    }
+
+    /**
+     * Returns {@link ContextPartitionConfiguration}s to configure context partitions.
+     */
+    public Set getContextPartitionConfigurations()
+    {
+        return ConfigurationUtil.getClonedSet( contextPartitionConfigurations );
+    }
+
+    /**
+     * Sets {@link ContextPartitionConfiguration}s to configure context partitions.
+     */
+    protected void setContextPartitionConfigurations( Set contextParitionConfigurations )
+    {
+        Set newSet = ConfigurationUtil.getTypeSafeSet(
+                contextParitionConfigurations, ContextPartitionConfiguration.class );
+        
+        Iterator i = newSet.iterator();
+        while( i.hasNext() )
+        {
+            ( ( ContextPartitionConfiguration ) i.next() ).validate();
+        }
+        
+        this.contextPartitionConfigurations = newSet;
+    }
+
+    /**
+     * Returns <tt>true</tt> if anonymous access is allowed.
+     */
+    public boolean isAllowAnonymousAccess()
+    {
+        return allowAnonymousAccess;
+    }
+
+    /**
+     * Sets whether to allow anonymous access or not
+     */
+    protected void setAllowAnonymousAccess( boolean enableAnonymousAccess )
+    {
+        this.allowAnonymousAccess = enableAnonymousAccess;
+    }
+
+    /**
+     * Returns <tt>true</tt> if Kerberos support is enabled.
+     */
+    public boolean isEnableKerberos()
+    {
+        return enableKerberos;
+    }
+
+    /**
+     * Sets whether to enable Kerberos support or not.
+     */
+    protected void setEnableKerberos( boolean enableKerberos )
+    {
+        this.enableKerberos = enableKerberos;
+    }
+
+    /**
+     * Returns interceptor chain.
+     */
+    public InterceptorChain getInterceptors()
+    {
+        return interceptors;
+    }
+
+    /**
+     * Sets interceptor chain.
+     */
+    protected void setInterceptors( InterceptorChain interceptors )
+    {
+        if( interceptors == null )
+        {
+            throw new ConfigurationException( "Interceptors cannot be null" );
+        }
+        this.interceptors = interceptors;
+    }
+
+    /**
+     * Returns LDAP TCP/IP port number to listen to.
+     */
+    public int getLdapPort()
+    {
+        return ldapPort;
+    }
+
+    /**
+     * Sets LDAP TCP/IP port number to listen to.
+     */
+    protected void setLdapPort( int ldapPort )
+    {
+        ConfigurationUtil.validatePortNumber( ldapPort );
+        this.ldapPort = ldapPort;
+    }
+
+    /**
+     * Returns LDAPS TCP/IP port number to listen to.
+     */
+    public int getLdapsPort()
+    {
+        return ldapsPort;
+    }
+
+    /**
+     * Sets LDAPS TCP/IP port number to listen to.
+     */
+    protected void setLdapsPort( int ldapsPort )
+    {
+        ConfigurationUtil.validatePortNumber( ldapsPort );
+        this.ldapsPort = ldapsPort;
+    }
+
+    /**
+     * Returns <a href="http://directory.apache.org/subprojects/network/">MINA</a>
+     * {@link ServiceRegistry} that will be used by ApacheDS.
+     */
+    public ServiceRegistry getMinaServiceRegistry()
+    {
+        return minaServiceRegistry;
+    }
+
+    /**
+     * Sets <a href="http://directory.apache.org/subprojects/network/">MINA</a>
+     * {@link ServiceRegistry} that will be used by ApacheDS.
+     */
+    protected void setMinaServiceRegistry( ServiceRegistry minaServiceRegistry )
+    {
+        if( interceptors == null )
+        {
+            throw new ConfigurationException( "MinaServiceRegistry cannot be null" );
+        }
+        this.minaServiceRegistry = minaServiceRegistry;
+    }
+
+    /**
+     * Returns test directory entries({@link Attributes}) to be loaded while
+     * bootstrapping.
+     */
+    public Set getTestEntries()
+    {
+        return ConfigurationUtil.getClonedSet( testEntries );
+    }
+
+    /**
+     * Sets test directory entries({@link Attributes}) to be loaded while
+     * bootstrapping.
+     */
+    protected void setTestEntries( Set testEntries )
+    {
+        this.testEntries = ConfigurationUtil.getTypeSafeSet(
+                testEntries, Attributes.class );
+    }
+
+    /**
+     * Returns working directory (counterpart of <tt>var/lib</tt>).
+     */
+    public File getWorkingDirectory()
+    {
+        return workingDirectory;
+    }
+
+    /**
+     * Sets working directory (counterpart of <tt>var/lib</tt>).
+     */
+    protected void setWorkingDirectory( File workingDirectory )
+    {
+        workingDirectory.mkdirs();
+        if( !workingDirectory.exists() )
+        {
+            throw new ConfigurationException( "Working directory '" + workingDirectory +
"' doesn't exist." );
+        }
+        if( !workingDirectory.isDirectory() )
+        {
+            throw new ConfigurationException( "Working directory '" + workingDirectory +
"' is not a directory." );
+        }
+
+        this.workingDirectory = workingDirectory;
+    }
+    
+    public void validate()
+    {
+        if( workingDirectory == null )
+        {
+            throw new ConfigurationException( "WorkingDirectory is not specified." );
+        }
+        
+        if( contextPartitionConfigurations == null || contextPartitionConfigurations.size()
== 0 )
+        {
+            throw new ConfigurationException( "ContextPartitionConfiguration is not specified."
);
+        }
     }
 }



Mime
View raw message