directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r519823 - in /directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src: main/java/org/apache/directory/server/ldap/ main/java/org/apache/directory/server/ldap/support/ test/java/org/apache/directory/server/ldap/
Date Mon, 19 Mar 2007 03:55:36 GMT
Author: erodriguez
Date: Sun Mar 18 20:55:34 2007
New Revision: 519823

URL: http://svn.apache.org/viewvc?view=rev&rev=519823
Log:
Clean-up in LDAP protocol provider in preparation for SASL configuration.
o  Addition of new LdapConfiguration bean for use with Spring.
o  Replaced StartupConfiguration with LdapConfiguration.
o  Updated SearchHandler to use LdapConfiguration.
o  Replaced LdapMessageHandler with MINA MessageHandler.
o  Updated unit test with above.

Added:
    directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapConfiguration.java
  (with props)
Modified:
    directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java
    directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/SessionRegistry.java
    directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
    directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/test/java/org/apache/directory/server/ldap/LdapProtocolProviderTest.java

Added: directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapConfiguration.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapConfiguration.java?view=auto&rev=519823
==============================================================================
--- directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapConfiguration.java
(added)
+++ directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapConfiguration.java
Sun Mar 18 20:55:34 2007
@@ -0,0 +1,425 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.directory.server.ldap;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.server.core.configuration.ConfigurationException;
+import org.apache.directory.server.protocol.shared.ServiceConfiguration;
+
+
+/**
+ * Contains the configuration parameters for the LDAP protocol provider.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapConfiguration extends ServiceConfiguration
+{
+    private static final long serialVersionUID = 3757127143811666817L;
+
+    /** The default maximum size limit. */
+    private static final int MAX_SIZE_LIMIT_DEFAULT = 100;
+
+    /** The default maximum time limit. */
+    private static final int MAX_TIME_LIMIT_DEFAULT = 10000;
+
+    /** The default IP port. */
+    private static final int IP_PORT_DEFAULT = 389;
+
+    /** Whether to allow anonymous access. */
+    private boolean allowAnonymousAccess = true; // allow by default
+
+    /** The maximum size limit. */
+    private int maxSizeLimit = MAX_SIZE_LIMIT_DEFAULT; // set to default value
+
+    /** The maximum time limit. */
+    private int maxTimeLimit = MAX_TIME_LIMIT_DEFAULT; // set to default value (milliseconds)
+
+    /** Whether LDAPS is enabled. */
+    private boolean enableLdaps = false;
+
+    /** The path to the certificate file. */
+    private File ldapsCertificateFile = new File( "server-work" + File.separator + "certificates"
+ File.separator
+        + "server.cert" );
+
+    /** The certificate password. */
+    private String ldapsCertificatePassword = "changeit";
+
+    /** The extended operation handlers. */
+    private final Collection extendedOperationHandlers = new ArrayList();
+
+    /** The supported authentication mechanisms. */
+    private List<String> supportedMechanisms;
+
+    /** The name of this host, validated during SASL negotiation. */
+    private String saslHost = "ldap.example.com";
+
+    /** The service principal, used by GSSAPI. */
+    private String saslPrincipal = "ldap/ldap.example.com@EXAMPLE.COM";
+
+    /** The quality of protection (QoP), used by DIGEST-MD5 and GSSAPI. */
+    private List<String> saslQop;
+
+    /** The list of realms serviced by this host. */
+    private List<String> saslRealms;
+
+    /** The search base DN for users to authenticate. */
+    private String saslBaseDn = "ou=users,dc=example,dc=com";
+
+
+    /**
+     * Creates a new instance of LdapConfiguration.
+     */
+    public LdapConfiguration()
+    {
+        super.setIpPort( IP_PORT_DEFAULT );
+        super.setEnabled( true );
+
+        supportedMechanisms = new ArrayList<String>();
+        supportedMechanisms.add( "SIMPLE" );
+        supportedMechanisms.add( "CRAM-MD5" );
+        supportedMechanisms.add( "DIGEST-MD5" );
+        supportedMechanisms.add( "GSSAPI" );
+
+        saslQop = new ArrayList<String>();
+        saslQop.add( "auth" );
+        saslQop.add( "auth-int" );
+        saslQop.add( "auth-conf" );
+
+        saslRealms = new ArrayList<String>();
+        saslRealms.add( "example.com" );
+    }
+
+
+    /**
+     * Returns <tt>true</tt> if LDAPS is enabled.
+     * 
+     * @return True if LDAPS is enabled.
+     */
+    public boolean isEnableLdaps()
+    {
+        return enableLdaps;
+    }
+
+
+    /**
+     * Sets if LDAPS is enabled or not.
+     * 
+     * @param enableLdaps Whether LDAPS is enabled.
+     */
+    public void setEnableLdaps( boolean enableLdaps )
+    {
+        this.enableLdaps = enableLdaps;
+    }
+
+
+    /**
+     * Returns the path of the X509 (or JKS) certificate file for LDAPS.
+     * The default value is <tt>"&lt;WORKDIR&gt;/certificates/server.cert"</tt>.
+     *  
+     * @return The LDAPS certificate file.
+     */
+    public File getLdapsCertificateFile()
+    {
+        return ldapsCertificateFile;
+    }
+
+
+    /**
+     * Sets the path of the SunX509 certificate file (either PKCS12 or JKS format)
+     * for LDAPS.
+     * 
+     * @param ldapsCertificateFile The path to the SunX509 certificate.
+     */
+    public void setLdapsCertificateFile( File ldapsCertificateFile )
+    {
+        if ( ldapsCertificateFile == null )
+        {
+            throw new ConfigurationException( "LdapsCertificateFile cannot be null." );
+        }
+        this.ldapsCertificateFile = ldapsCertificateFile;
+    }
+
+
+    /**
+     * Returns the password which is used to load the the SunX509 certificate file
+     * (either PKCS12 or JKS format).
+     * The default value is <tt>"changeit"</tt>.  This is the same value with
what
+     * <a href="http://jakarta.apache.org/tomcat/">Apache Jakarta Tomcat</a>
uses by
+     * default.
+     * 
+     * @return The LDAPS certificate password.
+     */
+    public String getLdapsCertificatePassword()
+    {
+        return ldapsCertificatePassword;
+    }
+
+
+    /**
+     * Sets the password which is used to load the LDAPS certificate file.
+     * 
+     * @param ldapsCertificatePassword The certificate password. 
+     */
+    public void setLdapsCertificatePassword( String ldapsCertificatePassword )
+    {
+        if ( ldapsCertificatePassword == null )
+        {
+            throw new ConfigurationException( "LdapsCertificatePassword cannot be null."
);
+        }
+        this.ldapsCertificatePassword = ldapsCertificatePassword;
+    }
+
+
+    /**
+     * Returns <code>true</code> if anonymous access is allowed.
+     * 
+     * @return True if anonymous access is allowed.
+     */
+    public boolean isAllowAnonymousAccess()
+    {
+        return allowAnonymousAccess;
+    }
+
+
+    /**
+     * Sets whether to allow anonymous access or not.
+     * 
+     * @param enableAnonymousAccess Set <code>true</code> to allow anonymous
access.
+     */
+    public void setAllowAnonymousAccess( boolean enableAnonymousAccess )
+    {
+        this.allowAnonymousAccess = enableAnonymousAccess;
+    }
+
+
+    /**
+     * Sets the maximum size limit.
+     *
+     * @param maxSizeLimit
+     */
+    public void setMaxSizeLimit( int maxSizeLimit )
+    {
+        this.maxSizeLimit = maxSizeLimit;
+    }
+
+
+    /**
+     * Returns the maximum size limit.
+     *
+     * @return The maximum size limit.
+     */
+    public int getMaxSizeLimit()
+    {
+        return maxSizeLimit;
+    }
+
+
+    /**
+     * Sets the maximum time limit.
+     *
+     * @param maxTimeLimit
+     */
+    public void setMaxTimeLimit( int maxTimeLimit )
+    {
+        this.maxTimeLimit = maxTimeLimit;
+    }
+
+
+    /**
+     * Returns the maximum time limit.
+     *
+     * @return The maximum time limit.
+     */
+    public int getMaxTimeLimit()
+    {
+        return maxTimeLimit;
+    }
+
+
+    /**
+     * Gets the {@link ExtendedOperationHandler}s.
+     *
+     * @return A collection of {@link ExtendedOperationHandler}s.
+     */
+    public Collection getExtendedOperationHandlers()
+    {
+        return new ArrayList( extendedOperationHandlers );
+    }
+
+
+    /**
+     * Sets the {@link ExtendedOperationHandler}s.
+     *
+     * @param handlers A collection of {@link ExtendedOperationHandler}s.
+     */
+    public void setExtendedOperationHandlers( Collection handlers )
+    {
+        for ( Iterator i = handlers.iterator(); i.hasNext(); )
+        {
+            if ( !( i.next() instanceof ExtendedOperationHandler ) )
+            {
+                throw new IllegalArgumentException(
+                    "The specified handler collection contains an element which is not an
ExtendedOperationHandler." );
+            }
+        }
+
+        this.extendedOperationHandlers.clear();
+        this.extendedOperationHandlers.addAll( handlers );
+    }
+
+
+    /**
+     * Returns the base DN containing users that can be SASL authenticated.
+     * 
+     * @return The base DN containing users that can be SASL authenticated.
+     */
+    public String getSaslBaseDn()
+    {
+        return saslBaseDn;
+    }
+
+
+    /**
+     * Sets the base DN containing users that can be SASL authenticated.
+     * 
+     * @param saslBaseDn The base DN containing users that can be SASL authenticated.
+     */
+    public void setSaslBaseDn( String saslBaseDn )
+    {
+        this.saslBaseDn = saslBaseDn;
+    }
+
+
+    /**
+     * Returns the FQDN of this SASL host, validated during SASL negotiation.
+     * 
+     * @return The FQDN of this SASL host, validated during SASL negotiation.
+     */
+    public String getSaslHost()
+    {
+        return saslHost;
+    }
+
+
+    /**
+     * Sets the FQDN of this SASL host, validated during SASL negotiation.
+     * 
+     * @param saslHost The FQDN of this SASL host, validated during SASL negotiation.
+     */
+    public void setSaslHost( String saslHost )
+    {
+        this.saslHost = saslHost;
+    }
+
+
+    /**
+     * Returns the Kerberos principal name for this LDAP service, used by GSSAPI.
+     * 
+     * @return The Kerberos principal name for this LDAP service, used by GSSAPI.
+     */
+    public String getSaslPrincipal()
+    {
+        return saslPrincipal;
+    }
+
+
+    /**
+     * Sets the Kerberos principal name for this LDAP service, used by GSSAPI.
+     * 
+     * @param saslPrincipal The Kerberos principal name for this LDAP service, used by GSSAPI.
+     */
+    public void setSaslPrincipal( String saslPrincipal )
+    {
+        this.saslPrincipal = saslPrincipal;
+    }
+
+
+    /**
+     * Returns the desired quality-of-protection, used by DIGEST-MD5 and GSSAPI.
+     * 
+     * @return The desired quality-of-protection, used by DIGEST-MD5 and GSSAPI.
+     */
+    public List getSaslQop()
+    {
+        return saslQop;
+    }
+
+
+    /**
+     * Sets the desired quality-of-protection, used by DIGEST-MD5 and GSSAPI.
+     * 
+     * @param saslQop The desired quality-of-protection, used by DIGEST-MD5 and GSSAPI.
+     */
+    public void setSaslQop( List<String> saslQop )
+    {
+        this.saslQop = saslQop;
+    }
+
+
+    /**
+     * Returns the realms serviced by this SASL host, used by DIGEST-MD5 and GSSAPI.
+     * 
+     * @return The realms serviced by this SASL host, used by DIGEST-MD5 and GSSAPI.
+     */
+    public List getSaslRealms()
+    {
+        return saslRealms;
+    }
+
+
+    /**
+     * Sets the realms serviced by this SASL host, used by DIGEST-MD5 and GSSAPI.
+     * 
+     * @param saslRealms The realms serviced by this SASL host, used by DIGEST-MD5 and GSSAPI.
+     */
+    public void setSaslRealms( List<String> saslRealms )
+    {
+        this.saslRealms = saslRealms;
+    }
+
+
+    /**
+     * Returns the list of supported authentication mechanisms.
+     * 
+     * @return The list of supported authentication mechanisms.
+     */
+    public List getSupportedMechanisms()
+    {
+        return supportedMechanisms;
+    }
+
+
+    /**
+     * Sets the list of supported authentication mechanisms.
+     * 
+     * @param supportedMechanisms The list of supported authentication mechanisms.
+     */
+    public void setSupportedMechanisms( List<String> supportedMechanisms )
+    {
+        this.supportedMechanisms = supportedMechanisms;
+    }
+}

Propchange: directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java?view=diff&rev=519823&r1=519822&r2=519823
==============================================================================
--- directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java
(original)
+++ directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java
Sun Mar 18 20:55:34 2007
@@ -30,14 +30,12 @@
 
 import javax.naming.Context;
 
-import org.apache.directory.server.core.configuration.StartupConfiguration;
 import org.apache.directory.server.ldap.support.AbandonHandler;
 import org.apache.directory.server.ldap.support.AddHandler;
 import org.apache.directory.server.ldap.support.BindHandler;
 import org.apache.directory.server.ldap.support.CompareHandler;
 import org.apache.directory.server.ldap.support.DeleteHandler;
 import org.apache.directory.server.ldap.support.ExtendedHandler;
-import org.apache.directory.server.ldap.support.LdapMessageHandler;
 import org.apache.directory.server.ldap.support.ModifyDnHandler;
 import org.apache.directory.server.ldap.support.ModifyHandler;
 import org.apache.directory.server.ldap.support.SearchHandler;
@@ -86,6 +84,7 @@
 import org.apache.mina.filter.codec.ProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolEncoder;
 import org.apache.mina.handler.demux.DemuxingIoHandler;
+import org.apache.mina.handler.demux.MessageHandler;
 import org.apache.mina.util.SessionLog;
 
 
@@ -104,11 +103,12 @@
     private static final Map DEFAULT_HANDLERS;
     /** a set of supported controls */
     private static final Set SUPPORTED_CONTROLS;
-    
+    /** configuration for the LDAP protocol provider **/
+    private LdapConfiguration cfg;
 
     static
     {
-        HashMap map = new HashMap();
+        Map<Object, Object> map = new HashMap<Object, Object>();
 
         /*
          * Note:
@@ -152,7 +152,7 @@
 
         DEFAULT_HANDLERS = Collections.unmodifiableMap( map );
 
-        HashSet set = new HashSet();
+        Set<Object> set = new HashSet<Object>();
         set.add( PersistentSearchControl.CONTROL_OID );
         set.add( EntryChangeControl.CONTROL_OID );
         set.add( ManageDsaITControl.CONTROL_OID );
@@ -176,17 +176,19 @@
      * @param env environment properties used to configure the provider and
      * underlying codec providers if any
      */
-    public LdapProtocolProvider( StartupConfiguration cfg, Hashtable env) throws LdapNamingException
+    public LdapProtocolProvider( LdapConfiguration cfg, Hashtable env) throws LdapNamingException
     {
+        this.cfg = cfg;
+
         Hashtable copy = ( Hashtable ) env.clone();
         copy.put( Context.PROVIDER_URL, "" );
         SessionRegistry.releaseSingleton();
-        new SessionRegistry( copy );
+        new SessionRegistry( cfg, copy );
 
         Iterator requestTypes = DEFAULT_HANDLERS.keySet().iterator();
         while ( requestTypes.hasNext() )
         {
-            LdapMessageHandler handler = null;
+            MessageHandler handler = null;
             String type = ( String ) requestTypes.next();
             Class clazz = null;
 
@@ -214,8 +216,7 @@
             try
             {
                 Class typeClass = Class.forName( type );
-                handler = ( LdapMessageHandler ) clazz.newInstance();
-                handler.init( cfg );
+                handler = ( MessageHandler ) clazz.newInstance();
                 this.handler.addMessageHandler( typeClass, handler );
             }
             catch ( Exception e )
@@ -338,13 +339,10 @@
     {
         public void sessionCreated( IoSession session ) throws Exception
         {
+            session.setAttribute( LdapConfiguration.class.toString(), cfg );
+
             IoFilterChain filters = session.getFilterChain();
             filters.addLast( "codec", new ProtocolCodecFilter( codecFactory ) );
-            
-            // TODO : The filter is logging too much information.
-            // Right now, I have commented it, but it may be 
-            // used with some parameter to disable it
-            //filters.addLast( "logger", new LoggingFilter() );
         }
 
 

Modified: directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/SessionRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/SessionRegistry.java?view=diff&rev=519823&r1=519822&r2=519823
==============================================================================
--- directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/SessionRegistry.java
(original)
+++ directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/SessionRegistry.java
Sun Mar 18 20:55:34 2007
@@ -33,8 +33,6 @@
 import javax.naming.ldap.LdapContext;
 import javax.naming.spi.InitialContextFactory;
 
-import org.apache.directory.server.core.configuration.Configuration;
-import org.apache.directory.server.core.configuration.StartupConfiguration;
 import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
 import org.apache.directory.shared.ldap.message.AbandonableRequest;
@@ -62,6 +60,9 @@
     /** the properties associated with this SessionRegistry */
     private Hashtable env;
 
+    /** the configuration associated with this SessionRegistry */
+    private LdapConfiguration cfg;
+
 
     /**
      * Gets the singleton instance for this SessionRegistry.  If the singleton
@@ -73,7 +74,7 @@
     {
         if ( s_singleton == null )
         {
-            s_singleton = new SessionRegistry( new Hashtable() );
+            s_singleton = new SessionRegistry( new LdapConfiguration(), new Hashtable() );
         }
 
         return s_singleton;
@@ -91,7 +92,7 @@
      *
      * @param env the properties associated with this SessionRegistry
      */
-    SessionRegistry( Hashtable env )
+    SessionRegistry( LdapConfiguration cfg, Hashtable env )
     {
         if ( s_singleton == null )
         {
@@ -99,7 +100,7 @@
         }
         else
         {
-            throw new IllegalStateException( "there can only be one singlton" );
+            throw new IllegalStateException( "There can only be one singleton." );
         }
 
         if ( env == null )
@@ -113,6 +114,15 @@
             this.env = env;
             this.env.put( Context.PROVIDER_URL, "" );
         }
+
+        if ( cfg == null )
+        {
+            this.cfg = new LdapConfiguration();
+        }
+        else
+        {
+            this.cfg = cfg;
+        }
     }
 
 
@@ -268,10 +278,8 @@
         // there is no context so its an implicit bind, no bind operation is being performed
         if ( ctx == null && allowAnonymous )
         {
-            // if configuration says disable anonymous binds we throw exection
-            StartupConfiguration config = ( StartupConfiguration ) Configuration.toConfiguration(
env );
-            
-            if ( ! config.isAllowAnonymousAccess() )
+            // if configuration says disable anonymous binds we throw exception
+            if ( !cfg.isAllowAnonymousAccess() )
             {
                 throw new LdapNoPermissionException( "Anonymous binds have been disabled!"
);
             }
@@ -309,7 +317,6 @@
                 slc = ( ServerLdapContext ) ctx;
             }
             boolean isAnonymousUser = slc.getPrincipal().getName().trim().equals( "" );
-            StartupConfiguration cfg = ( StartupConfiguration ) Configuration.toConfiguration(
env );
 
             // if the user principal is anonymous and the configuration does not allow anonymous
binds we
             // prevent the operation by blowing a NoPermissionsException

Modified: directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java?view=diff&rev=519823&r1=519822&r2=519823
==============================================================================
--- directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
(original)
+++ directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
Sun Mar 18 20:55:34 2007
@@ -33,9 +33,9 @@
 import javax.naming.ldap.Control;
 import javax.naming.ldap.LdapContext;
 
-import org.apache.directory.server.core.configuration.StartupConfiguration;
 import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.server.ldap.LdapConfiguration;
 import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.OperationAbandonedException;
@@ -53,9 +53,8 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.ArrayUtils;
 import org.apache.directory.shared.ldap.util.ExceptionUtils;
-
 import org.apache.mina.common.IoSession;
-
+import org.apache.mina.handler.demux.MessageHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,11 +65,10 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class SearchHandler implements LdapMessageHandler
+public class SearchHandler implements MessageHandler
 {
     private static final Logger log = LoggerFactory.getLogger( SearchHandler.class );
     private static final String DEREFALIASES_KEY = "java.naming.ldap.derefAliases";
-    private StartupConfiguration cfg;
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
@@ -82,7 +80,7 @@
      * @param ids the ids to return
      * @return the SearchControls to use with the ApacheDS server side JNDI provider
      */
-    private SearchControls getSearchControls( SearchRequest req, String[] ids, boolean isAdmin
)
+    private SearchControls getSearchControls( SearchRequest req, String[] ids, boolean isAdmin,
int maxSize, int maxTime )
     {
         // prepare all the search controls
         SearchControls controls = new SearchControls();
@@ -108,8 +106,8 @@
         }
         else
         {
-            controls.setCountLimit( Math.min( req.getSizeLimit(), cfg.getMaxSizeLimit() )
);
-            controls.setTimeLimit( ( int ) Math.min( req.getTimeLimit(), cfg.getMaxTimeLimit()
) );
+            controls.setCountLimit( Math.min( req.getSizeLimit(), maxSize ) );
+            controls.setTimeLimit( ( int ) Math.min( req.getTimeLimit(), maxTime ) );
         }
         
         controls.setSearchScope( req.getScope().getValue() );
@@ -144,6 +142,8 @@
      */
     public void messageReceived( IoSession session, Object request ) throws Exception
     {
+        LdapConfiguration cfg = ( LdapConfiguration ) session.getAttribute(  LdapConfiguration.class.toString()
);
+
     	if ( IS_DEBUG )
     	{
     		log.debug( "Message received : " + request.toString() );
@@ -239,19 +239,22 @@
             // Set search limits differently based on user's identity
             // ===============================================================
 
+            int maxSize = cfg.getMaxSizeLimit();
+            int maxTime = cfg.getMaxTimeLimit();
+
             SearchControls controls = null;
             if ( isAnonymousUser )
             {
-                controls = getSearchControls( req, ids, false );
+                controls = getSearchControls( req, ids, false, maxSize, maxTime );
             }
             else if ( ( ( ServerLdapContext ) ctx ).getPrincipal().getName()
                 .trim().equals( PartitionNexus.ADMIN_PRINCIPAL_NORMALIZED ) )
             {
-                controls = getSearchControls( req, ids, true );
+                controls = getSearchControls( req, ids, true, maxSize, maxTime );
             }
             else
             {
-                controls = getSearchControls( req, ids, false );
+                controls = getSearchControls( req, ids, false, maxSize, maxTime );
             }
             
             
@@ -435,11 +438,5 @@
                 }
             }
         }
-    }
-
-
-    public void init( StartupConfiguration cfg )
-    {
-        this.cfg = cfg;
     }
 }

Modified: directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/test/java/org/apache/directory/server/ldap/LdapProtocolProviderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/test/java/org/apache/directory/server/ldap/LdapProtocolProviderTest.java?view=diff&rev=519823&r1=519822&r2=519823
==============================================================================
--- directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/test/java/org/apache/directory/server/ldap/LdapProtocolProviderTest.java
(original)
+++ directory/apacheds/branches/apacheds-sasl-branch/protocol-ldap/src/test/java/org/apache/directory/server/ldap/LdapProtocolProviderTest.java
Sun Mar 18 20:55:34 2007
@@ -24,10 +24,7 @@
 
 import junit.framework.TestCase;
 
-import org.apache.directory.server.core.configuration.StartupConfiguration;
-import org.apache.directory.server.ldap.LdapProtocolProvider;
 import org.apache.directory.server.ldap.support.ExtendedHandler;
-import org.apache.directory.server.ldap.support.LdapMessageHandler;
 import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.message.AbandonRequest;
@@ -50,8 +47,8 @@
 import org.apache.directory.shared.ldap.message.SearchRequestImpl;
 import org.apache.directory.shared.ldap.message.UnbindRequest;
 import org.apache.directory.shared.ldap.message.UnbindRequestImpl;
-
 import org.apache.mina.common.IoSession;
+import org.apache.mina.handler.demux.MessageHandler;
 
 
 /**
@@ -72,7 +69,7 @@
      */
     public void testDefaultOperation() throws LdapNamingException
     {
-        LdapProtocolProvider provider = new LdapProtocolProvider( new StartupConfiguration(),
new Properties() );
+        LdapProtocolProvider provider = new LdapProtocolProvider( new LdapConfiguration(),
new Properties() );
         assertNotNull( provider.getCodecFactory() );
         assertTrue( provider.getName() == LdapProtocolProvider.SERVICE_NAME );
     }
@@ -119,116 +116,80 @@
         props.setProperty( UnbindRequest.class.getName(), BogusUnbindHandler.class.getName()
);
         props.setProperty( UnbindRequestImpl.class.getName(), BogusUnbindHandler.class.getName()
);
 
-        LdapProtocolProvider provider = new LdapProtocolProvider( new StartupConfiguration(),
props );
+        LdapProtocolProvider provider = new LdapProtocolProvider( new LdapConfiguration(),
props );
         assertNotNull( provider.getCodecFactory() );
         assertTrue( provider.getName() == LdapProtocolProvider.SERVICE_NAME );
     }
 
-    public static class BogusAbandonHandler implements LdapMessageHandler
+    public static class BogusAbandonHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
-
-        public void init( StartupConfiguration cfg )
-        {
-        }
     }
 
-    public static class BogusUnbindHandler implements LdapMessageHandler
+    public static class BogusUnbindHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
-
-        public void init( StartupConfiguration cfg )
-        {
-        }
     }
 
-    public static class BogusAddHandler implements LdapMessageHandler
+    public static class BogusAddHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
-
-        public void init( StartupConfiguration cfg )
-        {
-        }
     }
 
-    public static class BogusBindHandler implements LdapMessageHandler
+    public static class BogusBindHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
-
-        public void init( StartupConfiguration cfg )
-        {
-        }
     }
 
-    public static class BogusCompareHandler implements LdapMessageHandler
+    public static class BogusCompareHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
-
-        public void init( StartupConfiguration cfg )
-        {
-        }
     }
 
-    public static class BogusDeleteHandler implements LdapMessageHandler
+    public static class BogusDeleteHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
-
-        public void init( StartupConfiguration cfg )
-        {
-        }
     }
 
-    public static class BogusModifyDnHandler implements LdapMessageHandler
+    public static class BogusModifyDnHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
-
-        public void init( StartupConfiguration cfg )
-        {
-        }
     }
 
-    public static class BogusModifyHandler implements LdapMessageHandler
+    public static class BogusModifyHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
-
-        public void init( StartupConfiguration cfg )
-        {
-        }
     }
 
-    public static class BogusSearchHandler implements LdapMessageHandler
+    public static class BogusSearchHandler implements MessageHandler
     {
         public void messageReceived( IoSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
-        }
-
-        public void init( StartupConfiguration cfg )
-        {
         }
     }
 }



Mime
View raw message