directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r548172 - /directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/
Date Mon, 18 Jun 2007 02:38:28 GMT
Author: erodriguez
Date: Sun Jun 17 19:38:27 2007
New Revision: 548172

URL: http://svn.apache.org/viewvc?view=rev&rev=548172
Log:
Added first cut of TCP support for Kerberos client.

Added:
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpCodecFactory.java
  (with props)
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpDecoder.java
  (with props)
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpEncoder.java
  (with props)
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpCodecFactory.java
  (contents, props changed)
      - copied, changed from r546752, directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientCodecFactory.java
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpDecoder.java
  (contents, props changed)
      - copied, changed from r546752, directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientDecoder.java
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpEncoder.java
  (contents, props changed)
      - copied, changed from r546752, directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientEncoder.java
Removed:
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientCodecFactory.java
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientDecoder.java
    directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientEncoder.java

Added: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpCodecFactory.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpCodecFactory.java?view=auto&rev=548172
==============================================================================
--- directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpCodecFactory.java
(added)
+++ directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpCodecFactory.java
Sun Jun 17 19:38:27 2007
@@ -0,0 +1,66 @@
+/*
+ *  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.client.kerberos.protocol;
+
+
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class KerberosClientTcpCodecFactory implements ProtocolCodecFactory
+{
+    private static final KerberosClientTcpCodecFactory INSTANCE = new KerberosClientTcpCodecFactory();
+
+
+    /**
+     * Returns the singleton {@link KerberosClientTcpCodecFactory}.
+     *
+     * @return The singleton {@link KerberosClientTcpCodecFactory}.
+     */
+    public static KerberosClientTcpCodecFactory getInstance()
+    {
+        return INSTANCE;
+    }
+
+
+    private KerberosClientTcpCodecFactory()
+    {
+        // Private constructor prevents instantiation outside this class.
+    }
+
+
+    public ProtocolEncoder getEncoder()
+    {
+        // Create a new encoder.
+        return new KerberosClientTcpEncoder();
+    }
+
+
+    public ProtocolDecoder getDecoder()
+    {
+        // Create a new decoder.
+        return new KerberosClientTcpDecoder();
+    }
+}

Propchange: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpCodecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpDecoder.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpDecoder.java?view=auto&rev=548172
==============================================================================
--- directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpDecoder.java
(added)
+++ directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpDecoder.java
Sun Jun 17 19:38:27 2007
@@ -0,0 +1,112 @@
+/*
+ *  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.client.kerberos.protocol;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.io.decoder.ErrorMessageDecoder;
+import org.apache.directory.server.kerberos.shared.io.decoder.KdcReplyDecoder;
+import org.apache.mina.common.BufferDataException;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * A {@link CumulativeProtocolDecoder} which supports Kerberos client operation over TCP,
+ * by reassembling split packets prior to ASN.1 DER decoding.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class KerberosClientTcpDecoder extends CumulativeProtocolDecoder
+{
+    private static final byte[] ERROR = new byte[]
+        { ( byte ) 0x7E, ( byte ) 0x78, ( byte ) 0x30, ( byte ) 0x76 };
+
+    private KdcReplyDecoder replyDecoder = new KdcReplyDecoder();
+    private ErrorMessageDecoder errorDecoder = new ErrorMessageDecoder();
+
+    private int maxObjectSize = 16384; // 16KB
+
+
+    /**
+     * Returns the allowed maximum size of the object to be decoded.
+     * If the size of the object to be decoded exceeds this value, this
+     * decoder will throw a {@link BufferDataException}.  The default
+     * value is <tt>16384</tt> (16KB).
+     * 
+     * @return The max object size.
+     */
+    public int getMaxObjectSize()
+    {
+        return maxObjectSize;
+    }
+
+
+    /**
+     * Sets the allowed maximum size of the object to be decoded.
+     * If the size of the object to be decoded exceeds this value, this
+     * decoder will throw a {@link BufferDataException}.  The default
+     * value is <tt>16384</tt> (16KB).
+     * 
+     * @param maxObjectSize 
+     */
+    public void setMaxObjectSize( int maxObjectSize )
+    {
+        if ( maxObjectSize <= 0 )
+        {
+            throw new IllegalArgumentException( "maxObjectSize: " + maxObjectSize );
+        }
+
+        this.maxObjectSize = maxObjectSize;
+    }
+
+
+    @Override
+    protected boolean doDecode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out
) throws Exception
+    {
+        if ( !in.prefixedDataAvailable( 4, maxObjectSize ) )
+        {
+            return false;
+        }
+
+        in.getInt();
+
+        byte[] header = new byte[4];
+        in.get( header );
+        in.rewind();
+
+        if ( Arrays.equals( ERROR, header ) )
+        {
+            System.out.println( "Got error." );
+            out.write( errorDecoder.decode( in.buf() ) );
+        }
+        else
+        {
+            System.out.println( "Got reply." );
+            out.write( replyDecoder.decode( in.buf() ) );
+        }
+
+        return true;
+    }
+}

Propchange: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpEncoder.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpEncoder.java?view=auto&rev=548172
==============================================================================
--- directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpEncoder.java
(added)
+++ directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpEncoder.java
Sun Jun 17 19:38:27 2007
@@ -0,0 +1,67 @@
+/*
+ *  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.client.kerberos.protocol;
+
+
+import java.io.IOException;
+
+import org.apache.directory.server.kerberos.shared.io.encoder.KdcRequestEncoder;
+import org.apache.directory.server.kerberos.shared.messages.KdcRequest;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class KerberosClientTcpEncoder extends ProtocolEncoderAdapter
+{
+    private KdcRequestEncoder requestEncoder = new KdcRequestEncoder();
+
+
+    public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws
IOException
+    {
+        ByteBuffer buf = ByteBuffer.allocate( 1024 );
+
+        // make space for int length
+        buf.putInt( 0 );
+
+        requestEncoder.encode( ( KdcRequest ) message, buf.buf() );
+
+        // mark position
+        int end = buf.position();
+
+        // length is the data minus 4 bytes for the pre-pended length
+        int recordLength = end - 4;
+
+        // write the length
+        buf.rewind();
+        buf.putInt( recordLength );
+
+        // set the position back before flipping the buffer
+        buf.position( end );
+        buf.flip();
+
+        out.write( buf );
+    }
+}

Propchange: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientTcpEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpCodecFactory.java
(from r546752, directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientCodecFactory.java)
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpCodecFactory.java?view=diff&rev=548172&p1=directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientCodecFactory.java&r1=546752&p2=directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpCodecFactory.java&r2=548172
==============================================================================
--- directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientCodecFactory.java
(original)
+++ directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpCodecFactory.java
Sun Jun 17 19:38:27 2007
@@ -29,23 +29,23 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 540371 $, $Date: 2007-05-21 17:00:43 -0700 (Mon, 21 May 2007) $
  */
-public class KerberosClientCodecFactory implements ProtocolCodecFactory
+public class KerberosClientUdpCodecFactory implements ProtocolCodecFactory
 {
-    private static final KerberosClientCodecFactory INSTANCE = new KerberosClientCodecFactory();
+    private static final KerberosClientUdpCodecFactory INSTANCE = new KerberosClientUdpCodecFactory();
 
 
     /**
-     * Returns the singleton {@link KerberosClientCodecFactory}.
+     * Returns the singleton {@link KerberosClientUdpCodecFactory}.
      *
-     * @return The singleton {@link KerberosClientCodecFactory}.
+     * @return The singleton {@link KerberosClientUdpCodecFactory}.
      */
-    public static KerberosClientCodecFactory getInstance()
+    public static KerberosClientUdpCodecFactory getInstance()
     {
         return INSTANCE;
     }
 
 
-    private KerberosClientCodecFactory()
+    private KerberosClientUdpCodecFactory()
     {
         // Private constructor prevents instantiation outside this class.
     }
@@ -54,13 +54,13 @@
     public ProtocolEncoder getEncoder()
     {
         // Create a new encoder.
-        return new KerberosClientEncoder();
+        return new KerberosClientUdpEncoder();
     }
 
 
     public ProtocolDecoder getDecoder()
     {
         // Create a new decoder.
-        return new KerberosClientDecoder();
+        return new KerberosClientUdpDecoder();
     }
 }

Propchange: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpCodecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpDecoder.java
(from r546752, directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientDecoder.java)
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpDecoder.java?view=diff&rev=548172&p1=directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientDecoder.java&r1=546752&p2=directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpDecoder.java&r2=548172
==============================================================================
--- directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientDecoder.java
(original)
+++ directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpDecoder.java
Sun Jun 17 19:38:27 2007
@@ -35,7 +35,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 502788 $, $Date: 2007-02-02 15:11:29 -0800 (Fri, 02 Feb 2007) $
  */
-public class KerberosClientDecoder extends ProtocolDecoderAdapter
+public class KerberosClientUdpDecoder extends ProtocolDecoderAdapter
 {
     private static final byte[] ERROR = new byte[]
         { ( byte ) 0x7E, ( byte ) 0x78, ( byte ) 0x30, ( byte ) 0x76 };

Propchange: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpEncoder.java
(from r546752, directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientEncoder.java)
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpEncoder.java?view=diff&rev=548172&p1=directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientEncoder.java&r1=546752&p2=directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpEncoder.java&r2=548172
==============================================================================
--- directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientEncoder.java
(original)
+++ directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpEncoder.java
Sun Jun 17 19:38:27 2007
@@ -34,7 +34,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 502788 $, $Date: 2007-02-02 15:11:29 -0800 (Fri, 02 Feb 2007) $
  */
-public class KerberosClientEncoder extends ProtocolEncoderAdapter
+public class KerberosClientUdpEncoder extends ProtocolEncoderAdapter
 {
     private KdcRequestEncoder requestEncoder = new KdcRequestEncoder();
 

Propchange: directory/clients/trunk/kerberos/client/src/main/java/org/apache/directory/client/kerberos/protocol/KerberosClientUdpEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message