[jboss-cvs] JBossAS SVN: r70412 - in projects/security/security-negotiation/trunk: jboss-negotiation and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 5 06:31:21 EST 2008


Author: darran.lofthouse at jboss.com
Date: 2008-03-05 06:31:19 -0500 (Wed, 05 Mar 2008)
New Revision: 70412

Added:
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/DebugHelper.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenDecoder.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoder.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoderTest.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInit.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoder.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoderTest.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTarg.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargDecoder.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoder.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoderTest.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/test/
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/test/MicrosoftDecoding.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SPNEGOValve.java
   projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SimpleValve.java
Modified:
   projects/security/security-negotiation/trunk/docs/userguide/
   projects/security/security-negotiation/trunk/jboss-negotiation/.classpath
   projects/security/security-negotiation/trunk/jboss-negotiation/pom.xml
Log:
Commit initial message handling implementation under an individual contributor agreement for Darran Lofthouse.



Property changes on: projects/security/security-negotiation/trunk/docs/userguide
___________________________________________________________________
Name: svn:ignore
   + target


Modified: projects/security/security-negotiation/trunk/jboss-negotiation/.classpath
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/.classpath	2008-03-05 10:40:53 UTC (rev 70411)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/.classpath	2008-03-05 11:31:19 UTC (rev 70412)
@@ -5,5 +5,9 @@
 	<classpathentry kind="src" path="src/tests"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
+	<classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-tomcat/catalina/5.5.12/catalina-5.5.12.jar"/>
 	<classpathentry kind="output" path="target/eclipse-classes"/>
 </classpath>

Modified: projects/security/security-negotiation/trunk/jboss-negotiation/pom.xml
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/pom.xml	2008-03-05 10:40:53 UTC (rev 70411)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/pom.xml	2008-03-05 11:31:19 UTC (rev 70412)
@@ -13,11 +13,31 @@
   <name>JBoss SPNEGO Authentication</name>
   <url>http://www.jboss.org</url>
   <description>JBoss SPNEGO Library</description> 
-  <dependencies>    
+  <dependencies> 
     <dependency>
+      <groupId>apache-tomcat</groupId>
+      <artifactId>catalina</artifactId>
+      <version>5.5.12</version>
+    </dependency>  
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <version>2.5</version>
+    </dependency>         
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
     </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>1.2.14</version>
+    </dependency>    
   </dependencies>
 </project>

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/DebugHelper.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/DebugHelper.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/DebugHelper.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import org.apache.commons.codec.binary.Hex;
+
+/**
+ * Utility class to assist debugging.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class DebugHelper
+{
+
+   public static String convertToHex(final byte[] message)
+   {
+      StringBuffer sb = new StringBuffer(message.length * 5);
+      char[] hex = Hex.encodeHex(message);
+
+      for (int i = 0; i < hex.length; i++)
+      {
+         if (i % 2 == 0)
+         {
+            sb.append(" 0x");
+         }
+
+         sb.append(hex[i]);
+      }
+
+      return sb.toString();
+   }
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/DebugHelper.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenDecoder.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenDecoder.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenDecoder.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,67 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * NegToken Decoder.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenDecoder
+{
+
+   public static int readLength(final InputStream is) throws IOException
+   {
+      byte first = (byte) is.read();
+      byte masked = (byte) (first & (byte) 128);
+   
+      if (masked == 0)
+      {
+         return first;
+      }
+   
+      int lengthLength = first & (byte) 127;
+   
+      byte[] lengthBytes = new byte[lengthLength];
+      is.read(lengthBytes);
+   
+      int length = 0;
+      for (int i = 0; i < lengthLength; i++)
+      {
+         int currentPos = lengthLength - i - 1;
+         int currentLength = lengthBytes[currentPos];
+   
+         if (currentLength < 0)
+         {
+            currentLength += 256;
+         }
+   
+         if (i > 0)
+         {
+            currentLength = currentLength * (int) (Math.pow(2, 8 * i));
+         }
+   
+         length += currentLength;
+      }
+   
+      return length;
+   }
+
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenDecoder.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoder.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoder.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoder.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,82 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+/**
+ * Neg Token Encoder.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenEncoder
+{
+
+   private static int bitsRequired(int x)
+   {
+      return (int) (Math.log(x) / Math.log(2)) + 1;
+   }
+
+   public static byte[] createTypeLength(final byte type, final int length)
+   {
+      byte[] token;
+
+      int bitsRequired = bitsRequired(length);
+
+      if (bitsRequired <= 7)
+      {
+         token = new byte[2];
+         token[1] = (byte) length;
+      }
+      else
+      {
+         int bytesRequired = bitsRequired / 8;
+         if (bitsRequired % 8 != 0)
+         {
+            bytesRequired++;
+         }
+
+         token = new byte[bytesRequired + 2];
+
+         token[1] = (byte) (bytesRequired | 0x80);
+
+         int lengthLeft = length;
+
+         for (int i = 0; i < bytesRequired; i++)
+         {
+            int pos = bytesRequired - i - 1;
+            if (pos == 0)
+            {
+               token[i + 2] = (byte) lengthLeft;
+            }
+            else
+            {
+               int pow = pos * 8;
+               int multiplier = (int) Math.pow(2, pow);
+               int byteValue = lengthLeft / multiplier;
+
+               token[i + 2] = (byte) byteValue;
+
+               lengthLeft -= byteValue * multiplier;
+            }
+
+         }
+      }
+
+      token[0] = type;
+
+      return token;
+   }
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoder.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoderTest.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoderTest.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoderTest.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case to test NegTokenEncoder. 
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenEncoderTest extends TestCase
+{
+
+   private static void log(final byte[] name)
+   {
+      String hex = DebugHelper.convertToHex(name);
+      System.out.println(hex);
+   }
+
+   /**
+    *  Test the createTypeLength method correctly 
+    *  creates a lengh of one byte using both extremes 
+    *  and a value in the middle. 
+    */
+   public void testCreateTypeLength_OneBye()
+   {
+      byte[] tl_1 = NegTokenEncoder.createTypeLength((byte) 0x00, 1);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, 0x01}, tl_1));
+      log(tl_1);
+
+      byte[] tl_2 = NegTokenEncoder.createTypeLength((byte) 0x00, 64);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, 0x40}, tl_2));
+      log(tl_2);
+
+      byte[] tl_3 = NegTokenEncoder.createTypeLength((byte) 0x00, 127);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, 0x7F}, tl_3));
+      log(tl_3);
+
+      byte[] tl_4 = NegTokenEncoder.createTypeLength((byte) 0x00, 255);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, (byte) 0x81, (byte) 0xFF}, tl_4));
+      log(tl_4);
+   }
+
+   public void testCreateTypeLength_TwoBytes()
+   {
+      byte[] tl_1 = NegTokenEncoder.createTypeLength((byte) 0x00, 256);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, (byte) 0x82, 0x01, 0x00}, tl_1));
+      log(tl_1);
+
+      byte[] tl_2 = NegTokenEncoder.createTypeLength((byte) 0x00, 32768);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, (byte) 0x82, (byte) 0x80, 0x00}, tl_2));
+      log(tl_2);
+
+      byte[] tl_3 = NegTokenEncoder.createTypeLength((byte) 0x00, 65280);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, (byte) 0x82, (byte) 0xFF, 0x00}, tl_3));
+      log(tl_3);
+
+      byte[] tl_4 = NegTokenEncoder.createTypeLength((byte) 0x00, 65535);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, (byte) 0x82, (byte) 0xFF, (byte) 0xFF}, tl_4));
+      log(tl_4);
+   }
+
+   public void testCreateTypeLength_ThreeBytes()
+   {
+      byte[] tl_1 = NegTokenEncoder.createTypeLength((byte) 0x00, 65536);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, (byte) 0x83, 0x01, 0x00, 0x00}, tl_1));
+      log(tl_1);
+
+      byte[] tl_2 = NegTokenEncoder.createTypeLength((byte) 0x00, 8421375);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, (byte) 0x83, (byte) 0x80, 0x7F, (byte) 0xFF}, tl_2));
+      log(tl_2);
+
+      byte[] tl_3 = NegTokenEncoder.createTypeLength((byte) 0x00, 16777215);
+      assertTrue(Arrays.equals(new byte[]
+      {0x00, (byte) 0x83, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}, tl_3));
+      log(tl_3);
+   }
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenEncoderTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInit.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInit.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInit.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.ietf.jgss.Oid;
+
+/**
+ * Representation of NegTokenInit.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenInit
+{
+
+   private Oid messageOid;
+
+   private final List mechTypes = new LinkedList();
+
+   private byte[] reqFlags;
+
+   private byte[] mechToken;
+
+   private byte[] mechListMIC;
+
+   public Oid getMessageOid()
+   {
+      return messageOid;
+   }
+
+   public void setMessageOid(final Oid messageOid)
+   {
+      this.messageOid = messageOid;
+   }
+
+   public List getMechTypes()
+   {
+      return mechTypes;
+   }
+
+   public void addMechType(final Oid mechType)
+   {
+      mechTypes.add(mechType);
+   }
+
+   public byte[] getMechToken()
+   {
+      return mechToken;
+   }
+
+   
+   public byte[] getReqFlags()
+   {
+      return reqFlags;
+   }
+
+   public void setReqFlags(byte[] reqFlags)
+   {
+      this.reqFlags = reqFlags;
+   }
+
+   public void setMechToken(byte[] mechToken)
+   {
+      this.mechToken = mechToken;
+   }
+
+   public byte[] getMechListMIC()
+   {
+      return mechListMIC;
+   }
+
+   public void setMechListMIC(byte[] mechListMIC)
+   {
+      this.mechListMIC = mechListMIC;
+   }
+
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInit.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoder.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoder.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoder.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,140 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.Oid;
+
+/**
+ * NegTokenInit Decoder.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenInitDecoder extends NegTokenDecoder
+{
+
+   protected static void decodeRequestFlags(final InputStream is, final NegTokenInit negTokenInit) throws IOException
+   {
+      int length = NegTokenDecoder.readLength(is);
+      byte[] reqFlags = new byte[length];
+      is.read(reqFlags);
+
+      negTokenInit.setReqFlags(reqFlags);
+   }
+
+   protected static void decodeMechTypes(final InputStream is, final NegTokenInit negTokenInit) throws IOException,
+         GSSException
+   {
+      int length = NegTokenDecoder.readLength(is);
+      byte sequenceType = (byte) is.read();
+      int sequenceLength = NegTokenDecoder.readLength(is);
+
+      int leftAfter = is.available() - sequenceLength;
+
+      while (is.available() > leftAfter)
+      {
+         negTokenInit.addMechType(new Oid(is));
+      }
+   }
+
+   protected static void decodeMechToken(final InputStream is, final NegTokenInit negTokenInit) throws IOException
+   {
+      int length = NegTokenDecoder.readLength(is);
+
+      byte type = (byte) is.read();
+      int tokenLength = readLength(is);
+
+      byte[] mechToken = new byte[tokenLength];
+      is.read(mechToken);
+
+      negTokenInit.setMechToken(mechToken);
+   }
+
+   protected static void decodeMechListMIC(final InputStream is, final NegTokenInit negTokenInit) throws IOException
+   {
+      int length = NegTokenDecoder.readLength(is);
+      byte[] mechListMIC = new byte[length];
+      is.read(mechListMIC);
+
+      negTokenInit.setMechListMIC(mechListMIC);
+   }
+
+   protected static void decodeNegTokenInitSequence(final InputStream is, final NegTokenInit negTokenInit)
+         throws IOException, GSSException
+   {
+      byte type = (byte) is.read();
+      int sequenceLength = NegTokenDecoder.readLength(is);
+
+      int leftAfter = is.available() - sequenceLength;
+
+      while (is.available() > leftAfter)
+      {
+         byte sequenceType = (byte) is.read();
+
+         switch (sequenceType)
+         {
+            case (byte) 0xa0 :
+               decodeMechTypes(is, negTokenInit);
+               break;
+            case (byte) 0xa1 :
+               decodeRequestFlags(is, negTokenInit);
+               break;
+            case (byte) 0xa2 :
+               decodeMechToken(is, negTokenInit);
+               break;
+            case (byte) 0xa3 :
+               decodeMechListMIC(is, negTokenInit);
+               break;
+            default :
+               throw new IOException("Unexpected message type");
+         }
+      }
+
+   }
+
+   /**
+    *  Decode the SPNEGO message contained witin the byte[] and return a
+    *  NegTokenInit object.
+    * 
+    * @param token - The SPNEGO message contained 
+    * with a byte[]
+    * @return The decoded NegTokenInit
+    * @throws IOException 
+    * @throws GSSException 
+    */
+   public static NegTokenInit decode(final byte[] token) throws IOException, GSSException
+   {
+      NegTokenInit negTokenInit = new NegTokenInit();
+      ByteArrayInputStream bais = new ByteArrayInputStream(token);
+      byte firstByte = (byte) bais.read();
+
+      int totalLength = NegTokenDecoder.readLength(bais);
+
+      negTokenInit.setMessageOid(new Oid(bais));
+
+      int tokenType = bais.read();
+      int remainingLength = NegTokenDecoder.readLength(bais);
+
+      decodeNegTokenInitSequence(bais, negTokenInit);
+
+      return negTokenInit;
+   }
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoder.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoderTest.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoderTest.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoderTest.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import java.io.ByteArrayInputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case to test the NegTokenInitDecoder.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenInitDecoderTest extends TestCase
+{
+
+   /**
+    * Test that the readLength method can correctly read 
+    * and decode the length.
+    *
+    */
+   public void testReadLength() throws Exception
+   {
+      NegTokenInitDecoder decoder = new NegTokenInitDecoder();
+
+      byte[] b1 = new byte[]
+      {0x01};
+      assertEquals(1, NegTokenDecoder.readLength(new ByteArrayInputStream(b1)));
+
+      byte[] b2 = new byte[]
+      {0x40};
+      assertEquals(64, NegTokenDecoder.readLength(new ByteArrayInputStream(b2)));
+
+      byte[] b3 = new byte[]
+      {0x7F};
+      assertEquals(127, NegTokenDecoder.readLength(new ByteArrayInputStream(b3)));
+
+      byte[] b4 = new byte[]
+      {(byte) 0x81, (byte) 0xFF};
+      assertEquals(255, NegTokenDecoder.readLength(new ByteArrayInputStream(b4)));
+
+      byte[] b5 = new byte[]
+      {(byte) 0x82, 0x01, 0x00};
+      assertEquals(256, NegTokenDecoder.readLength(new ByteArrayInputStream(b5)));
+
+      byte[] b6 = new byte[]
+      {(byte) 0x82, (byte) 0x80, 0x00};
+      assertEquals(32768, NegTokenDecoder.readLength(new ByteArrayInputStream(b6)));
+
+      byte[] b7 = new byte[]
+      {(byte) 0x82, (byte) 0xFF, 0x00};
+      assertEquals(65280, NegTokenDecoder.readLength(new ByteArrayInputStream(b7)));
+
+      byte[] b8 = new byte[]
+      {(byte) 0x82, (byte) 0xFF, (byte) 0xFF};
+      assertEquals(65535, NegTokenDecoder.readLength(new ByteArrayInputStream(b8)));
+
+      byte[] b9 = new byte[]
+      {(byte) 0x83, 0x01, 0x00, 0x00};
+      assertEquals(65536, NegTokenDecoder.readLength(new ByteArrayInputStream(b9)));
+
+      byte[] b10 = new byte[]
+      {(byte) 0x83, (byte) 0x80, 0x7F, (byte) 0xFF};
+      assertEquals(8421375, NegTokenDecoder.readLength(new ByteArrayInputStream(b10)));
+
+      byte[] b11 = new byte[]
+      {(byte) 0x83, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
+      assertEquals(16777215, NegTokenDecoder.readLength(new ByteArrayInputStream(b11)));
+
+   }
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenInitDecoderTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTarg.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTarg.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTarg.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,82 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import org.ietf.jgss.Oid;
+
+/**
+ * Representation of NegTokenTarg.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenTarg
+{
+   public static final Integer ACCEPT_COMPLETED = new Integer(1);
+
+   public static final Integer ACCEPT_INCOMPLETE = new Integer(2);
+
+   public static final Integer REJECTED = new Integer(3);
+
+   private Integer negResult = null;
+
+   private Oid supportedMech = null;
+
+   private byte[] responseToken = null;
+
+   private byte[] mechListMIC = null;
+
+   public Integer getNegResult()
+   {
+      return negResult;
+   }
+
+   public void setNegResult(Integer negResult)
+   {
+      this.negResult = negResult;
+   }
+
+   public Oid getSupportedMech()
+   {
+      return supportedMech;
+   }
+
+   public void setSupportedMech(Oid supportedMech)
+   {
+      this.supportedMech = supportedMech;
+   }
+
+   public byte[] getResponseToken()
+   {
+      return responseToken;
+   }
+
+   public void setResponseToken(byte[] responseToken)
+   {
+      this.responseToken = responseToken;
+   }
+
+   public byte[] getMechListMIC()
+   {
+      return mechListMIC;
+   }
+
+   public void setMechListMIC(byte[] mechListMIC)
+   {
+      this.mechListMIC = mechListMIC;
+   }
+
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTarg.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargDecoder.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargDecoder.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargDecoder.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,133 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.Oid;
+
+/**
+ * NegTokenTarg Decoder.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenTargDecoder extends NegTokenDecoder
+{
+
+   private static void decodeNegResult(final InputStream is, final NegTokenTarg negTokenTarg) throws IOException
+   {
+      int length = readLength(is);
+      byte type = (byte) is.read();
+
+      byte negResult = (byte) is.read();
+
+      switch (negResult)
+      {
+         case 0x00 :
+            negTokenTarg.setNegResult(NegTokenTarg.ACCEPT_COMPLETED);
+            break;
+         case 0x01 :
+            negTokenTarg.setNegResult(NegTokenTarg.ACCEPT_INCOMPLETE);
+            break;
+         case 0x02 :
+            negTokenTarg.setNegResult(NegTokenTarg.REJECTED);
+            break;
+         default :
+            throw new IOException("Unexpected negResult");
+      }
+   }
+
+   private static void decodeSupportedMech(final InputStream is, final NegTokenTarg negTokenTarg) throws IOException,
+         GSSException
+   {
+      int length = readLength(is);
+
+      negTokenTarg.setSupportedMech(new Oid(is));
+   }
+
+   private static void decodeResponseToken(final InputStream is, final NegTokenTarg negTokenTarg) throws IOException
+   {
+      int length = readLength(is);
+
+      byte type = (byte) is.read();
+      int tokenLength = readLength(is);
+
+      byte[] responseToken = new byte[tokenLength];
+      is.read(responseToken);
+
+      negTokenTarg.setResponseToken(responseToken);
+   }
+
+   private static void decodeMechListMIC(final InputStream is, final NegTokenTarg negTokenTarg) throws IOException
+   {
+      int length = readLength(is);
+
+      byte[] mechListMIC = new byte[length];
+      is.read(mechListMIC);
+
+      negTokenTarg.setMechListMIC(mechListMIC);
+   }
+
+   private static void decodeNegTokenTargSequence(final InputStream is, final NegTokenTarg negTokenTarg)
+         throws IOException, GSSException
+   {
+      byte type = (byte) is.read();
+      int sequenceLength = readLength(is);
+
+      int leftAfter = is.available() - sequenceLength;
+
+      while (is.available() > leftAfter)
+      {
+         byte sequenceType = (byte) is.read();
+
+         switch (sequenceType)
+         {
+            case (byte) 0xa0 :
+               decodeNegResult(is, negTokenTarg);
+               break;
+            case (byte) 0xa1 :
+               decodeSupportedMech(is, negTokenTarg);
+               break;
+            case (byte) 0xa2 :
+               decodeResponseToken(is, negTokenTarg);
+               break;
+            case (byte) 0xa3 :
+               decodeMechListMIC(is, negTokenTarg);
+               break;
+            default :
+               throw new IOException("Unexpected message type");
+         }
+      }
+
+   }
+
+   public static NegTokenTarg decode(final byte[] token) throws IOException, GSSException
+   {
+      NegTokenTarg negTokenTarg = new NegTokenTarg();
+      ByteArrayInputStream bais = new ByteArrayInputStream(token);
+
+      byte firstByte = (byte) bais.read();
+      int totalLength = readLength(bais);
+
+      decodeNegTokenTargSequence(bais, negTokenTarg);
+
+      return negTokenTarg;
+   }
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargDecoder.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoder.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoder.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoder.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,155 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.Oid;
+
+/**
+ * NegTokenTarg Encoder.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenTargEncoder extends NegTokenEncoder
+{
+
+   protected static int getTotalLength(final List tokens)
+   {
+      int length = 0;
+      Iterator it = tokens.iterator();
+      while (it.hasNext())
+      {
+         byte[] current = (byte[]) it.next();
+         length += current.length;
+      }
+
+      return length;
+   }
+
+   protected static void encodeNegTokenTarg(final List tokens)
+   {
+      byte[] constructedSequence = createTypeLength((byte) 0xa1, getTotalLength(tokens));
+
+      tokens.add(0, constructedSequence);
+   }
+
+   protected static void encodeConstructedSequence(final List tokens)
+   {
+      byte[] constructedSequence = createTypeLength((byte) 0x30, getTotalLength(tokens));
+
+      tokens.add(0, constructedSequence);
+   }
+
+   protected static void encodeNegResult(final List tokens, final Integer negResult)
+   {
+      if (negResult == null)
+         return;
+
+      byte result;
+
+      if (NegTokenTarg.ACCEPT_COMPLETED.equals(negResult))
+      {
+         result = 0x00;
+      }
+      else if (NegTokenTarg.ACCEPT_INCOMPLETE.equals(negResult))
+      {
+         result = 0x01;
+      }
+      else
+      {
+         result = 0x02;
+      }
+
+      byte[] negResultToken =
+      {(byte) 0xa0, 0x03, 0x0a, 0x01, result};
+
+      tokens.add(0, negResultToken);
+   }
+
+   protected static void encodeSupportedMech(final List tokens, final Oid supportedMech) throws GSSException
+   {
+      if (supportedMech == null)
+         return;
+
+      byte[] supportedMechToken = supportedMech.getDER();
+      byte[] sequenceLength = createTypeLength((byte) 0xa1, supportedMechToken.length);
+
+      tokens.add(0, supportedMechToken);
+      tokens.add(0, sequenceLength);
+   }
+
+   protected static void encodeResponseToken(final List tokens, final byte[] responseToken)
+   {
+      if (responseToken == null || responseToken.length == 0)
+         return;
+
+      byte[] octletLength = createTypeLength((byte) 0x04, responseToken.length);
+      byte[] sequenceLength = createTypeLength((byte) 0xa2, responseToken.length + octletLength.length);
+
+      tokens.add(0, responseToken);
+      tokens.add(0, octletLength);
+      tokens.add(0, sequenceLength);
+   }
+
+   protected static void encodeMechListMIC(final List tokens, final byte[] mechListMIC)
+   {
+      if (mechListMIC == null || mechListMIC.length == 0)
+         return;
+
+      byte[] octletLength = createTypeLength((byte) 0x04, mechListMIC.length);
+      byte[] sequenceLength = createTypeLength((byte) 0xa3, mechListMIC.length + octletLength.length);
+
+      tokens.add(0, mechListMIC);
+      tokens.add(0, octletLength);
+      tokens.add(0, sequenceLength);
+   }
+
+   protected static byte[] contructMessage(final List tokens) throws IOException
+   {
+      int length = getTotalLength(tokens);
+
+      ByteArrayOutputStream baous = new ByteArrayOutputStream(length);
+
+      Iterator it = tokens.iterator();
+      while (it.hasNext())
+      {
+         baous.write((byte[]) it.next());
+      }
+
+      return baous.toByteArray();
+   }
+
+   public static byte[] encode(final NegTokenTarg negTokenTarg) throws GSSException, IOException
+   {
+      List tokens = new LinkedList();
+
+      encodeMechListMIC(tokens, negTokenTarg.getMechListMIC());
+      encodeResponseToken(tokens, negTokenTarg.getResponseToken());
+      encodeSupportedMech(tokens, negTokenTarg.getSupportedMech());
+      encodeNegResult(tokens, negTokenTarg.getNegResult());
+      encodeConstructedSequence(tokens);
+      encodeNegTokenTarg(tokens);
+
+      return contructMessage(tokens);
+   }
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoder.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoderTest.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoderTest.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoderTest.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.spnego;
+
+import java.io.IOException;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.Oid;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for the NegTokenTargEncoder.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenTargEncoderTest extends TestCase
+{
+
+   /**
+    * Test a NegTokenTarg response can be constructed to request 
+    * an alternate supported mechanism.
+    * @throws GSSException 
+    * @throws IOException 
+    *
+    */
+   public void testSupportedMech() throws GSSException, IOException
+   {
+      NegTokenTarg targ = new NegTokenTarg();
+      targ.setNegResult(NegTokenTarg.ACCEPT_INCOMPLETE);
+      targ.setSupportedMech(new Oid("1.2.840.113554.1.2.2"));
+
+      byte[] response = NegTokenTargEncoder.encode(targ);
+
+      String responseHex = DebugHelper.convertToHex(response);
+      System.out.println(responseHex);
+   }
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/spnego/NegTokenTargEncoderTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/test/MicrosoftDecoding.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/test/MicrosoftDecoding.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/test/MicrosoftDecoding.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,312 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.BinaryCodec;
+import org.apache.commons.codec.binary.Hex;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.Oid;
+
+/**
+ * Debug code to test header as encoded by Microsoft.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class MicrosoftDecoding
+{
+
+   private static final String encoded = "YIIEygYGKwYBBQUCoIIEvjCCBLqgMDAuBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKoZIhvcSAQICAwYKKwYBBAGCNwICCqKCBIQEggSAYIIEfAYJKoZIhvcSAQICAQBuggRrMIIEZ6ADAgEFoQMCAQ6iBwMFACAAAACjggOXYYIDkzCCA4+gAwIBBaERGw9EQUxORVQuUExVUy5DT02iIDAeoAMCAQKhFzAVGwRIVFRQGw1zYW1wbGVfc2VydmVyo4IDUTCCA02gAwIBA6KCA0QEggNAF+1Zfe6/6t26s6CdqiH45+FVeFoqux5TjWAPNrhf6dCLAUJk0eY+Oth4Uve1J4HMv44IAix5Qcp1qlUchf45NQ43vf/lmz1p0jL9vdEe/icBYLnLlN7E8+SjOeDmLn4/a18sy4LN7nx1bOEgN/JVMI8xywLnVTrOyQGMzUxAeBfSaLDskP001h5haFSc+J08oToS0NYIQ4Beaj9Rn1mENcNCV9ZidNfVdrGnpkZSu1coAboRerIKg4ZPftzEJdU0RUFtSLBuHyxqxdSoFMXmzi44/uVEZi0RiMyHF9xBEifpJFTgWExc4lgOeeHp+HkWAwoDYJt5L7WDfsMf7W5gw0tmAsJOpSL6s8NYNSmv+1EKXllkF7Zs9oIa2HDdqPjlX1I2IaeobN5LBPx4j12pgfCymgcilggQyhXjLdlOPJ+31T7OugkYtqiPbrHn9OLGah6R6XzGHjPO+Siv0eCVn0vWdMoH29UZ+jS7EifkNz3J3EpN1/OpuW46E+IdupzN1hgmFHwjgA+3LSKjqTgN9BYqZeaH1R6snuMsNEhLAG6AOov/9FDhtx8pKbZmRkNzLj20vqFptPYcbNmnZ4G4EnJ9ZvM4XOqNQ12Cp19FD0vE2CBkpxYh772TUVMTuayaRDk0U0BQR3FXLge9Z1fNPU!
 2LbMQN5b0aTfGtgcOX0r7DiZ9kZM0t7AYMCVBiFvH3DvUmNcN7azdVcFKcOREmYy2Bo43mUiUAVhPbyTZJNqgPEaFdw3pgNBKBZCfySMwyRU/BKT7v09C6gDWKKuCFFNbgdZWxnj5GmYOaDsUGT1woYJFBnZO/9fjy7U/H+9x82llm9p7IPTL2C/lE05sPE5M+vRJCAL3xeGY3Q2ptmS8z28QPV0schl09CriHu/mEo7AEeJ04iQNFUVcFBdqk1a8r9Zq/M7Gjs5FN86yv4V0kTscvRthAQ4wvluFvZHtwF5VdnKWNwWHBomFgJap4zr41i6e4N6Z0S9TMcL5jQCbkao5GvYaEjxUnlDbgNDSrEKI/zxzQsE2uOfOp/nmixlz07C+xOsqYVNZgbxrPxectEjUEzzwEZq+VTSsbT9U0edBsHLv3rx8Bde4yNDde/6SBtjCBs6ADAgEDooGrBIGommHtA6iDG0no+z7tX/mAsEKHQvhjcKthP4cke9RbhgWj2aO0MgXsBm5ZyxOcNLPEwsPQPA6Jm5SU8732GQTP0MRBFjAMImuxEnrDBUDhd1lQXDoI6yv/a0E7VtrOb78HnvnS3eny1YXrMQG5Pdy5xbtVhfNESJUa2oJhBmBDlrqdeM3WohXyGHg0ujIjQ9gX9hJZJa6PzPBeJboJkv5aEacK8vLRTrWL";
+
+   private static final byte LEAD_BYTE = 0x60;
+
+   private enum DERType {
+      Integer, BitString, OctletString, ObjectIdentifier, Sequence;
+   }
+
+   private enum NegotiationToken {
+      NegTokenInit, NegTokenTarg;
+   }
+
+   private static final int readLength(final InputStream is) throws IOException
+   {
+      byte first = (byte) is.read();
+      byte masked = (byte) (first & (byte) 128);
+
+      if (masked == 0)
+      {
+         return first;
+      }
+
+      int lengthLength = first & (byte) 127;
+
+      byte[] lengthBytes = new byte[lengthLength];
+      is.read(lengthBytes);
+
+      int length = 0;
+      for (int i = 0; i < lengthLength; i++)
+      {
+         int currentPos = lengthLength - i - 1;
+         int currentLength = lengthBytes[currentPos];
+
+         if (currentLength < 0)
+         {
+            currentLength += 256;
+         }
+
+         if (i > 0)
+         {
+            currentLength = currentLength * 256 * i;
+         }
+
+         length += currentLength;
+      }
+
+      return length;
+   }
+
+   private static final int readConstructedSequenceLength(final InputStream is) throws IOException
+   {
+      is.mark(Integer.MAX_VALUE);
+
+      byte type = (byte) is.read();
+      if (type != 0x30)
+      {
+         is.reset();
+         throw new IOException("Not Constructed Sequence");
+      }
+
+      return readLength(is);
+   }
+
+   private static final DERType readType(final InputStream is) throws IOException
+   {
+      is.mark(Integer.MAX_VALUE);
+      switch (is.read())
+      {
+         case 0x02 :
+            return DERType.Integer;
+         case 0x03 :
+            return DERType.BitString;
+         case 0x04 :
+            return DERType.OctletString;
+         case 0x06 :
+            return DERType.ObjectIdentifier;
+         case 0x10 :
+            return DERType.Sequence;
+         default :
+            is.reset();
+            return null;
+      }
+   }
+
+   private static final NegotiationToken readTokenType(final InputStream is) throws IOException
+   {
+      is.mark(Integer.MAX_VALUE);
+      switch (is.read())
+      {
+         case 0xA0 :
+            return NegotiationToken.NegTokenInit;
+         case 0xA1 :
+            return NegotiationToken.NegTokenTarg;
+         default :
+            is.reset();
+            return null;
+
+      }
+   }
+
+   public static List readMechTypes(final InputStream is) throws IOException, GSSException
+   {
+      int sequenceLength = readConstructedSequenceLength(is);
+      System.out.println("sequenceLength " + sequenceLength);
+
+      int leftAfterSequence = is.available() - sequenceLength;
+      List mechTypes = new ArrayList();
+      while (is.available() > leftAfterSequence)
+      {
+         mechTypes.add(new Oid(is));
+      }
+
+      return mechTypes;
+   }
+
+   public static byte[] readMechToken(final InputStream is) throws IOException
+   {
+      int length = readLength(is);
+
+      byte[] token = new byte[length];
+      is.read(token);
+
+      return token;
+   }
+
+   public static final byte[] parse(final byte[] spnegoToken) throws IOException, GSSException
+   {
+      byte[] token = null;
+
+      ByteArrayInputStream bais = new ByteArrayInputStream(spnegoToken);
+
+      byte lead = (byte) bais.read();
+      if (lead != LEAD_BYTE)
+      {
+         System.err.println("Invalid leading byte.");
+      }
+
+      System.out.println("Length - " + readLength(bais));
+
+      Oid oid = new Oid(bais);
+      System.out.println(oid.toString());
+
+      NegotiationToken tokenType = readTokenType(bais);
+      System.out.println(tokenType.name());
+
+      int negTokenInitLength = readLength(bais);
+      System.out.println("negTokenInitLength " + negTokenInitLength);
+
+      int sequenceLength = readConstructedSequenceLength(bais);
+      System.out.println("sequenceLength " + sequenceLength);
+
+      int leftAfterSequence = bais.available() - sequenceLength;
+
+      while (bais.available() > leftAfterSequence)
+      {
+         byte type = (byte) bais.read();
+
+         int length = 0;
+         switch (type)
+         {
+            case (byte) 0xA0 :
+               System.out.println("mechTypes");
+               length = readLength(bais);
+
+               List mechTypes = readMechTypes(bais);
+               for (Object current : mechTypes)
+               {
+                  System.out.println(current.toString());
+               }
+               break;
+            case (byte) 0xA1 :
+               System.out.println("reqFlags");
+               length = readLength(bais);
+               bais.skip(length);
+               break;
+            case (byte) 0xA2 :
+               System.out.println("mechToken");
+               //length = readLength(bais);
+
+               token = readMechToken(bais);
+               char[] hex = Hex.encodeHex(token);
+
+               for (int i = 0; i < hex.length; i++)
+               {
+                  if (i % 2 == 0)
+                  {
+                     System.out.print(" 0x");
+                  }
+                  System.out.print(hex[i]);
+               }
+               System.out.println();
+
+               byte[] base64 = Base64.encodeBase64Chunked(token);
+               System.out.println(new String(base64));
+
+               break;
+            case (byte) 0xA3 :
+               System.out.println("mechListMIC");
+               length = readLength(bais);
+               bais.skip(length);
+               break;
+            default :
+               throw new IOException("Unexpected type");
+         }
+      }
+
+      System.out.println(bais.available());
+
+      return token;
+   }
+
+   /** 
+    * 
+    * @param args
+    * @throws IOException 
+    * @throws GSSException 
+    */
+   public static void main(final String[] args) throws IOException, GSSException
+   {
+      byte[] decoded = Base64.decodeBase64(encoded.getBytes());
+
+      System.out.println(encoded.indexOf("YII", 1));
+
+      System.out.println("Decoded Length " + decoded.length);
+
+      char[] result = Hex.encodeHex(decoded);
+      for (int i = 0; i < result.length; i++)
+      {
+         if (i % 2 == 0)
+         {
+            System.out.print(" 0x");
+         }
+         System.out.print(result[i]);
+      }
+
+      System.out.println();
+
+      char[] binary = BinaryCodec.toAsciiChars(decoded);
+      System.out.println("Binary Length = " + binary.length);
+      System.out.println("Bits Per Byte " + binary.length / decoded.length);
+      for (int i = 0; i < binary.length; i++)
+      {
+         if (i % 8 == 0)
+         {
+            System.out.print(" ");
+         }
+         System.out.print(binary[i]);
+      }
+      System.out.println();
+
+      for (int i = 0; i < decoded.length; i++)
+      {
+         System.out.print(" " + (int) decoded[i]);
+      }
+      System.out.println();
+
+      // Parsing Message
+      int pos = 1;
+
+      byte masked = (byte) (decoded[pos] & (byte) 127);
+      System.out.println("Masked " + (int) masked);
+      if (masked > 0)
+      {
+         System.out.println("First byte is length length");
+      }
+      else
+      {
+
+      }
+
+      parse(decoded);
+   }
+
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/test/MicrosoftDecoding.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SPNEGOValve.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SPNEGOValve.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SPNEGOValve.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,342 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.tomcat.gss;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.security.PrivilegedAction;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpSession;
+
+import org.apache.catalina.Valve;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+import org.ietf.jgss.GSSContext;
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSManager;
+import org.ietf.jgss.Oid;
+
+import com.darranl.spnego.DebugHelper;
+import com.darranl.spnego.NegTokenInit;
+import com.darranl.spnego.NegTokenInitDecoder;
+import com.darranl.spnego.NegTokenTarg;
+import com.darranl.spnego.NegTokenTargDecoder;
+import com.darranl.spnego.NegTokenTargEncoder;
+
+/**
+ * A SPNEGOValve for Kerberos authentication for web
+ * applications.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ * @version $Revision$
+ */
+public class SPNEGOValve implements Valve
+{
+
+   private static final Logger log = Logger.getLogger(SPNEGOValve.class);
+
+   private final Oid spnego;
+
+   private final Oid kerberosLegacy;
+
+   private final Oid kerberos;
+
+   private Valve next;
+
+   public SPNEGOValve() throws GSSException
+   {
+      spnego = new Oid("1.3.6.1.5.5.2");
+      kerberosLegacy = new Oid("1.2.840.48018.1.2.2");
+      kerberos = new Oid("1.2.840.113554.1.2.2");
+   }
+
+   public String getInfo()
+   {
+      return "SPNEGO Authentication Valve";
+   }
+
+   public Valve getNext()
+   {
+      return next;
+   }
+
+   public void setNext(final Valve next)
+   {
+      this.next = next;
+   }
+
+   public void backgroundProcess()
+   {
+      //log.info("backgroundProcess()");
+   }
+
+   public void invoke(final Request request, final Response response) throws IOException, ServletException
+   {
+      log.info("invoke");
+
+      boolean authenticated;
+      try
+      {
+         authenticated = authenticate(request, response);
+         log.info("authenticated=" + authenticated);
+      }
+      catch (Exception e)
+      {
+         log.warn("Authenticate Failed", e);
+         throw new IOException("Authentication failure - " + e.getMessage());
+      }
+
+      if (authenticated)
+      {
+         getNext().invoke(request, response);
+      }
+
+   }
+
+   protected boolean authenticate(final Request request, final Response response) throws Exception
+   {
+      Principal user = request.getUserPrincipal();
+
+      if (user != null)
+      {
+         log.info("There is a user");
+         return true;
+      }
+
+      // Do this early so we can get header from client before we have to authenticate.
+      String authHeader = request.getHeader("Authorization");
+
+      if (authHeader == null)
+      {
+         log.debug("No Authorization Header, sending 401");
+         response.setHeader("WWW-Authenticate", "Negotiate");
+
+         response.sendError(401);
+
+         return false;
+      }
+      // End Early
+
+      Subject server = getServerSubject();
+
+      AcceptSecContext action = new AcceptSecContext(request, response);
+
+      Object result = Subject.doAs(server, action);
+
+      if (result instanceof Exception)
+      {
+         log.info("Throwing Exception", (Exception) result);
+         throw (Exception) result;
+      }
+      else if (result instanceof Boolean)
+      {
+         return ((Boolean) result).booleanValue();
+      }
+
+      log.info("Default return false");
+      return false;
+   }
+
+   protected Subject getServerSubject() throws LoginException
+   {
+      log.info("getServerSubject");
+      LoginContext lc = new LoginContext("host");
+      lc.login();
+
+      log.info("Subject = " + lc.getSubject());
+      log.info("Logged in 'host' LoginContext");
+
+      return lc.getSubject();
+   }
+
+   private class AcceptSecContext implements PrivilegedAction
+   {
+
+      private final Request request;
+
+      private final Response response;
+
+      AcceptSecContext(final Request request, final Response response)
+      {
+         this.request = request;
+         this.response = response;
+      }
+
+      public Object run()
+      {
+         try
+         {
+            String authHeader = request.getHeader("Authorization");
+
+            if (authHeader == null)
+            {
+               log.debug("No Authorization Header, sending 401");
+               response.setHeader("WWW-Authenticate", "Negotiate");
+
+               response.sendError(401);
+
+               return Boolean.FALSE;
+            }
+
+            if (authHeader.startsWith("Negotiate ") == false)
+            {
+               return new IOException("Invalid 'Authorization' header.");
+            }
+
+            String reqEncoded = authHeader.substring(10);
+
+            log.info("Encoded '" + reqEncoded + "'");
+
+            byte[] reqToken = Base64.decodeBase64(reqEncoded.getBytes());
+            byte[] gssToken = null;
+
+            String reqHex = DebugHelper.convertToHex(reqToken);
+            log.info("Request Token '" + reqHex + "'");
+
+            if (reqToken[0] == 0x60)
+            {
+               NegTokenInit negTokenInit = NegTokenInitDecoder.decode(reqToken);
+               List mechList = negTokenInit.getMechTypes();
+
+               if (mechList.get(0).equals(kerberos))
+               {
+                  gssToken = negTokenInit.getMechToken();
+               }
+               else
+               {
+                  boolean kerberosSupported = false;
+
+                  Iterator it = mechList.iterator();
+                  while (it.hasNext() && kerberosSupported == false)
+                  {
+                     kerberosSupported = it.next().equals(kerberos);
+                  }
+
+                  NegTokenTarg negTokenTarg = new NegTokenTarg();
+
+                  if (kerberosSupported)
+                  {
+                     negTokenTarg.setNegResult(NegTokenTarg.ACCEPT_INCOMPLETE);
+                     negTokenTarg.setSupportedMech(kerberos);
+                  }
+                  else
+                  {
+                     negTokenTarg.setNegResult(NegTokenTarg.REJECTED);
+                  }
+
+                  byte[] respSpnego = NegTokenTargEncoder.encode(negTokenTarg);
+                  String respSpnegoHex = DebugHelper.convertToHex(respSpnego);
+                  log.info("SPNEGO Response '" + respSpnegoHex + "'");
+
+                  String respEncoded = new String(Base64.encodeBase64(respSpnego));
+                  response.setHeader("WWW-Authenticate", "Negotiate " + respEncoded);
+
+                  response.sendError(401);
+
+                  return Boolean.FALSE;
+               }
+
+            }
+            else if (reqToken[0] == (byte) 0xa1)
+            {
+               NegTokenTarg negTokenTarg = NegTokenTargDecoder.decode(reqToken);
+
+               gssToken = negTokenTarg.getResponseToken();
+            }
+
+            HttpSession session = request.getSession();
+
+            GSSContext context = (GSSContext) session.getAttribute("GSSContext");
+
+            if (context == null)
+            {
+               GSSManager manager = GSSManager.getInstance();
+               context = manager.createContext((GSSCredential) null);
+
+               session.setAttribute("GSSContext", context);
+            }
+
+            if (context.isEstablished())
+            {
+               return Boolean.TRUE;
+            }
+
+            String gssTokenHex = DebugHelper.convertToHex(gssToken);
+            log.info("GSS Token '" + gssTokenHex + "'");
+
+            byte[] respToken = context.acceptSecContext(gssToken, 0, gssToken.length);
+
+            if (respToken != null)
+            {
+               NegTokenTarg negTokenTarg = new NegTokenTarg();
+               negTokenTarg.setResponseToken(respToken);
+
+               byte[] respSpnego = NegTokenTargEncoder.encode(negTokenTarg);
+               String respSpnegoHex = DebugHelper.convertToHex(respSpnego);
+
+               log.info("SPNEGO Response '" + respSpnegoHex + "'");
+
+               String respEncoded = new String(Base64.encodeBase64(respSpnego));
+               response.setHeader("WWW-Authenticate", "Negotiate " + respEncoded);
+            }
+
+            if (context.isEstablished() == false)
+            {
+               response.sendError(401);
+
+               return Boolean.FALSE;
+            }
+            else
+            {
+               log.info("context.getCredDelegState() = " + context.getCredDelegState());
+               log.info("context.getMutualAuthState() = " + context.getMutualAuthState());
+               log.info("context.getSrcName() = " + context.getSrcName().toString());
+            }
+
+         }
+         catch (Exception e)
+         {
+            return e;
+         }
+
+         return Boolean.TRUE;
+
+      }
+   }
+
+   protected void debug(final NegTokenInit negTokenInit)
+   {
+      log.info("Message OID - " + negTokenInit.getMessageOid());
+      Iterator it = negTokenInit.getMechTypes().iterator();
+      while (it.hasNext())
+      {
+         Oid current = (Oid) it.next();
+         log.info("Supported Mech - " + current);
+      }
+   }
+
+
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SPNEGOValve.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SimpleValve.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SimpleValve.java	                        (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SimpleValve.java	2008-03-05 11:31:19 UTC (rev 70412)
@@ -0,0 +1,115 @@
+/*
+ * Copyright © 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
+ * by the @author tags or express copyright attribution statements applied by the 
+ * authors. All third-party contributions are distributed under license by Red Hat 
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy, 
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General 
+ * Public License, v. 2.1. This program is distributed in the hope that it will be 
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY 
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 
+ * more details. You should have received a copy of the GNU Lesser General Public License, 
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package com.darranl.tomcat.gss;
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+import javax.servlet.ServletException;
+
+import org.apache.catalina.Valve;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.log4j.Logger;
+
+/**
+ * A simple valve which logs request and response information.
+ * 
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class SimpleValve implements Valve
+{
+
+   private static final Logger log = Logger.getLogger(SimpleValve.class);
+
+   private Valve next;
+
+   public SimpleValve()
+   {
+      /*
+       * log.info("Constructor Stack Trace", new Exception()); new
+       * Exception().printStackTrace();
+       */
+   }
+
+   public void invoke(final Request request, final Response response) throws IOException, ServletException
+   {
+      // log.info("Valve Object Name '" + getObjectName().toString());
+      System.out.println("Invoke  SimpleValve");
+      log.info("URI " + request.getDecodedRequestURI());
+      log.debug("Current Stack Trace", new Exception());
+
+      Enumeration e1 = request.getAttributeNames();
+      while (e1.hasMoreElements())
+      {
+         Object element = e1.nextElement();
+         log.info("Attribute " + element);
+      }
+
+      Enumeration e2 = request.getHeaderNames();
+      while (e2.hasMoreElements())
+      {
+         String name = (String) e2.nextElement();
+         Enumeration e2_1 = request.getHeaders(name);
+         while (e2_1.hasMoreElements())
+         {
+            String value = (String) e2_1.nextElement();
+            log.info("+ Request header " + name + "=" + value);
+         }
+      }
+
+      Enumeration e3 = request.getParameterNames();
+      while (e3.hasMoreElements())
+      {
+         Object element = e3.nextElement();
+         log.info("Parameter " + element);
+      }
+
+      log.info("** Incoke Next");
+      getNext().invoke(request, response);
+      log.info("** Incoke Next - Complete");
+
+      for (String name : response.getHeaderNames())
+      {
+         for (String value : response.getHeaderValues(name))
+         {
+            log.info("- Response header " + name + "=" + value);
+         }
+      }
+   }
+
+   public String getInfo()
+   {
+      return "";
+   }
+
+   public Valve getNext()
+   {
+      return next;
+   }
+
+   public void backgroundProcess()
+   {
+   }
+
+   public void setNext(final Valve valve)
+   {
+      this.next = valve;
+   }
+
+
+}


Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation/src/main/com/darranl/tomcat/gss/SimpleValve.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-cvs-commits mailing list