directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r567410 - /directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/
Date Sun, 19 Aug 2007 14:28:31 GMT
Author: elecharny
Date: Sun Aug 19 07:28:30 2007
New Revision: 567410

URL: http://svn.apache.org/viewvc?view=rev&rev=567410
Log:
° Added a common inherited abstract class (LdapHandler) to factorise a method used by all
the handler (setControls)
° Modified the Handlers to extend this class
° Injected the controls into LdapContext for BindHandler
° Removed the EMPTY_CONTROLS static member, which mya have caused some concurrency access
° Also remove dthe EMPTY_MODITEMS in MidofyHandler for the very same reason

Added:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/LdapHandler.java
Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AddHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/CompareHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/DeleteHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ExtendedHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyDnHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AddHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AddHandler.java?view=diff&rev=567410&r1=567409&r2=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AddHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AddHandler.java
Sun Aug 19 07:28:30 2007
@@ -28,7 +28,6 @@
 import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.message.AddRequest;
-import org.apache.directory.shared.ldap.message.Control;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ManageDsaITControl;
 import org.apache.directory.shared.ldap.message.ReferralImpl;
@@ -47,10 +46,9 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class AddHandler implements MessageHandler
+public class AddHandler extends LdapHandler implements MessageHandler
 {
     private static final Logger log = LoggerFactory.getLogger( AddHandler.class );
-    private static Control[] EMPTY_CONTROLS = new Control[0];
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
@@ -68,6 +66,7 @@
         try
         {
             LdapContext ctx = SessionRegistry.getSingleton().getLdapContext( session, null,
true );
+            
             if ( req.getControls().containsKey( ManageDsaITControl.CONTROL_OID ) )
             {
                 ctx.addToEnvironment( Context.REFERRAL, "ignore" );
@@ -76,7 +75,10 @@
             {
                 ctx.addToEnvironment( Context.REFERRAL, "throw" );
             }
-            ctx.setRequestControls( req.getControls().values().toArray( EMPTY_CONTROLS )
);
+            
+            // Inject controls into the context
+            setControls( ctx, req );
+
             ctx.createSubcontext( req.getEntry(), req.getAttributes() );
         }
         catch ( ReferralException e )

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java?view=diff&rev=567410&r1=567409&r2=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java
Sun Aug 19 07:28:30 2007
@@ -29,6 +29,7 @@
 import javax.naming.ldap.LdapContext;
 import javax.naming.spi.InitialContextFactory;
 
+import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.server.ldap.LdapConfiguration;
 import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.directory.server.ldap.support.bind.BindHandlerChain;
@@ -56,7 +57,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class BindHandler implements MessageHandler
+public class BindHandler extends LdapHandler implements MessageHandler
 {
     private static final Logger log = LoggerFactory.getLogger( BindHandler.class );
 
@@ -66,7 +67,7 @@
     /** Definition of SIMPLE and STRONG authentication constants */
     private static final String SIMPLE_AUTHENTICATION_LEVEL = "simple";
         
-    private static final String STRONG_AUTHENTICATION_LEVEL = "strong";
+    //private static final String STRONG_AUTHENTICATION_LEVEL = "strong";
     
     /** An empty Contol array used to get back the controls if any */
     private static final Control[] EMPTY_CONTROL = new Control[0];
@@ -205,7 +206,7 @@
      * must have been allowed in the configuration, otherwise an error is thrown.
      * 
      */
-    private void handleSimpleAuth( IoSession session, BindRequest bindRequest )
+    private void handleSimpleAuth( IoSession session, BindRequest bindRequest ) throws NamingException
     {
         LdapConfiguration config = ( LdapConfiguration ) session.getAttribute( LdapConfiguration.class.toString()
);
         
@@ -230,6 +231,10 @@
         
         // Now, get the context
         LdapContext ctx = getLdapContext( session, bindRequest, env );
+        ServerLdapContext newCtx = ( ServerLdapContext ) ctx.lookup( "" );
+        
+        // Inject controls into the context
+        setControls( newCtx, bindRequest );
         
         // Test that we successfully got one. If not, an error has already been returned.
         if ( ctx != null )
@@ -252,6 +257,8 @@
 
         if ( log.isDebugEnabled() )
         {
+        	log.debug( "User {} is binding", bindRequest.getName() );
+        	
             if ( bindRequest.isSimple() )
             {
                 log.debug( "Using simple authentication." );
@@ -274,7 +281,7 @@
             session.write( bindRequest.getResultResponse() );
             return;
         }
-
+        
         // Deal with the two kinds of authen :
         // - if it's simple, handle it in this class for speed
         // - for sasl, we go through a chain right now (but it may change in the near future)

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/CompareHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/CompareHandler.java?view=diff&rev=567410&r1=567409&r2=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/CompareHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/CompareHandler.java
Sun Aug 19 07:28:30 2007
@@ -29,7 +29,6 @@
 import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.message.CompareRequest;
-import org.apache.directory.shared.ldap.message.Control;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ManageDsaITControl;
 import org.apache.directory.shared.ldap.message.ReferralImpl;
@@ -48,10 +47,9 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class CompareHandler implements MessageHandler
+public class CompareHandler extends LdapHandler implements MessageHandler
 {
     private static final Logger log = LoggerFactory.getLogger( CompareHandler.class );
-    private static Control[] EMPTY_CONTROLS = new Control[0];
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
@@ -74,7 +72,9 @@
             {
                 newCtx.addToEnvironment( Context.REFERRAL, "throw" );
             }
-            newCtx.setRequestControls( req.getControls().values().toArray( EMPTY_CONTROLS
) );
+            
+            // Inject controls into the context
+            setControls( newCtx, req );
 
             if ( newCtx.compare( req.getName(), req.getAttributeId(), req.getAssertionValue()
) )
             {

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/DeleteHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/DeleteHandler.java?view=diff&rev=567410&r1=567409&r2=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/DeleteHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/DeleteHandler.java
Sun Aug 19 07:28:30 2007
@@ -27,7 +27,6 @@
 
 import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.message.Control;
 import org.apache.directory.shared.ldap.message.DeleteRequest;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ManageDsaITControl;
@@ -47,10 +46,9 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class DeleteHandler implements MessageHandler
+public class DeleteHandler extends LdapHandler implements MessageHandler
 {
     private static final Logger log = LoggerFactory.getLogger( DeleteHandler.class );
-    private static Control[] EMPTY_CONTROLS = new Control[0];
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
@@ -71,7 +69,10 @@
             {
                 ctx.addToEnvironment( Context.REFERRAL, "throw" );
             }
-            ctx.setRequestControls( req.getControls().values().toArray( EMPTY_CONTROLS )
);
+            
+            // Inject controls into the context
+            setControls( ctx, req );
+
             ctx.destroySubcontext( req.getName() );
         }
         catch ( ReferralException e )

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ExtendedHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ExtendedHandler.java?view=diff&rev=567410&r1=567409&r2=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ExtendedHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ExtendedHandler.java
Sun Aug 19 07:28:30 2007
@@ -24,6 +24,8 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.naming.ldap.LdapContext;
+
 import org.apache.directory.server.ldap.ExtendedOperationHandler;
 import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.directory.shared.ldap.message.ExtendedRequest;
@@ -41,7 +43,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ExtendedHandler implements MessageHandler
+public class ExtendedHandler extends LdapHandler implements MessageHandler
 {
     private Map<String, ExtendedOperationHandler> handlers = new HashMap<String,
ExtendedOperationHandler>();
 
@@ -95,6 +97,9 @@
         {
             try
             {
+            	SessionRegistry registry = SessionRegistry.getSingleton();
+                //LdapContext ldapContext = registry.getLdapContext( session, null, false);
+            	
                 handler.handleExtendedOperation( session, SessionRegistry.getSingleton(),
req );
             }
             catch ( Exception e )

Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/LdapHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/LdapHandler.java?view=auto&rev=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/LdapHandler.java
(added)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/LdapHandler.java
Sun Aug 19 07:28:30 2007
@@ -0,0 +1,59 @@
+/*
+ *  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.support;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.message.Control;
+
+import org.apache.directory.shared.ldap.message.Message;
+import org.apache.mina.handler.demux.MessageHandler;
+
+/**
+ * An abstract class to handle common methods used by all the handlers
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 541827 $
+ */
+public abstract class LdapHandler implements MessageHandler
+{
+	/**
+	 * Return an array containing the controls for this message.
+	 *  
+	 * @param context The context in which we will store teh found controls
+	 * @param message The message for which we want to extract the controls
+	 */
+	protected void setControls( LdapContext context, Message message ) throws NamingException
+	{
+		Control[] controls = null;
+		
+		if ( message.getControls() != null )
+		{
+			int nbControls = message.getControls().size();
+			
+			if ( nbControls != 0 )
+			{
+				controls = new Control[ nbControls ];
+				context.setRequestControls( message.getControls().values().toArray( controls ) );
+			}
+		}
+	}
+}

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyDnHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyDnHandler.java?view=diff&rev=567410&r1=567409&r2=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyDnHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyDnHandler.java
Sun Aug 19 07:28:30 2007
@@ -28,7 +28,6 @@
 import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.directory.shared.ldap.constants.JndiPropertyConstants;
 import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.message.Control;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ManageDsaITControl;
 import org.apache.directory.shared.ldap.message.ModifyDnRequest;
@@ -48,10 +47,9 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ModifyDnHandler implements MessageHandler
+public class ModifyDnHandler extends LdapHandler implements MessageHandler
 {
     private static final Logger log = LoggerFactory.getLogger( ModifyDnHandler.class );
-    private static Control[] EMPTY_CONTROLS = new Control[0];
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
@@ -105,7 +103,9 @@
                     ctx.addToEnvironment( Context.REFERRAL, "throw" );
                 }
                 
-                ctx.setRequestControls( req.getControls().values().toArray( EMPTY_CONTROLS
) );
+                // Inject controls into the context
+                setControls( ctx, req );
+                
                 String deleteRDN = String.valueOf( req.getDeleteOldRdn() );
                 ctx.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DELETE_RDN, deleteRDN
);
 

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyHandler.java?view=diff&rev=567410&r1=567409&r2=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/ModifyHandler.java
Sun Aug 19 07:28:30 2007
@@ -27,7 +27,6 @@
 
 import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.message.Control;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ManageDsaITControl;
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
@@ -48,11 +47,9 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ModifyHandler implements MessageHandler
+public class ModifyHandler extends LdapHandler implements MessageHandler
 {
     private static final Logger log = LoggerFactory.getLogger( ModifyHandler.class );
-    private static final ModificationItemImpl[] EMPTY = new ModificationItemImpl[0];
-    private static Control[] EMPTY_CONTROLS = new Control[0];
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
@@ -73,9 +70,29 @@
             {
                 ctx.addToEnvironment( Context.REFERRAL, "throw" );
             }
-            ctx.setRequestControls( req.getControls().values().toArray( EMPTY_CONTROLS )
);
-            Object[] mods = req.getModificationItems().toArray( EMPTY );
-            ctx.modifyAttributes( req.getName(), ( ModificationItemImpl[] ) mods );
+            
+            // Inject controls into the context
+            setControls( ctx, req );
+
+            // Process the modifications
+            if ( req.getModificationItems() != null )
+            {
+            	int nbItems = req.getModificationItems().size();
+            	
+            	if ( nbItems != 0 )
+            	{
+            		ModificationItemImpl[] mods = new ModificationItemImpl[nbItems];
+            		ctx.modifyAttributes( req.getName(), req.getModificationItems().toArray( mods
) );
+            	}
+            	else
+            	{
+            		 // What should we do if we don't have any modification ???
+            	}
+            }
+            else
+            {
+            	// What should we do if we don't have any modification ???
+            }
         }
         catch ( ReferralException e )
         {

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java?view=diff&rev=567410&r1=567409&r2=567410
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
Sun Aug 19 07:28:30 2007
@@ -30,7 +30,6 @@
 import javax.naming.NamingException;
 import javax.naming.ReferralException;
 import javax.naming.directory.SearchControls;
-import javax.naming.ldap.Control;
 import javax.naming.ldap.LdapContext;
 
 import org.apache.directory.server.core.jndi.ServerLdapContext;
@@ -67,7 +66,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class SearchHandler implements MessageHandler
+public class SearchHandler extends LdapHandler implements MessageHandler
 {
     //TM private static long cumul = 0L;
     //TM private static long count = 0;
@@ -159,7 +158,7 @@
         SearchRequest req = ( SearchRequest ) request;
         NamingEnumeration list = null;
         String[] ids = null;
-        Collection retAttrs = new HashSet();
+        Collection<String> retAttrs = new HashSet<String>();
         retAttrs.addAll( req.getAttributes() );
 
         // add the search request to the registry of outstanding requests for this session
@@ -183,10 +182,12 @@
             // ===============================================================
 
             boolean isRootDSESearch = isRootDSESearch( req );
+            
             // bypass checks to disallow anonymous binds for search on RootDSE with base
obj scope
             if ( isRootDSESearch )
             {
                 LdapContext unknown = SessionRegistry.getSingleton().getLdapContextOnRootDSEAccess(
session, null );
+                
                 if ( !( unknown instanceof ServerLdapContext ) )
                 {
                     ctx = ( ServerLdapContext ) unknown.lookup( "" );
@@ -200,6 +201,7 @@
             else
             {
                 LdapContext unknown = SessionRegistry.getSingleton().getLdapContext( session,
null, true );
+                
                 if ( !( unknown instanceof ServerLdapContext ) )
                 {
                     ctx = ( ServerLdapContext ) unknown.lookup( "" );
@@ -208,10 +210,12 @@
                 {
                     ctx = ( ServerLdapContext ) unknown;
                 }
-                Control[] controls = req.getControls().values().toArray( new Control[0] );
-                ctx.setRequestControls( controls );
+                
             }
             
+            // Inject controls into the context
+            setControls( ctx, req );
+
             ctx.addToEnvironment( DEREFALIASES_KEY, req.getDerefAliases() );
             
             if ( req.getControls().containsKey( ManageDsaITControl.CONTROL_OID ) )



Mime
View raw message