You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/11/24 17:26:24 UTC
svn commit: r1038676 - in
/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec:
actions/AbstractReadHostAddresses.java kdcReqBody/actions/StoreAddresses.java
Author: kayyagari
Date: Wed Nov 24 16:26:23 2010
New Revision: 1038676
URL: http://svn.apache.org/viewvc?rev=1038676&view=rev
Log:
o abstracted reading of HostAddresses
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadHostAddresses.java
Modified:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadHostAddresses.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadHostAddresses.java?rev=1038676&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadHostAddresses.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/AbstractReadHostAddresses.java Wed Nov 24 16:26:23 2010
@@ -0,0 +1,116 @@
+/*
+ * 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.hostAddresses.HostAddressesContainer;
+import org.apache.directory.shared.kerberos.components.HostAddresses;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The abstract action used to read the HostAddresses
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractReadHostAddresses extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( AbstractReadHostAddresses.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new AbstractReadHostAddresses action.
+ */
+ public AbstractReadHostAddresses( String name )
+ {
+ super( name );
+ }
+
+
+ /**
+ * set HostAddresses on the ASN.1 object present in the container
+ *
+ * @param hostAddresses the host addresses
+ * @param container the container holding the ASN.1 object
+ */
+ protected abstract void setHostAddresses( HostAddresses hostAddresses, 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 HostAddresses
+ Asn1Decoder hostAddressesDecoder = new Asn1Decoder();
+
+ HostAddressesContainer hostAddressesContainer = new HostAddressesContainer();
+
+ // Passes the Stream to the decoder
+ hostAddressesContainer.setStream( container.getStream() );
+
+ // Decode the HostAddresses PDU
+ try
+ {
+ hostAddressesDecoder.decode( container.getStream(), hostAddressesContainer );
+ }
+ catch ( DecoderException de )
+ {
+ throw de;
+ }
+
+ // Store the HostAddresses in the container
+ HostAddresses hostAddresses = hostAddressesContainer.getHostAddresses();
+ setHostAddresses( hostAddresses, container );
+
+ // Update the expected length for the current TLV
+ tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+ // Update the parent
+ container.updateParent();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "HostAddresses : {}", hostAddresses );
+ }
+ }
+}
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java?rev=1038676&r1=1038675&r2=1038676&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReqBody/actions/StoreAddresses.java Wed Nov 24 16:26:23 2010
@@ -21,17 +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.hostAddresses.HostAddressesContainer;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadHostAddresses;
import org.apache.directory.shared.kerberos.codec.kdcReqBody.KdcReqBodyContainer;
import org.apache.directory.shared.kerberos.components.HostAddresses;
-import org.apache.directory.shared.kerberos.components.KdcReqBody;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -39,14 +31,8 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class StoreAddresses extends GrammarAction
+public class StoreAddresses extends AbstractReadHostAddresses
{
- /** The logger */
- private static final Logger LOG = LoggerFactory.getLogger( StoreAddresses.class );
-
- /** Speedup for logs */
- private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-
/**
* Instantiates a new StoreAddresses action.
@@ -60,56 +46,11 @@ public class StoreAddresses extends Gram
/**
* {@inheritDoc}
*/
- public void action( Asn1Container container ) throws DecoderException
+ @Override
+ protected void setHostAddresses( HostAddresses hostAddresses, Asn1Container container )
{
KdcReqBodyContainer kdcReqBodyContainer = ( KdcReqBodyContainer ) container;
-
- TLV tlv = kdcReqBodyContainer.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 ) );
- }
-
- KdcReqBody kdcReqBody = kdcReqBodyContainer.getKdcReqBody();
-
- // Now, let's decode the HostAddresses
- Asn1Decoder hostAddressesDecoder = new Asn1Decoder();
-
- HostAddressesContainer hostAddressesContainer = new HostAddressesContainer();
-
- // Passes the Stream to the decoder
- hostAddressesContainer.setStream( container.getStream() );
-
- // Decode the HostAddresses PDU
- try
- {
- hostAddressesDecoder.decode( container.getStream(), hostAddressesContainer );
- }
- catch ( DecoderException de )
- {
- throw de;
- }
-
- // Store the HostAddresses in the container
- HostAddresses hostAddresses = hostAddressesContainer.getHostAddresses();
- kdcReqBody.setAddresses( hostAddresses );
-
- // Update the expected length for the current TLV
- tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
-
- // Update the parent
- container.updateParent();
-
+ kdcReqBodyContainer.getKdcReqBody().setAddresses( hostAddresses );
container.setGrammarEndAllowed( true );
-
- if ( IS_DEBUG )
- {
- LOG.debug( "Addresses : {}", hostAddresses );
- }
}
}