directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r678507 - /directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/
Date Mon, 21 Jul 2008 17:48:00 GMT
Author: elecharny
Date: Mon Jul 21 10:47:59 2008
New Revision: 678507

URL: http://svn.apache.org/viewvc?rev=678507&view=rev
Log:
Modified the different handlers. It's not working yet...

Modified:
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewSearchHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/PersistentSearchListener.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/SearchResponseIterator.java

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java?rev=678507&r1=678506&r2=678507&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
Mon Jul 21 10:47:59 2008
@@ -40,15 +40,23 @@
  */
 public abstract class LdapRequestHandler<T extends Request> implements MessageHandler<T>
 {
+	/** The reference on the Ldap server instance */
     protected LdapServer ldapServer;
 
 
+    /**
+     * @return The associated ldap server instance
+     */
     public final LdapServer getLdapServer()
     {
         return ldapServer;
     }
 
 
+    /**
+     * Associates a Ldap server instance to the message handler
+     * @param ldapServer the associated ldap server instance
+     */
     public final void setLdapServer( LdapServer ldapServer )
     {
         this.ldapServer = ldapServer;
@@ -57,7 +65,15 @@
 
     /**
      * TODO - add notes about how this protects against unauthorized access
-     * and sets up the ldapSession's coreConte.
+     * and sets up the ldapSession's coreContext.
+     * 
+     * Handle a LDAP message received during a session.
+     * 
+     * @param session the user session created when the user first connected
+     * to the server
+     * @param message the LDAP message received. Can be any of the LDAP Request
+     * @throws Exception the thrown exception if something went wrong during 
+     * the message processing
      */
     public final void messageReceived( IoSession session, T message ) throws Exception
     {

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java?rev=678507&r1=678506&r2=678507&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java
Mon Jul 21 10:47:59 2008
@@ -81,6 +81,43 @@
     
 
     /**
+     * Handle the Simple authentication.
+     *
+     * @param session The associated Session
+     * @param message The BindRequest received
+     * @throws Exception If the authentication cannot be done
+     */
+    public void handleSimpleAuth( LdapSession session, BindRequest bindRequest ) throws Exception
+    {
+        // create a new Bind context, with a null session, as we don't have 
+        // any context yet.
+        BindOperationContext opContext = new BindOperationContext( null );
+        
+        // Stores the DN of the user to check, and its password
+        opContext.setDn( bindRequest.getName() );
+        opContext.setCredentials( bindRequest.getCredentials() );
+
+        // Stores the request controls into the operation context
+        LdapProtocolUtils.setRequestControls( opContext, bindRequest );
+        
+        // And call the OperationManager bind operation.
+        getLdapServer().getDirectoryService().getOperationManager().bind( opContext );
+        
+        // As a result, store the created session in the Core Session
+        session.setCoreSession( opContext.getSession() );
+        
+        // Return the successful response
+        BindResponse response = ( BindResponse ) bindRequest.getResultResponse();
+        response.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
+        LdapProtocolUtils.setResponseControls( opContext, response );
+        
+        // Write it back to the client
+        session.getIoSession().write( response );
+        LOG.debug( "Returned SUCCESS message: {}.", response );
+    }
+    
+    
+    /**
      * Handle the SASL authentication.
      *
      * @param session The associated Session
@@ -347,25 +384,10 @@
             return;
         }
 
-
-        // Deal with the two kinds of authentication :
-        // - 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)
+        // Deal with the two kinds of authentication : Simple and SASL
         if ( bindRequest.isSimple() )
         {
-            BindOperationContext opContext = new BindOperationContext( null );
-            opContext.setCredentials( bindRequest.getCredentials() );
-            opContext.setDn( bindRequest.getName() );
-            LdapProtocolUtils.setRequestControls( opContext, bindRequest );
-            getLdapServer().getDirectoryService().getOperationManager().bind( opContext );
-            session.setCoreSession( opContext.getSession() );
-            
-            BindResponse response = ( BindResponse ) bindRequest.getResultResponse();
-            response.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
-            LdapProtocolUtils.setResponseControls( opContext, response );
-            
-            session.getIoSession().write( response );
-            LOG.debug( "Returned SUCCESS message." );
+            handleSimpleAuth( session, bindRequest );
         }
         else
         {

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewSearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewSearchHandler.java?rev=678507&r1=678506&r2=678507&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewSearchHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewSearchHandler.java
Mon Jul 21 10:47:59 2008
@@ -21,12 +21,17 @@
 
 
 import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.entry.ServerAttribute;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.entry.ServerEntryUtils;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.server.newldap.LdapServer;
 import org.apache.directory.server.newldap.LdapSession;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.constants.JndiPropertyConstants;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.OperationAbandonedException;
 import org.apache.directory.shared.ldap.filter.PresenceNode;
@@ -41,8 +46,14 @@
 import org.apache.directory.shared.ldap.message.ScopeEnum;
 import org.apache.directory.shared.ldap.message.SearchRequest;
 import org.apache.directory.shared.ldap.message.SearchResponseDone;
+import org.apache.directory.shared.ldap.message.SearchResponseEntry;
+import org.apache.directory.shared.ldap.message.SearchResponseEntryImpl;
+import org.apache.directory.shared.ldap.message.SearchResponseReference;
+import org.apache.directory.shared.ldap.message.SearchResponseReferenceImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.util.ArrayUtils;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.apache.mina.common.IoSession;
 import org.slf4j.Logger;
@@ -52,6 +63,7 @@
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.ReferralException;
+import javax.naming.directory.Attribute;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
@@ -71,10 +83,8 @@
 {
     private static final Logger LOG = LoggerFactory.getLogger( NewSearchHandler.class );
 
-    
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-
     
     private void handlePersistentSearch( LdapSession session, SearchRequest req, 
         PersistentSearchControl psearchControl, EntryFilteringCursor list ) throws NamingException

@@ -94,6 +104,7 @@
             }
             
             list.beforeFirst();
+            
             if ( list.next() )
             {
                 Iterator<Response> it = new SearchResponseIterator( req, list, session
);
@@ -138,6 +149,9 @@
     
     /**
      * Main message handing method for search requests.
+     * 
+     * @param session the associated session
+     * @param req the received SearchRequest
      */
     public void handle( LdapSession session, SearchRequest req ) throws Exception
     {
@@ -146,29 +160,23 @@
             LOG.debug( "Message received:  {}", req.toString() );
         }
 
-        EntryFilteringCursor list = null;
+        EntryFilteringCursor cursor = null;
         String[] ids = null;
         Collection<String> retAttrs = new HashSet<String>();
-        retAttrs.addAll( req.getAttributes() );
-
+        
+        AttributeTypeRegistry atr = session.getCoreSession().getDirectoryService().getRegistries().getAttributeTypeRegistry();

+        
         // add the search request to the registry of outstanding requests for this session
         session.registerOutstandingRequest( req );
 
-        // check the attributes to see if a referral's ref attribute is included
-        if ( retAttrs.size() > 0 && !retAttrs.contains( SchemaConstants.REF_AT
) )
-        {
-            retAttrs.add( SchemaConstants.REF_AT );
-            ids = retAttrs.toArray( ArrayUtils.EMPTY_STRING_ARRAY );
-        }
-        else if ( retAttrs.size() > 0 )
-        {
-            ids = retAttrs.toArray( ArrayUtils.EMPTY_STRING_ARRAY );
-        }
-
         try
         {
             boolean isRootDSESearch = isRootDSESearch( req );
 
+            // ===============================================================
+            // Handle search in rootDSE differently.
+            // TODO : is this necessary ?
+            // ===============================================================
             if ( isRootDSESearch )
             {
             }
@@ -185,7 +193,7 @@
             
             if ( psearchControl != null )
             {
-                handlePersistentSearch( session, req, psearchControl, list );
+                handlePersistentSearch( session, req, psearchControl, cursor );
                 return;
             }
 
@@ -197,33 +205,79 @@
              * Iterate through all search results building and sending back responses
              * for each search result returned.
              */
-            list = session.getCoreSession().search( req );
+            cursor = session.getCoreSession().search( req );
             
             // TODO - fix this (need to make Cursors abandonable)
-            if ( list instanceof AbandonListener )
+            if ( cursor instanceof AbandonListener )
             {
-                req.addAbandonListener( ( AbandonListener ) list );
+                req.addAbandonListener( ( AbandonListener ) cursor );
             }
 
-            list.beforeFirst();
-            if ( list.next() )
+            // Position the cursor at the beginning
+            // TODO : should'nt it be always the case ?
+            cursor.beforeFirst();
+            
+            while ( cursor.next() )
             {
-                Iterator<Response> it = new SearchResponseIterator( req, list, session
);
+            	ServerEntry result = cursor.get();
+            	
+                SearchResponseEntry respEntry;
+                respEntry = new SearchResponseEntryImpl( req.getMessageId() );
+                respEntry.setAttributes( ServerEntryUtils.toAttributesImpl( result ) );
+                respEntry.setObjectName( result.getDn() );
                 
-                while ( it.hasNext() )
-                {
-                    session.getIoSession().write( it.next() );
-                }
-            }
-            else
-            {
-                list.close();
-                req.getResultResponse().getLdapResult().setResultCode( ResultCodeEnum.SUCCESS
);
+                /*
+                 * TODO : handle referrals here ...
+                 */
+            	/*
+                EntryAttribute ref = result.get( SchemaConstants.REF_AT );
+                LdapDN dn = result.getDn();
                 
-                for ( ResultResponse resultResponse : Collections.singleton( req.getResultResponse()
) )
+                if ( !session.getCoreSession().getReferralHandlingMode() 
+                    || req.getControls().containsKey( ManageDsaITControl.CONTROL_OID ) )
                 {
-                    session.getIoSession().write( resultResponse );
+                    SearchResponseEntry respEntry;
+                    respEntry = new SearchResponseEntryImpl( req.getMessageId() );
+                    respEntry.setAttributes( result.getAttributes() );
+                    respEntry.setObjectName( dn );
+                    prefetched = respEntry;
                 }
+                else
+                {
+                
+                    SearchResponseReference respRef;
+                    respRef = new SearchResponseReferenceImpl( req.getMessageId() );
+                    respRef.setReferral( new ReferralImpl() );
+
+                    for ( int ii = 0; ii < ref.size(); ii++ )
+                    {
+                        String url;
+
+                        try
+                        {
+                            url = ( String ) ref.get( ii );
+                            respRef.getReferral().addLdapUrl( url );
+                        }
+                        catch ( NamingException e )
+                        {
+                            try
+                            {
+                                underlying.close();
+                            }
+                            catch ( Throwable t )
+                            {
+                                LOG.error( "Encountered error while trying to close underlying
enumeration", t );
+                            }
+
+                            prefetched = null;
+                            respDone = getResponse( req, e );
+                        }
+                    }
+
+                    prefetched = respRef;
+                //}*/
+                
+                session.getIoSession().write( (Response)respEntry );
             }
         }
         catch ( ReferralException e )
@@ -300,11 +354,11 @@
         }
         finally
         {
-            if ( list != null )
+            if ( cursor != null )
             {
                 try
                 {
-                    list.close();
+                	cursor.close();
                 }
                 catch ( NamingException e )
                 {

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/PersistentSearchListener.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/PersistentSearchListener.java?rev=678507&r1=678506&r2=678507&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/PersistentSearchListener.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/PersistentSearchListener.java
Mon Jul 21 10:47:59 2008
@@ -31,7 +31,6 @@
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerEntryUtils;
 import org.apache.directory.server.core.jndi.ServerLdapContext;
-import org.apache.directory.server.newldap.SessionRegistry;
 import org.apache.directory.shared.ldap.codec.search.controls.ChangeType;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.OperationAbandonedException;
@@ -67,21 +66,19 @@
  */
 class PersistentSearchListener implements ObjectChangeListener, NamespaceChangeListener,
AbandonListener
 {
-    private static final Logger LOG = LoggerFactory.getLogger( SearchHandler.class );
+    private static final Logger LOG = LoggerFactory.getLogger( PersistentSearchListener.class
);
     final ServerLdapContext ctx;
     final IoSession session;
     final SearchRequest req;
     final PersistentSearchControl control;
-    final SessionRegistry registry;
 
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
 
 
-    PersistentSearchListener( SessionRegistry registry, ServerLdapContext ctx, IoSession
session, SearchRequest req )
+    PersistentSearchListener( ServerLdapContext ctx, IoSession session, SearchRequest req
)
     {
-        this.registry = registry;
         this.session = session;
         this.req = req;
         req.addAbandonListener( this );
@@ -141,7 +138,6 @@
             return;
         }
 
-        registry.removeOutstandingRequest( session, new Integer( req.getMessageId() ) );
         String msg = "failed on persistent search operation";
 
         if ( IS_DEBUG )

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/SearchResponseIterator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/SearchResponseIterator.java?rev=678507&r1=678506&r2=678507&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/SearchResponseIterator.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/SearchResponseIterator.java
Mon Jul 21 10:47:59 2008
@@ -31,7 +31,6 @@
 import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.core.jndi.ServerLdapContext;
-import org.apache.directory.server.newldap.SessionRegistry;
 import org.apache.directory.shared.ldap.codec.util.LdapURL;
 import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -69,7 +68,6 @@
     private final ServerLdapContext ctx;
     private final NamingEnumeration<SearchResult> underlying;
     private final IoSession session;
-    private final SessionRegistry registry;
     private SearchResponseDone respDone;
     private boolean done;
     private Response prefetched;
@@ -90,15 +88,13 @@
      * @param scope the scope of the search
      * @param session the session of the issuer of the search
      */
-    public SearchResponseIterator( SearchRequest req, ServerLdapContext ctx, NamingEnumeration<SearchResult>
underlying, int scope,
-        IoSession session, SessionRegistry registry )
+    public SearchResponseIterator( SearchRequest req, NamingEnumeration<SearchResult>
underlying, int scope,
+        IoSession session )
     {
         this.req = req;
-        this.ctx = ctx;
         this.scope = scope;
         this.underlying = underlying;
         this.session = session;
-        this.registry = registry;
 
         try
         {
@@ -159,7 +155,6 @@
             }
             else
             {
-                registry.removeOutstandingRequest( session, req.getMessageId() );
             }
         }
         catch ( NamingException e )
@@ -257,7 +252,6 @@
                 respDone = ( SearchResponseDone ) req.getResultResponse();
                 respDone.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
                 prefetched = null;
-                registry.removeOutstandingRequest( session, req.getMessageId() );
                 return next;
             }
         }
@@ -474,7 +468,6 @@
             }
         }
         
-        registry.removeOutstandingRequest( session, req.getMessageId() );
         return resp;
     }
 }
\ No newline at end of file



Mime
View raw message