directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1037787 - in /directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec: actions/AbstractReadEncryptedPart.java kdcRep/actions/StoreEncPart.java
Date Mon, 22 Nov 2010 17:31:14 GMT
Author: kayyagari
Date: Mon Nov 22 17:31:13 2010
New Revision: 1037787

URL: http://svn.apache.org/viewvc?rev=1037787&view=rev
Log:
o abstracted the action code to read EncryptionData 

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadEncryptedPart.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadEncryptedPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadEncryptedPart.java?rev=1037787&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadEncryptedPart.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadEncryptedPart.java
Mon Nov 22 17:31:13 2010
@@ -0,0 +1,118 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+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.encryptedData.EncryptedDataContainer;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to read the EncryptedData
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractReadEncryptedPart extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new AbstractReadEncryptedPart action.
+     */
+    public AbstractReadEncryptedPart( String name )
+    {
+        super( name );
+    }
+
+
+    /**
+     * 
+     * set the EncryptedData on the ASN.1 object present in the container
+     *
+     * @param encryptedData the encrypted data
+     * @param container the container holding ASN.1 object
+     */
+    protected abstract void setEncryptedData( EncryptedData encryptedData, Asn1Container
container );
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public final void action( Asn1Container container ) throws DecoderException
+    {
+        TLV tlv = container.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 encryptedDataDecoder = new Asn1Decoder();
+
+        EncryptedDataContainer encryptedDataContainer = new EncryptedDataContainer();
+        encryptedDataContainer.setStream( container.getStream() );
+
+        // Decode the Ticket PDU
+        try
+        {
+            encryptedDataDecoder.decode( container.getStream(), encryptedDataContainer );
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+
+        EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "EncryptedData : " + encryptedData );
+        }
+
+        setEncryptedData( encryptedData, container );
+        
+        // Update the TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+
+        container.setGrammarEndAllowed( true );
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java?rev=1037787&r1=1037786&r2=1037787&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java
Mon Nov 22 17:31:13 2010
@@ -21,18 +21,9 @@ 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.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.encryptedData.EncryptedDataContainer;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadEncryptedPart;
 import org.apache.directory.shared.kerberos.codec.kdcRep.KdcRepContainer;
 import org.apache.directory.shared.kerberos.components.EncryptedData;
-import org.apache.directory.shared.kerberos.components.KdcRep;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -40,14 +31,8 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StoreEncPart extends GrammarAction
+public class StoreEncPart extends AbstractReadEncryptedPart
 {
-    /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
-
-    /** Speedup for logs */
-    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-
 
     /**
      * Instantiates a new TicketEncPart action.
@@ -61,52 +46,12 @@ public class StoreEncPart extends Gramma
     /**
      * {@inheritDoc}
      */
-    public void action( Asn1Container container ) throws DecoderException
+    @Override
+    protected void setEncryptedData( EncryptedData encryptedData, Asn1Container container
)
     {
         KdcRepContainer kdcRepContainer = ( KdcRepContainer ) container;
-
-        TLV tlv = kdcRepContainer.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 encryptedDataDecoder = new Asn1Decoder();
+        kdcRepContainer.getKdcRep().setEncPart( encryptedData );
         
-        EncryptedDataContainer encryptedDataContainer = new EncryptedDataContainer();
-        encryptedDataContainer.setStream( container.getStream() );
-
-        // Decode the Ticket PDU
-        try
-        {
-            encryptedDataDecoder.decode( container.getStream(), encryptedDataContainer );
-        }
-        catch ( DecoderException de )
-        {
-            throw de;
-        }
-
-        EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
-        KdcRep kdcRep = kdcRepContainer.getKdcRep();
-        kdcRep.setEncPart( encryptedData );
-
-        if ( IS_DEBUG )
-        {
-            LOG.debug( "EncryptedData : " + encryptedData );
-        }
-
-        // Update the TLV
-        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
-
-        // Update the parent
-        container.updateParent();
-
         container.setGrammarEndAllowed( true );
     }
 }



Mime
View raw message