directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1039991 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/principalName/ main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/ test/java/org/apache/directory/share...
Date Mon, 29 Nov 2010 00:19:58 GMT
Author: elecharny
Date: Mon Nov 29 00:19:58 2010
New Revision: 1039991

URL: http://svn.apache.org/viewvc?rev=1039991&view=rev
Log:
Reviewed the PrincipalName classes, added some logs, tests etc...

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/PrincipalNameInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameString.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameStatesEnum.java?rev=1039991&r1=1039990&r2=1039991&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameStatesEnum.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameStatesEnum.java
Mon Nov 29 00:19:58 2010
@@ -33,9 +33,6 @@ import org.apache.directory.shared.kerbe
  */
 public enum PrincipalNameStatesEnum implements States
 {
-    // ~ Static fields/initializers
-    // -----------------------------------------------------------------
-
     // Start
     START_STATE,                            // 0
     

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/PrincipalNameInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/PrincipalNameInit.java?rev=1039991&r1=1039990&r2=1039991&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/PrincipalNameInit.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/PrincipalNameInit.java
Mon Nov 29 00:19:58 2010
@@ -20,12 +20,11 @@
 package org.apache.directory.shared.kerberos.codec.principalName.actions;
 
 
+import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
 import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.i18n.I18n;
-import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
 import org.apache.directory.shared.kerberos.codec.principalName.PrincipalNameContainer;
 import org.apache.directory.shared.kerberos.components.PrincipalName;
 import org.slf4j.Logger;
@@ -40,7 +39,7 @@ import org.slf4j.LoggerFactory;
 public class PrincipalNameInit extends GrammarAction
 {
     /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+    private static final Logger LOG = LoggerFactory.getLogger( PrincipalNameInit.class );
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
@@ -67,10 +66,10 @@ public class PrincipalNameInit extends G
         // The Length should not be null
         if ( tlv.getLength() == 0 )
         {
-            LOG.error( I18n.err( I18n.ERR_04066 ) );
+            LOG.error( I18n.err( I18n.ERR_744_NULL_PDU_LENGTH ) );
 
             // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+            throw new DecoderException( I18n.err( I18n.ERR_744_NULL_PDU_LENGTH ) );
         }
         
         // We have to create a PrincipalName object here

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameString.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameString.java?rev=1039991&r1=1039990&r2=1039991&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameString.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameString.java
Mon Nov 29 00:19:58 2010
@@ -20,14 +20,13 @@
 package org.apache.directory.shared.kerberos.codec.principalName.actions;
 
 
+import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
 import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.kerberos.KerberosUtils;
-import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
 import org.apache.directory.shared.kerberos.codec.principalName.PrincipalNameContainer;
 import org.apache.directory.shared.kerberos.components.PrincipalName;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -43,7 +42,7 @@ import org.slf4j.LoggerFactory;
 public class StoreNameString extends GrammarAction
 {
     /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+    private static final Logger LOG = LoggerFactory.getLogger( StoreNameString.class );
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
@@ -70,10 +69,10 @@ public class StoreNameString extends Gra
         // The Length should not be null
         if ( tlv.getLength() == 0 )
         {
-            LOG.error( I18n.err( I18n.ERR_04066 ) );
+            LOG.error( I18n.err( I18n.ERR_744_NULL_PDU_LENGTH ) );
 
             // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+            throw new DecoderException( I18n.err( I18n.ERR_744_NULL_PDU_LENGTH ) );
         }
         
         // Get the principalName
@@ -96,10 +95,13 @@ public class StoreNameString extends Gra
         }
         else
         {
-            LOG.error( I18n.err( I18n.ERR_04066 ) );
+            String valBytes = StringTools.dumpBytes( value.getData() );
+            String valStr = StringTools.utf8ToString( value.getData() );
+            String valAll = valBytes + "/" + valStr;
+            LOG.error( I18n.err( I18n.ERR_745_NOT_A_KERBEROS_STRING, valAll ) );
     
             // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+            throw new DecoderException( I18n.err( I18n.ERR_745_NOT_A_KERBEROS_STRING, valAll
) );
         }
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java?rev=1039991&r1=1039990&r2=1039991&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java
Mon Nov 29 00:19:58 2010
@@ -21,18 +21,10 @@ package org.apache.directory.shared.kerb
 
 
 import org.apache.directory.shared.asn1.ber.Asn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
-import org.apache.directory.shared.asn1.ber.tlv.TLV;
-import org.apache.directory.shared.asn1.ber.tlv.Value;
-import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.asn1.util.IntegerDecoder;
-import org.apache.directory.shared.asn1.util.IntegerDecoderException;
-import org.apache.directory.shared.i18n.I18n;
-import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+import org.apache.directory.shared.asn1.codec.actions.AbstractReadInteger;
 import org.apache.directory.shared.kerberos.codec.principalName.PrincipalNameContainer;
 import org.apache.directory.shared.kerberos.codec.types.PrincipalNameType;
 import org.apache.directory.shared.kerberos.components.PrincipalName;
-import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,10 +34,10 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StoreNameType extends GrammarAction
+public class StoreNameType extends AbstractReadInteger
 {
     /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+    private static final Logger LOG = LoggerFactory.getLogger( StoreNameType.class );
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
@@ -63,51 +55,19 @@ public class StoreNameType extends Gramm
     /**
      * {@inheritDoc}
      */
-    public void action( Asn1Container container ) throws DecoderException
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
     {
         PrincipalNameContainer principalNameContainer = ( PrincipalNameContainer ) container;
-
-        TLV tlv = principalNameContainer.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 ) );
-        }
-        
-        // Get the principalName
         PrincipalName principalName = principalNameContainer.getPrincipalName();
         
-        Value value = tlv.getValue();
-        PrincipalNameType principalNameType = null;
-        
-        try
-        {
-            int nameType = IntegerDecoder.parse( value, PrincipalNameType.KRB_NT_UNKNOWN.getValue(),
PrincipalNameType.KRB_NT_ENTERPRISE.getValue() );
-            principalNameType = PrincipalNameType.getTypeByValue( nameType );
-
-            principalName.setNameType( principalNameType );
-
-            if ( IS_DEBUG )
-            {
-                LOG.debug( "name-type : " + nameType );
-            }
-        }
-        catch ( IntegerDecoderException ide )
-        {
-            LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ),
ide
-                .getLocalizedMessage() ) );
-
-            // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( ide.getMessage() );
-        }
+        PrincipalNameType principalNameType = PrincipalNameType.getTypeByValue( value );
+        principalName.setNameType( principalNameType );
         
         if ( IS_DEBUG )
         {
-            LOG.debug( "PrincipalName type : {}", principalNameType );
+            LOG.debug( "name-type : {}" + principalNameType );
         }
+
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java?rev=1039991&r1=1039990&r2=1039991&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java
Mon Nov 29 00:19:58 2010
@@ -172,11 +172,11 @@ public class PrincipalNameDecoderTest
     {
         Asn1Decoder kerberosDecoder = new Asn1Decoder();
 
-        ByteBuffer stream = ByteBuffer.allocate( 0x0B );
+        ByteBuffer stream = ByteBuffer.allocate( 0x06 );
         
         stream.put( new byte[]
             { 0x30, 0x04,
-                (byte)0xA0, 0x03,                 // name-type
+                (byte)0xA0, 0x02,                 // name-type
                   0x02, 0x00                      // NT-PRINCIPAL
             } );
 
@@ -336,4 +336,33 @@ public class PrincipalNameDecoderTest
         // Decode the PrincipalName PDU
         kerberosDecoder.decode( stream, principalNameContainer );
     }
+    
+    
+    /**
+     * Test the decoding of a PrincipalName with no name-type
+     */
+    @Test( expected = DecoderException.class )
+    public void testPrincipalNameNoNameType() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x24 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x22,
+                (byte)0xA1, 0x20,                 // name-string
+                  0x30, 0x1E,
+                    0x1B, 0x08, 'h', 'n', 'e', 'l', 's', 'o', 'n', '1',
+                    0x1B, 0x08, 'h', 'n', 'e', '\r', 's', 'o', 'n', '2',
+                    0x1B, 0x08, 'h', 'n', 'e', 'l', 's', 'o', 'n', '3',
+            } );
+
+        stream.flip();
+
+        // Allocate a PrincipalName Container
+        Asn1Container principalNameContainer = new PrincipalNameContainer();
+
+        // Decode the PrincipalName PDU
+        kerberosDecoder.decode( stream, principalNameContainer );
+    }
 }



Mime
View raw message