directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1150500 - in /directory/apacheds/trunk: kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/ kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ kerberos-codec/src/test/java/org/apache/directory/...
Date Sun, 24 Jul 2011 22:15:48 GMT
Author: elecharny
Date: Sun Jul 24 22:15:46 2011
New Revision: 1150500

URL: http://svn.apache.org/viewvc?rev=1150500&view=rev
Log:
(ugly) fix for DIRSERVER-1636. I don't like the try/catch I added to deal with the decoding
of a ByteBuffer with 4 more bytes at the beginning... 

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosDecoder.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosEncoder.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
    directory/apacheds/trunk/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosDecoder.java?rev=1150500&r1=1150499&r2=1150500&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosDecoder.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosDecoder.java
Sun Jul 24 22:15:46 2011
@@ -97,8 +97,26 @@ public class KerberosDecoder extends Pro
             session.setAttribute( KERBEROS_MESSAGE_CONTAINER, kerberosMessageContainer );
             kerberosMessageContainer.setStream( buf );
             kerberosMessageContainer.setGathering( true );
+            kerberosMessageContainer.setTCP( !session.getTransportMetadata().isConnectionless()
);
         }
         
+        if ( kerberosMessageContainer.isTCP() )
+        {
+            if ( buf.remaining() > 4 )
+            {
+                kerberosMessageContainer.setTcpLength( buf.getInt() );
+                buf.mark();
+            }
+            else
+            {
+                return;
+            }
+        }
+        else
+        {
+            buf.mark();
+        }
+
         while ( buf.hasRemaining() )
         {
             try

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosEncoder.java?rev=1150500&r1=1150499&r2=1150500&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosEncoder.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosEncoder.java
Sun Jul 24 22:15:46 2011
@@ -38,16 +38,35 @@ public class KerberosEncoder extends Pro
     public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws
IOException
     {
         AbstractAsn1Object asn1Obj = ( AbstractAsn1Object ) message;
+        boolean isTcp = !session.getTransportMetadata().isConnectionless();
+        IoBuffer response = null;
+        IoBuffer kerberosMessage = null;
         
-        IoBuffer buf = IoBuffer.allocate( asn1Obj.computeLength() );
+        int responseLength = asn1Obj.computeLength();
+        kerberosMessage = IoBuffer.allocate( responseLength );
+        
+        if ( isTcp )
+        {
+            response = IoBuffer.allocate( responseLength + 4 );
+        }
+        else
+        {
+            response = kerberosMessage;
+        }
 
         try
         {
-            asn1Obj.encode( buf.buf() );
+            asn1Obj.encode( kerberosMessage.buf() );
+
+            if ( isTcp )
+            { 
+                response.putInt( responseLength );
+                response.put( kerberosMessage.buf().array() );
+            }
 
-            buf.flip();
+            response.flip();
 
-            out.write( buf );
+            out.write( response );
         }
         catch( EncoderException e )
         {

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java?rev=1150500&r1=1150499&r2=1150500&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java
Sun Jul 24 22:15:46 2011
@@ -39,6 +39,12 @@ public class KerberosMessageContainer ex
     
     /** A PrincipalName container */
     private PrincipalName principalName;
+    
+    /** A flag used when the protocol used to transfer the PDU is TCP */
+    private boolean isTCP;
+    
+    /** When the connection is using a TCP protocol, the PDU length */
+    private int tcpLength = -1;
 
     /**
      * Creates a new KerberosMessageContainer object. We will store ten grammars,
@@ -102,4 +108,40 @@ public class KerberosMessageContainer ex
     {
         this.principalName = principalName;
     }
+
+
+    /**
+     * @return the isTCP
+     */
+    public boolean isTCP()
+    {
+        return isTCP;
+    }
+
+
+    /**
+     * @param isTCP the isTCP to set
+     */
+    public void setTCP( boolean isTCP )
+    {
+        this.isTCP = isTCP;
+    }
+
+
+    /**
+     * @return the tcpLength
+     */
+    public int getTcpLength()
+    {
+        return tcpLength;
+    }
+
+
+    /**
+     * @param tcpLength the tcpLength to set
+     */
+    public void setTcpLength( int tcpLength )
+    {
+        this.tcpLength = tcpLength;
+    }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java?rev=1150500&r1=1150499&r2=1150500&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
Sun Jul 24 22:15:46 2011
@@ -21,6 +21,7 @@ package org.apache.directory.shared.kerb
 
 
 import java.nio.ByteBuffer;
+import java.nio.InvalidMarkException;
 
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
@@ -70,7 +71,15 @@ public final class KerberosMessageGramma
         public void action( KerberosMessageContainer kerberosMessageContainer ) throws DecoderException
         {
             ByteBuffer stream = kerberosMessageContainer.getStream();
-            stream.rewind();
+    
+            try
+            {
+                stream.reset();
+            }
+            catch ( InvalidMarkException ime )
+            {
+                stream.rewind();
+            }
 
             TLV tlv = kerberosMessageContainer.getCurrentTLV();
             kerberosMessageContainer.setGrammarEndAllowed( true );

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java?rev=1150500&r1=1150499&r2=1150500&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
Sun Jul 24 22:15:46 2011
@@ -26,8 +26,6 @@ import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.EncoderException;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
@@ -39,6 +37,9 @@ import org.apache.directory.shared.kerbe
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the decoder for some KerberosMessage

Modified: directory/apacheds/trunk/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java?rev=1150500&r1=1150499&r2=1150500&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java
(original)
+++ directory/apacheds/trunk/kerberos-test/src/test/java/org/apache/directory/server/kerberos/kdc/KerberosTcpITest.java
Sun Jul 24 22:15:46 2011
@@ -33,7 +33,6 @@ import org.apache.directory.server.core.
 import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -71,7 +70,6 @@ Project</a>
        @CreateTransport(protocol = "TCP")
    })
 @ApplyLdifFiles("org/apache/directory/server/kerberos/kdc/KerberosIT.ldif")
-@Ignore("TCP tests not working.")
 public class KerberosTcpITest extends AbstractKerberosITest
 {
     private static Integer udpPrefLimit;



Mime
View raw message