You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/11/26 00:03:56 UTC
svn commit: r1039216 - in /directory/apacheds/trunk/kerberos-codec/src:
main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/
main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/
main/java/org/apache/directory/shared...
Author: elecharny
Date: Thu Nov 25 23:03:56 2010
New Revision: 1039216
URL: http://svn.apache.org/viewvc?rev=1039216&view=rev
Log:
o Added the EncAsRepPart grammar
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartStatesEnum.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java
Modified:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/EncKdcRepPartInit.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/EncKdcRepPartInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/EncKdcRepPartInit.java?rev=1039216&r1=1039215&r2=1039216&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/EncKdcRepPartInit.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/EncKdcRepPartInit.java Thu Nov 25 23:03:56 2010
@@ -25,7 +25,6 @@ import org.apache.directory.shared.asn1.
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.KerberosMessageType;
import org.apache.directory.shared.kerberos.codec.EncKdcRepPart.EncKdcRepPartContainer;
import org.apache.directory.shared.kerberos.components.EncKdcRepPart;
import org.slf4j.Logger;
@@ -73,7 +72,7 @@ public class EncKdcRepPartInit extends G
throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
}
- EncKdcRepPart encKdcRepPart = new EncKdcRepPart( KerberosMessageType.ENC_AS_REP_PART );
+ EncKdcRepPart encKdcRepPart = new EncKdcRepPart();
encKdcRepPartContainer.setEncKdcRepPart( encKdcRepPart );
if ( IS_DEBUG )
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartContainer.java?rev=1039216&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartContainer.java Thu Nov 25 23:03:56 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.encAsRepPart;
+
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.messages.EncAsRepPart;
+
+
+/**
+ * The EncAsRepPart container stores the EncAsRepPart decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncAsRepPartContainer extends KdcReqContainer
+{
+ /** An EncAsRepPart container */
+ private EncAsRepPart encAsRepPart = new EncAsRepPart();
+
+ /**
+ * Creates a new EncAsRepPartContainer object.
+ */
+ public EncAsRepPartContainer()
+ {
+ super();
+ this.stateStack = new int[1];
+ this.grammar = EncAsRepPartGrammar.getInstance();
+ setTransition( EncAsRepPartStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the EncAsRepPart.
+ */
+ public EncAsRepPart getEncAsRepPart()
+ {
+ return encAsRepPart;
+ }
+
+
+ /**
+ * Set an EncAsRepPart Object into the container. It will be completed by the
+ * KerberosDecoder.
+ *
+ * @param encAsRepPart The EncAsRepPart to set.
+ */
+ public void setEncAsRepPart( EncAsRepPart encAsRepPart )
+ {
+ this.encAsRepPart = encAsRepPart;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java?rev=1039216&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartGrammar.java Thu Nov 25 23:03:56 2010
@@ -0,0 +1,83 @@
+/*
+ * 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.encAsRepPart;
+
+
+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.GrammarTransition;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.encAsRepPart.actions.StoreEncAsRepPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the EncAsRepPart structure. All the actions are declared
+ * in this class. As it is a singleton, these declaration are only done once. If
+ * an action is to be added or modified, this is where the work is to be done !
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class EncAsRepPartGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( EncAsRepPartGrammar.class );
+
+ /** A speedup for logger */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. EncAsRepPartGrammar is a singleton */
+ private static Grammar instance = new EncAsRepPartGrammar();
+
+
+ /**
+ * Creates a new EncAsRepPartGrammar object.
+ */
+ private EncAsRepPartGrammar()
+ {
+ setName( EncAsRepPartGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[EncAsRepPartStatesEnum.LAST_ENC_AS_REP_PART_STATE.ordinal()][256];
+
+ // ============================================================================================
+ // AS-REP
+ // ============================================================================================
+ // --------------------------------------------------------------------------------------------
+ // Transition from AS-REP init to KDC-REP
+ // --------------------------------------------------------------------------------------------
+ // EncASRepPart ::= [APPLICATION 25] EncKDCRepPart
+ super.transitions[EncAsRepPartStatesEnum.START_STATE.ordinal()][KerberosConstants.ENC_AS_REP_PART_TAG] = new GrammarTransition(
+ EncAsRepPartStatesEnum.START_STATE, EncAsRepPartStatesEnum.ENC_AS_REP_PART_STATE, KerberosConstants.ENC_AS_REP_PART_TAG,
+ new StoreEncAsRepPart() );
+ }
+
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the EncAsRepPart Grammar
+ */
+ public static Grammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartStatesEnum.java?rev=1039216&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/EncAsRepPartStatesEnum.java Thu Nov 25 23:03:56 2010
@@ -0,0 +1,105 @@
+/*
+ * 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.encAsRepPart;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.States;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+
+
+/**
+ * This class store the EncAsRepPart grammar's constants. It is also used for debugging
+ * purpose
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum EncAsRepPartStatesEnum implements States
+{
+ // Start
+ START_STATE, // 0
+
+ // ----- EncAsRepPart message --------------------------------------
+ ENC_AS_REP_PART_STATE, // 1
+
+ // End
+ LAST_ENC_AS_REP_PART_STATE; // 2
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "ENC_AS_REP_PART_GRAMMAR";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( Grammar grammar )
+ {
+ if ( grammar instanceof KerberosMessageGrammar )
+ {
+ return "ENC_AS_REP_PART_GRAMMAR";
+ }
+ else
+ {
+ return "UNKNOWN GRAMMAR";
+ }
+ }
+
+
+ /**
+ * Get the string representing the state
+ *
+ * @param state The state number
+ * @return The String representing the state
+ */
+ public String getState( int state )
+ {
+ return ( ( state == LAST_ENC_AS_REP_PART_STATE.ordinal() ) ? "ENC_AS_REP_PART_END_STATE" : name() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == LAST_ENC_AS_REP_PART_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public EncAsRepPartStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java?rev=1039216&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encAsRepPart/actions/StoreEncAsRepPart.java Thu Nov 25 23:03:56 2010
@@ -0,0 +1,111 @@
+/*
+ * 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.encAsRepPart.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.EncKdcRepPart.EncKdcRepPartContainer;
+import org.apache.directory.shared.kerberos.codec.encAsRepPart.EncAsRepPartContainer;
+import org.apache.directory.shared.kerberos.components.EncKdcRepPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to add a EncAsRepPart object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreEncAsRepPart 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 EncAsRepPart action.
+ */
+ public StoreEncAsRepPart()
+ {
+ super( "Add an EncAsRepPart instance" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ EncAsRepPartContainer encAsRepPartContainer = ( EncAsRepPartContainer ) container;
+
+ TLV tlv = encAsRepPartContainer.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 EncKdcRepPart
+ Asn1Decoder encKdcRepPartDecoder = new Asn1Decoder();
+
+ EncKdcRepPartContainer encKdcRepPartContainer = new EncKdcRepPartContainer();
+ encKdcRepPartContainer.setStream( container.getStream() );
+
+ // Decode the EncKdcRepPart PDU
+ try
+ {
+ encKdcRepPartDecoder.decode( container.getStream(), encKdcRepPartContainer );
+ }
+ catch ( DecoderException de )
+ {
+ throw de;
+ }
+
+ // Update the expected length for the current TLV
+ tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+ // Update the parent
+ container.updateParent();
+
+ EncKdcRepPart encKdcRepPart = encKdcRepPartContainer.getEncKdcRepPart();
+
+ encAsRepPartContainer.getEncAsRepPart().setEncKdcRepPart( encKdcRepPart );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "AS-REP : {}", encKdcRepPart );
+ }
+
+ container.setGrammarEndAllowed( true );
+ }
+}
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java?rev=1039216&r1=1039215&r2=1039216&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java Thu Nov 25 23:03:56 2010
@@ -24,15 +24,14 @@ import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
import org.apache.directory.shared.asn1.ber.tlv.TLV;
import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
import org.apache.directory.shared.asn1.ber.tlv.Value;
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.kerberos.KerberosConstants;
-import org.apache.directory.shared.kerberos.KerberosMessageType;
import org.apache.directory.shared.kerberos.KerberosTime;
import org.apache.directory.shared.kerberos.flags.TicketFlags;
-import org.apache.directory.shared.kerberos.messages.KerberosMessage;
import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,7 +60,7 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class EncKdcRepPart extends KerberosMessage
+public class EncKdcRepPart extends AbstractAsn1Object
{
/** The logger */
private static final Logger log = LoggerFactory.getLogger( EncKdcRepPart.class );
@@ -119,9 +118,8 @@ public class EncKdcRepPart extends Kerbe
/**
* Creates a new instance of EncKdcRepPart.
*/
- public EncKdcRepPart( KerberosMessageType msgType )
+ public EncKdcRepPart()
{
- super( msgType );
}
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java?rev=1039216&r1=1039215&r2=1039216&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/EncAsRepPart.java Thu Nov 25 23:03:56 2010
@@ -37,8 +37,11 @@ import org.apache.directory.shared.kerbe
* </pre>
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class EncAsRepPart extends EncKdcRepPart
+public class EncAsRepPart extends KerberosMessage
{
+ /** The EncKdcRepPart */
+ private EncKdcRepPart encKdcRepPart;
+
// Storage for computed lengths
private transient int encKdcRepPartLength;
@@ -50,6 +53,24 @@ public class EncAsRepPart extends EncKdc
super( KerberosMessageType.ENC_AS_REP_PART );
}
+
+ /**
+ * @return the encKdcRepPart
+ */
+ public EncKdcRepPart getEncKdcRepPart()
+ {
+ return encKdcRepPart;
+ }
+
+
+ /**
+ * @param encKdcRepPart the encKdcRepPart to set
+ */
+ public void setEncKdcRepPart( EncKdcRepPart encKdcRepPart )
+ {
+ this.encKdcRepPart = encKdcRepPart;
+ }
+
/**
* Compute the EncAsRepPart length
@@ -63,7 +84,7 @@ public class EncAsRepPart extends EncKdc
*/
public int computeLength()
{
- encKdcRepPartLength = super.computeLength();
+ encKdcRepPartLength = encKdcRepPart.computeLength();
return 1 + TLV.getNbBytes( encKdcRepPartLength ) + encKdcRepPartLength;
}
@@ -87,7 +108,7 @@ public class EncAsRepPart extends EncKdc
buffer.put( TLV.getBytes( encKdcRepPartLength ) );
// The EncKdcRepPart --------------------------------------------------------
- super.encode( buffer );
+ encKdcRepPart.encode( buffer );
return buffer;
}
Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java?rev=1039216&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncAsRepPartDecoderTest.java Thu Nov 25 23:03:56 2010
@@ -0,0 +1,197 @@
+/*
+ * 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;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.asRep.AsRepContainer;
+import org.apache.directory.shared.kerberos.codec.encAsRepPart.EncAsRepPartContainer;
+import org.apache.directory.shared.kerberos.messages.EncAsRepPart;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for a EncAsRepPart
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class EncAsRepPartDecoderTest
+{
+ /**
+ * Test the decoding of a EncAsRepPart message
+ */
+ @Test
+ public void testDecodeFullEncAsRepPart() throws Exception
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0xA2 );
+
+ stream.put( new byte[]
+ {
+ 0x79, (byte)0x81, (byte)0x9F,
+ 0x30, (byte)0x81, (byte)0x9C,
+ (byte)0xA0, 0x11,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA1, 0x08,
+ 0x04, 0x06,
+ 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+ (byte)0xA1, 0x36,
+ 0x30, 0x34,
+ 0x30, 0x18,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x11,
+ 0x18, 0x0F,
+ 0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+ 0x30, 0x18,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x11,
+ 0x18, 0x0F,
+ 0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+ (byte)0xA2, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA4, 0x07,
+ 0x03, 0x05, 0x00, 0x40, 0x00, 0x00, 0x00,
+ (byte)0xA5, 0x11,
+ 0x18, 0x0F,
+ 0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+ (byte)0xA7, 0x11,
+ 0x18, 0x0F,
+ 0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+ (byte)0xA9, 0x06,
+ 0x1B, 0x04, 'a', 'b', 'c', 'd',
+ (byte)0xAA, 0x13,
+ 0x30, 0x11,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+ });
+
+ stream.flip();
+
+ // Allocate a EncAsRepPart Container
+ EncAsRepPartContainer encAsRepPartContainer = new EncAsRepPartContainer();
+ encAsRepPartContainer.setStream( stream );
+
+ // Decode the EncAsRepPart PDU
+ try
+ {
+ kerberosDecoder.decode( stream, encAsRepPartContainer );
+ }
+ catch ( DecoderException de )
+ {
+ fail( de.getMessage() );
+ }
+
+ EncAsRepPart encAsRepPart = encAsRepPartContainer.getEncAsRepPart();
+
+ // Check the encoding
+ int length = encAsRepPart.computeLength();
+
+ // Check the length
+ assertEquals( 0xA2, length );
+
+ // Check the encoding
+ ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+
+ try
+ {
+ encodedPdu = encAsRepPart.encode( encodedPdu );
+
+ // Check the length
+ assertEquals( 0xA2, encodedPdu.limit() );
+ }
+ catch ( EncoderException ee )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * Test the decoding of a EncAsRepPart with nothing in it
+ */
+ @Test( expected = DecoderException.class)
+ public void testEncAsRepPartEmpty() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+
+ stream.put( new byte[]
+ { 0x79, 0x00 } );
+
+ stream.flip();
+
+ // Allocate a EncAsRepPart Container
+ Asn1Container encAsRepPartContainer = new AsRepContainer();
+
+ // Decode the EncAsRepPart PDU
+ kerberosDecoder.decode( stream, encAsRepPartContainer );
+ fail();
+ }
+
+
+ /**
+ * Test the decoding of a EncAsRepPart with empty EncKdcRepPart tag
+ */
+ @Test( expected = DecoderException.class)
+ public void testEncAsRepPartEmptyEncKdcRepPart() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+
+ stream.put( new byte[]
+ {
+ 0x79, 0x02,
+ 0x30, 0x00
+ } );
+
+ stream.flip();
+
+ // Allocate a EncAsRepPart Container
+ Asn1Container encAsRepPartContainer = new EncAsRepPartContainer();
+ encAsRepPartContainer.setStream( stream );
+
+ // Decode the EncAsRepPart PDU
+ kerberosDecoder.decode( stream, encAsRepPartContainer );
+ fail();
+ }
+}