directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1032120 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/ main/java/org/apache/directory/shared/kerberos/codec/actions/ main/java/org/apache/directory/shared/kerberos/codec/ticket/ mai...
Date Sat, 06 Nov 2010 17:35:47 GMT
Author: elecharny
Date: Sat Nov  6 17:35:47 2010
New Revision: 1032120

URL: http://svn.apache.org/viewvc?rev=1032120&view=rev
Log:
o Calling the PrincipalName grammar from the Ticket grammar

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/CheckNotNullLength.java
      - copied, changed from r1031917, directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java
Removed:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java?rev=1032120&r1=1032119&r2=1032120&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
Sat Nov  6 17:35:47 2010
@@ -21,6 +21,7 @@ package org.apache.directory.shared.kerb
 
 
 import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.ber.grammar.AbstractGrammar;
 import org.apache.directory.shared.asn1.ber.grammar.Grammar;
 import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
@@ -33,10 +34,11 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.util.IntegerDecoderException;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.kerberos.KerberosConstants;
-import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
-import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameInit;
+import org.apache.directory.shared.kerberos.codec.principalName.PrincipalNameContainer;
 import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameNameString;
 import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameNameType;
+import org.apache.directory.shared.kerberos.codec.ticket.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.components.PrincipalName;
 import org.apache.directory.shared.kerberos.messages.Ticket;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -231,19 +233,101 @@ public final class KerberosMessageGramma
         //         sname           [2] 
         super.transitions[KerberosStatesEnum.TICKET_REALM_STATE.ordinal()][KerberosConstants.TICKET_SNAME_TAG]
= new GrammarTransition(
             KerberosStatesEnum.TICKET_REALM_STATE, KerberosStatesEnum.TICKET_SNAME_TAG_STATE,
KerberosConstants.TICKET_SNAME_TAG,
-            new CheckNotNullLength() );
+            new GrammarAction( "Kerberos Ticket principalName" )
+            {
+                public void action( Asn1Container container ) throws DecoderException
+                {
+                    KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer
) container;
+
+                    TLV tlv = kerberosMessageContainer.getCurrentTLV();
+
+                    // The Length should not be null
+                    if ( tlv.getLength() == 0 )
+                    {
+                        LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+                        // This will generate a PROTOCOL_ERROR
+                        throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+                    }
+                    
+                    // Now, let's decode the PrincipalName
+                    Asn1Decoder principalNameDecoder = new Asn1Decoder();
+                    
+                    PrincipalNameContainer principalNameContainer = new PrincipalNameContainer();
+
+                    // Decode the Ticket PDU
+                    try
+                    {
+                        principalNameDecoder.decode( container.getStream(), principalNameContainer
);
+                    }
+                    catch ( DecoderException de )
+                    {
+                        throw de;
+                    }
+
+                    PrincipalName principalName = principalNameContainer.getPrincipalName();
+                    Ticket ticket = kerberosMessageContainer.getTicket();
+                    ticket.setSName( principalName );
+
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "PrincipalName : " + kerberosMessageContainer );
+                    }
+                }
+            } );
+
 
         // --------------------------------------------------------------------------------------------
-        // Transition from sname tag to PrincipalName init
+        // Transition from sname tag to enc-part tag
         // --------------------------------------------------------------------------------------------
         // Ticket          ::= [APPLICATION 1] SEQUENCE { 
         //         ...
         //         sname           [2] PrincipalName,
-        //
-        // PrincipalName   ::= SEQUENCE {
-        super.transitions[KerberosStatesEnum.TICKET_SNAME_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
-            KerberosStatesEnum.TICKET_SNAME_TAG_STATE, KerberosStatesEnum.PRINCIPAL_NAME_STATE,
UniversalTag.SEQUENCE.getValue(),
-            new PrincipalNameInit() );
+        //         enc-part        [3]
+        // 
+        super.transitions[KerberosStatesEnum.TICKET_SNAME_TAG_STATE.ordinal()][KerberosConstants.TICKET_ENC_PART_TAG]
= new GrammarTransition(
+            KerberosStatesEnum.TICKET_SNAME_TAG_STATE, KerberosStatesEnum.TICKET_ENC_PART_TAG_STATE,
KerberosConstants.TICKET_ENC_PART_TAG,
+            new GrammarAction( "Kerberos Ticket principalName" )
+            {
+                public void action( Asn1Container container ) throws DecoderException
+                {
+                    KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer
) container;
+
+                    TLV tlv = kerberosMessageContainer.getCurrentTLV();
+
+                    // The Length should not be null
+                    if ( tlv.getLength() == 0 )
+                    {
+                        LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+                        // This will generate a PROTOCOL_ERROR
+                        throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+                    }
+                    
+                    // Now, let's decode the PrincipalName
+                    Asn1Decoder principalNameDecoder = new Asn1Decoder();
+                    
+                    PrincipalNameContainer principalNameContainer = new PrincipalNameContainer();
+
+                    // Decode the Ticket PDU
+                    try
+                    {
+                        principalNameDecoder.decode( container.getStream(), principalNameContainer
);
+                    }
+                    catch ( DecoderException de )
+                    {
+                        throw de;
+                    }
+
+                    PrincipalName principalName = principalNameContainer.getPrincipalName();
+                    kerberosMessageContainer.setPrincipalName( principalName );
+
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "PrincipalName : " + kerberosMessageContainer );
+                    }
+                }
+            } );
         
         // ============================================================================================
         // PrincipalName 

Copied: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/CheckNotNullLength.java
(from r1031917, directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/CheckNotNullLength.java?p2=directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/CheckNotNullLength.java&p1=directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java&r1=1031917&r2=1032120&rev=1032120&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/CheckNotNullLength.java
Sat Nov  6 17:35:47 2010
@@ -17,7 +17,7 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.shared.kerberos.codec.actions;
+package org.apache.directory.shared.kerberos.codec.ticket.actions;
 
 
 import org.apache.directory.shared.asn1.ber.Asn1Container;

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java?rev=1032120&r1=1032119&r2=1032120&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PrincipalName.java
Sat Nov  6 17:35:47 2010
@@ -443,7 +443,7 @@ public class PrincipalName extends Abstr
     {
         StringBuilder sb = new StringBuilder();
 
-        sb.append( "PincipalName : {\n" );
+        sb.append( "PrincipalName : {\n" );
 
         sb.append( "    name-type: " ).append( nameType.name() ).append( '\n' );
 

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java?rev=1032120&r1=1032119&r2=1032120&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
Sat Nov  6 17:35:47 2010
@@ -65,12 +65,12 @@ public class TicketDecoderTest
                     0x1B, 0x0B, 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
                   (byte)0xA2, 0x14,                     // sname
                     0x30, 0x12,
-                      (byte)0xA1, 0x03,                 // name-type
+                      (byte)0xA0, 0x03,                 // name-type
                         0x02, 0x01, 0x01,               // NT-PRINCIPAL
-                      (byte)0xA2, 0x0B,                 // name-string
+                      (byte)0xA1, 0x0B,                 // name-string
                         0x30, 0x09,
                           0x1B, 0x07, 'h', 'n', 'e', 'l', 's', 'o', 'n',
-                      (byte)0xA3, 0x02, 0x01, 0x02      // enc-part
+                  (byte)0xA3, 0x02, 0x01, 0x02      // enc-part
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -78,6 +78,7 @@ public class TicketDecoderTest
 
         // Allocate a KerberosMessage Container
         Asn1Container kerberosMessageContainer = new KerberosMessageContainer();
+        kerberosMessageContainer.setStream( stream );
 
         // Decode the Ticket PDU
         try



Mime
View raw message