directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r414312 - in /directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap: ./ support/
Date Wed, 14 Jun 2006 16:31:20 GMT
Author: akarasulu
Date: Wed Jun 14 09:31:19 2006
New Revision: 414312

URL: http://svn.apache.org/viewvc?rev=414312&view=rev
Log:
removed the use of all asn.1 codecs: sending and recieving captured PDUs

Modified:
    directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java
    directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AbandonHandler.java
    directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java
    directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
    directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/UnbindHandler.java

Modified: directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java?rev=414312&r1=414311&r2=414312&view=diff
==============================================================================
--- directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java
(original)
+++ directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolProvider.java
Wed Jun 14 09:31:19 2006
@@ -25,24 +25,26 @@
 
 import javax.naming.Context;
 
-import org.apache.mina.filter.codec.asn1.Asn1CodecDecoder;
-import org.apache.mina.filter.codec.asn1.Asn1CodecEncoder;
 import org.apache.directory.server.ldap.support.AbandonHandler;
 import org.apache.directory.server.ldap.support.BindHandler;
 import org.apache.directory.server.ldap.support.SearchHandler;
 import org.apache.directory.server.ldap.support.UnbindHandler;
 import org.apache.directory.shared.ldap.exception.LdapNamingException;
+import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.message.AbandonRequest;
 import org.apache.directory.shared.ldap.message.AbandonRequestImpl;
 import org.apache.directory.shared.ldap.message.BindRequest;
 import org.apache.directory.shared.ldap.message.BindRequestImpl;
-import org.apache.directory.shared.ldap.message.MessageDecoder;
-import org.apache.directory.shared.ldap.message.MessageEncoder;
+import org.apache.directory.shared.ldap.message.DerefAliasesEnum;
+import org.apache.directory.shared.ldap.message.Request;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.message.ScopeEnum;
 import org.apache.directory.shared.ldap.message.SearchRequest;
 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.directory.shared.ldap.name.LdapDN;
+import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
@@ -50,7 +52,9 @@
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
 import org.apache.mina.handler.demux.DemuxingIoHandler;
 import org.apache.mina.handler.demux.MessageHandler;
 
@@ -243,13 +247,96 @@
 
         public ProtocolEncoder getEncoder()
         {
-            return new Asn1CodecEncoder( new MessageEncoder( env ) );
+            return new ProtocolEncoder()
+            {
+                public void encode( IoSession session, Object input, ProtocolEncoderOutput
output ) throws Exception
+                {
+                    if ( input instanceof byte[] )
+                    {
+                        output.write( ByteBuffer.wrap( ( byte[] ) input ) );
+                    }
+                }
+
+                public void dispose( IoSession session ) throws Exception
+                {
+                }
+            };
         }
 
 
         public ProtocolDecoder getDecoder()
         {
-            return new Asn1CodecDecoder( new MessageDecoder( env ) );
+            return new ProtocolDecoder()
+            {
+                /*
+                 * Bind Request:
+                 *   id = 1
+                 *   
+                 *               30 0c 02 01 01 60 07 02 01 03 04 00
+                 *   80 00
+                 */
+                
+                /*
+                 * Search Request:
+                 *   id = 2 
+                 *   
+                 *               30 25 02 01 02 63 20 04 00 0a 01 00 
+                 *   0a 01 00 02 01 00 02 01 00 01 01 00 87 0b 6f 62 
+                 *   6a 65 63 74 43 6c 61 73 73 30 00
+                 */
+                
+                /*
+                 * Unbind Request:
+                 *   id = 3
+                 *   
+                 *               30 05 02 01 03 42 00
+                 */
+                
+                public void decode( IoSession session, ByteBuffer input, ProtocolDecoderOutput
output ) throws Exception
+                {
+                    Request req = null;
+                    byte b5 = input.get( 5 );
+                    if ( b5 == 0x60 )
+                    {
+                        System.out.println( "bind request" );
+                        BindRequestImpl br = new BindRequestImpl(1);
+                        br.setCredentials( "secret".getBytes() );
+                        br.setName( new LdapDN() );
+                        br.setSimple( true );
+                        br.setVersion3( true );
+                        req = br;
+                    }
+                    else if ( b5 == 0x63 )
+                    {
+                        System.out.println( "search request" );
+                        SearchRequestImpl sr = new SearchRequestImpl( 2 );
+                        sr.setBase( new LdapDN() );
+                        sr.setDerefAliases( DerefAliasesEnum.DEREFALWAYS );
+                        sr.setFilter( new PresenceNode( "objectClass" ) );
+                        sr.setSizeLimit( 0 );
+                        sr.setTimeLimit( 0 );
+                        sr.setTypesOnly( false );
+                        sr.setScope( ScopeEnum.BASEOBJECT );
+                        req = sr;
+                    }
+                    else if ( b5 == 0x42 )
+                    {
+                        System.out.println( "unbind request" );
+                        UnbindRequestImpl ur = new UnbindRequestImpl( 3 );
+                        req = ur;
+                    }
+                    else 
+                    {
+                        throw new IllegalStateException( "Unknown message type" );
+                    }
+                    
+                    output.write( req );
+                }
+
+                public void dispose( IoSession session ) throws Exception
+                {
+                }
+            };
         }
     }
 

Modified: directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AbandonHandler.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AbandonHandler.java?rev=414312&r1=414311&r2=414312&view=diff
==============================================================================
--- directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AbandonHandler.java
(original)
+++ directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/AbandonHandler.java
Wed Jun 14 09:31:19 2006
@@ -17,14 +17,8 @@
 package org.apache.directory.server.ldap.support;
 
 
-import org.apache.directory.server.ldap.SessionRegistry;
-import org.apache.directory.shared.ldap.message.AbandonRequest;
-import org.apache.directory.shared.ldap.message.AbandonableRequest;
-import org.apache.directory.shared.ldap.message.Request;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.handler.demux.MessageHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -35,52 +29,7 @@
  */
 public class AbandonHandler implements MessageHandler
 {
-    private static final Logger log = LoggerFactory.getLogger( AbandonHandler.class );
-
-
     public void messageReceived( IoSession session, Object request )
     {
-        AbandonRequest req = ( AbandonRequest ) request;
-        int abandonedId = req.getAbandoned();
-
-        if ( abandonedId < 0 )
-        {
-            return;
-        }
-
-        Request abandonedRequest = SessionRegistry.getSingleton().getOutstandingRequest(
session, abandonedId );
-
-        if ( abandonedRequest == null )
-        {
-            if ( log.isWarnEnabled() )
-            {
-                log.warn( "Got abandon request from client " + session + " but request must
have already "
-                    + "terminated.  Abandon request " + req + " had no effect." );
-            }
-            return;
-        }
-
-        if ( abandonedRequest instanceof AbandonableRequest )
-        {
-            log
-                .warn( "Abandon, Bind, Unbind, and StartTLS operations cannot be abandoned.
 Abandon request will be ignored." );
-        }
-
-        ( ( AbandonableRequest ) abandonedRequest ).abandon();
-        if ( SessionRegistry.getSingleton().removeOutstandingRequest( session, abandonedId
) == null )
-        {
-            if ( log.isWarnEnabled() )
-            {
-                log.warn( "Got abandon request from client " + session + " but request must
have already "
-                    + "terminated." );
-            }
-        }
-        else
-        {
-            if ( log.isDebugEnabled() )
-            {
-                log.debug( "Abandoned request: " + req );
-            }
-        }
     }
 }

Modified: directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java?rev=414312&r1=414311&r2=414312&view=diff
==============================================================================
--- directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java
(original)
+++ directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/BindHandler.java
Wed Jun 14 09:31:19 2006
@@ -17,9 +17,6 @@
 package org.apache.directory.server.ldap.support;
 
 
-import org.apache.directory.shared.ldap.message.BindRequest;
-import org.apache.directory.shared.ldap.message.LdapResult;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.handler.demux.MessageHandler;
 
@@ -33,9 +30,7 @@
 {
     public void messageReceived( IoSession session, Object request )
     {
-        BindRequest req = ( BindRequest ) request;
-        LdapResult result = req.getResultResponse().getLdapResult();
-        result.setResultCode( ResultCodeEnum.SUCCESS );
-        session.write( req.getResultResponse() );
+        byte[] msg = new byte[] { 0x30, 0x0c, 0x02, 0x01, 0x01, 0x61, 0x07, 0x0a, 0x01, 0x00,
0x04, 0x00, 0x04, 0x00 };
+        session.write( msg );
     }
 }

Modified: directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java?rev=414312&r1=414311&r2=414312&view=diff
==============================================================================
--- directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
(original)
+++ directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/SearchHandler.java
Wed Jun 14 09:31:19 2006
@@ -16,16 +16,6 @@
 package org.apache.directory.server.ldap.support;
 
 
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
-
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-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.name.LdapDN;
-
 import org.apache.mina.common.IoSession;
 import org.apache.mina.handler.demux.MessageHandler;
 
@@ -38,30 +28,22 @@
  */
 public class SearchHandler implements MessageHandler
 {
-    private Attributes entry;
-    private LdapDN entryDn;
-
-    
-    public SearchHandler()
-    {
-        entry = new BasicAttributes( "objectClass", "top", true );
-        entryDn = new LdapDN();
-    }
-    
-    
     /**
      * Main message handing method for search requests.
      */
     public void messageReceived( IoSession session, Object request )
     {
-        SearchResponseEntry respEntry;
-        respEntry = new SearchResponseEntryImpl( ( ( SearchRequest) request ).getMessageId()
);
-        respEntry.setAttributes( entry );
-        respEntry.setObjectName( entryDn );
-        session.write( respEntry );
+        byte[] entryMsg = new byte[] { 
+            0x30, 0x1f, 0x02, 0x01, 0x02, 0x64, 0x1a, 0x04, 0x00, 0x30, 0x16, 
+            0x30, 0x14, 0x04, 0x0b, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 
+            0x6c, 0x61, 0x73, 0x73, 0x31, 0x05, 0x04, 0x03, 0x74, 0x6f, 0x70 
+            };
+        session.write( entryMsg );
         
-        SearchResponseDone respDone = ( SearchResponseDone ) ( ( SearchRequest) request ).getResultResponse();
-        respDone.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
-        session.write( respDone );
+        byte[] doneMsg = new byte[] {
+            0x30, 0x0c, 0x02, 0x01, 0x02, 0x65, 0x07, 0x0a, 0x01, 0x00, 0x04, 
+            0x00, 0x04, 0x00
+        };
+        session.write( doneMsg );
     }
 }

Modified: directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/UnbindHandler.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/UnbindHandler.java?rev=414312&r1=414311&r2=414312&view=diff
==============================================================================
--- directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/UnbindHandler.java
(original)
+++ directory/branches/apacheds/nocodec-experiment/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/UnbindHandler.java
Wed Jun 14 09:31:19 2006
@@ -17,17 +17,9 @@
 package org.apache.directory.server.ldap.support;
 
 
-import javax.naming.NamingException;
-import javax.naming.ldap.LdapContext;
-
-import org.apache.directory.server.core.jndi.ServerLdapContext;
-import org.apache.directory.server.ldap.SessionRegistry;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.handler.demux.MessageHandler;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 
 /**
  * A no reply protocol handler implementation for LDAP {@link
@@ -38,31 +30,7 @@
  */
 public class UnbindHandler implements MessageHandler
 {
-    private static final Logger log = LoggerFactory.getLogger( UnbindHandler.class );
-
-
     public void messageReceived( IoSession session, Object request )
     {
-        SessionRegistry registry = SessionRegistry.getSingleton();
-
-        try
-        {
-            LdapContext ctx = ( LdapContext ) SessionRegistry.getSingleton().getLdapContext(
session, null, false );
-
-            if ( ctx != null )
-            {
-                if ( ctx instanceof ServerLdapContext && ( ( ServerLdapContext )
ctx ).getService().isStarted() )
-                {
-                    ( ( ServerLdapContext ) ctx ).ldapUnbind();
-                }
-                ctx.close();
-            }
-            registry.terminateSession( session );
-            registry.remove( session );
-        }
-        catch ( NamingException e )
-        {
-            log.error( "failed to unbind session properly", e );
-        }
     }
 }



Mime
View raw message