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/20 17:23:39 UTC
svn commit: r1037257 - in /directory/apacheds/trunk/kerberos-codec/src:
main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/
main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/
main/java/org/apache/directory/shared/ke...
Author: kayyagari
Date: Sat Nov 20 16:23:38 2010
New Revision: 1037257
URL: http://svn.apache.org/viewvc?rev=1037257&view=rev
Log:
o implementation of KRB-SAFE-BODY codec
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyStatesEnum.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/KrbSafeBodyInit.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreRecipientAddress.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSenderAddress.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSeqNumber.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreTimestamp.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUsec.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUserData.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KrbSafeBody.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyContainer.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyContainer.java Sat Nov 20 16:23:38 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.krbSafeBody;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.KrbSafeBody;
+
+
+/**
+ * The KrbSafeBody container stores the KRB-SAFE-BODY decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbSafeBodyContainer extends AbstractContainer
+{
+ /** An KRB-SAFE-BODY container */
+ private KrbSafeBody krbSafeBody;
+
+ /**
+ * Creates a new KrbSafeBodyContainer object.
+ */
+ public KrbSafeBodyContainer()
+ {
+ super();
+ this.stateStack = new int[1];
+ this.grammar = KrbSafeBodyGrammar.getInstance();
+ setTransition( KrbSafeBodyStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the KrbSafeBody.
+ */
+ public KrbSafeBody getKrbSafeBody()
+ {
+ return krbSafeBody;
+ }
+
+
+ /**
+ * Set a KrbSafeBody Object into the container. It will be completed by the
+ * KerberosDecoder.
+ *
+ * @param krbSafeBody The KrbSafeBody to set.
+ */
+ public void setKrbSafeBody( KrbSafeBody krbSafeBody )
+ {
+ this.krbSafeBody = krbSafeBody;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,219 @@
+/*
+ * 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.krbSafeBody;
+
+
+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.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.actions.KrbSafeBodyInit;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.actions.StoreRecipientAddress;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.actions.StoreSenderAddress;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.actions.StoreSeqNumber;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.actions.StoreTimestamp;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.actions.StoreUsec;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.actions.StoreUserData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the KrbSafeBody 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 KrbSafeBodyGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( KrbSafeBodyGrammar.class );
+
+ /** A speedup for logger */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. KrbSafeBodyGrammar is a singleton */
+ private static Grammar instance = new KrbSafeBodyGrammar();
+
+
+ /**
+ * Creates a new KrbSafeBodyGrammar object.
+ */
+ private KrbSafeBodyGrammar()
+ {
+ setName( KrbSafeBodyGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[KrbSafeBodyStatesEnum.LAST_KRB_SAFE_BODY_STATE.ordinal()][256];
+
+ // ============================================================================================
+ // KrbSafeBody
+ // ============================================================================================
+ // --------------------------------------------------------------------------------------------
+ // Transition from KrbSafeBody init to KrbError seq
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ super.transitions[KrbSafeBodyStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.START_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_TAG_STATE, UniversalTag.SEQUENCE.getValue(),
+ new KrbSafeBodyInit() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from KrbSafeBody seq to user-data tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // user-data [0]
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_TAG_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_USER_DATA_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_TAG_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_USER_DATA_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from user-data tag to user-data value
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // user-data [0] OCTET STRING
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_TAG_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE, UniversalTag.OCTET_STRING.getValue(),
+ new StoreUserData() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from user-data value to timestamp tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // timestamp [1]
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_TIMESTAMP_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_TIMESTAMP_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_TIMESTAMP_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from timestamp tag to timestamp value
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // timestamp [1] KerberosTime OPTIONAL
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_TIMESTAMP_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME.getValue()] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_TIMESTAMP_TAG_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_TIMESTAMP_STATE, UniversalTag.GENERALIZED_TIME.getValue(),
+ new StoreTimestamp() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from timestamp value to usec tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // usec [2]
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_TIMESTAMP_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_USEC_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_TIMESTAMP_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_USEC_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from usec tag to usec value
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // usec [2] Microseconds OPTIONAL
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_TAG_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_STATE, UniversalTag.INTEGER.getValue(),
+ new StoreUsec() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from usec value to seq-number tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // seq-number [3]
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_SEQ_NUMBER_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_NUMBER_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_SEQ_NUMBER_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from seq-number tag to seq-number value
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // seq-number [3] UInt32 OPTIONAL
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_NUMBER_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_NUMBER_TAG_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_NUMBER_STATE, UniversalTag.INTEGER.getValue(),
+ new StoreSeqNumber() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from seq-number to s-address tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // s-address [4] HostAddress
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_NUMBER_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_NUMBER_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SENDER_ADDRESS_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG,
+ new StoreSenderAddress() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from s-address tag to r-address tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // r-address [5] HostAddress
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SENDER_ADDRESS_TAG_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_RECIPIENT_ADDRESS_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SENDER_ADDRESS_TAG_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_RECIPIENT_ADDRESS_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_RECIPIENT_ADDRESS_TAG,
+ new StoreRecipientAddress() );
+
+ //----------------------------- OPTIONAL transitions ---------------------------
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from user-data value to usec tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // usec [2]
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_USEC_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_USEC_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from user-data value to seq-number tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // seq-number [3]
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_SEQ_NUMBER_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SEQ_NUMBER_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_SEQ_NUMBER_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from user-data value to s-address tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // s-address [4]
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SENDER_ADDRESS_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from usec value to s-address tag
+ // --------------------------------------------------------------------------------------------
+ // KRB-SAFE-BODY ::= SEQUENCE {
+ // s-address [4]
+ super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG] = new GrammarTransition(
+ KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SENDER_ADDRESS_TAG_STATE, KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG,
+ new CheckNotNullLength() );
+ }
+
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the KRB-SAFE-BODY Grammar
+ */
+ public static Grammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyStatesEnum.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyStatesEnum.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,121 @@
+/*
+ * 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.krbSafeBody;
+
+
+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 stores the KRB-SAFE-BODY grammar's constants. It is also used for debugging
+ * purpose
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum KrbSafeBodyStatesEnum implements States
+{
+ // Start
+ START_STATE, // 0
+
+ // ----- KRB-ERROR component --------------------------------------
+ KRB_SAFE_BODY_SEQ_TAG_STATE, // 1
+
+ KRB_SAFE_BODY_USER_DATA_TAG_STATE, // 2
+ KRB_SAFE_BODY_USER_DATA_STATE, // 3
+
+ KRB_SAFE_BODY_TIMESTAMP_TAG_STATE, // 4
+ KRB_SAFE_BODY_TIMESTAMP_STATE, // 5
+
+ KRB_SAFE_BODY_USEC_TAG_STATE, // 6
+ KRB_SAFE_BODY_USEC_STATE, // 7
+
+ KRB_SAFE_BODY_SEQ_NUMBER_TAG_STATE, // 8
+ KRB_SAFE_BODY_SEQ_NUMBER_STATE, // 9
+
+ KRB_SAFE_BODY_SENDER_ADDRESS_TAG_STATE, // 10
+
+ KRB_SAFE_BODY_RECIPIENT_ADDRESS_TAG_STATE, // 11
+
+ // End
+ LAST_KRB_SAFE_BODY_STATE; // 12
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "KRB_SAFE_BODY_GRAMMAR";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( Grammar grammar )
+ {
+ if ( grammar instanceof KerberosMessageGrammar )
+ {
+ return "KRB_SAFE_BODY_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_KRB_SAFE_BODY_STATE.ordinal() ) ? "LAST_KRB_SAFE_BODY_STATE" : name() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == LAST_KRB_SAFE_BODY_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public KrbSafeBodyStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/KrbSafeBodyInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/KrbSafeBodyInit.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/KrbSafeBodyInit.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/KrbSafeBodyInit.java Sat Nov 20 16:23:38 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.krbSafeBody.actions;
+
+
+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.krbSafeBody.KrbSafeBodyContainer;
+import org.apache.directory.shared.kerberos.components.KrbSafeBody;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the KrbSafeBody object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbSafeBodyInit extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( KrbSafeBodyInit.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new KrbSafeBodyInit action.
+ */
+ public KrbSafeBodyInit()
+ {
+ super( "Creates a KrbSafeBody instance" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ KrbSafeBodyContainer krbSafeBodyContainer = ( KrbSafeBodyContainer ) container;
+
+ TLV tlv = krbSafeBodyContainer.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 ) );
+ }
+
+ KrbSafeBody krbSafeBody = new KrbSafeBody();
+ krbSafeBodyContainer.setKrbSafeBody( krbSafeBody );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "KrbSafeBody created" );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreRecipientAddress.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreRecipientAddress.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreRecipientAddress.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreRecipientAddress.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,56 @@
+/*
+ * 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.krbSafeBody.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadHostAddress;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.KrbSafeBodyContainer;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+
+
+/**
+ * Store the r-address of KrbSafeBody.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreRecipientAddress extends AbstractReadHostAddress
+{
+
+ public StoreRecipientAddress()
+ {
+ super( "KRB-SAFE-BODY r-address" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setAddress( HostAddress hostAddress, Asn1Container container )
+ {
+ KrbSafeBodyContainer krbSafeBodyContainer = ( KrbSafeBodyContainer ) container;
+ krbSafeBodyContainer.getKrbSafeBody().setRecipientAddress( hostAddress );
+
+ container.setGrammarEndAllowed( true );
+ }
+
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSenderAddress.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSenderAddress.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSenderAddress.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSenderAddress.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,56 @@
+/*
+ * 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.krbSafeBody.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadHostAddress;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.KrbSafeBodyContainer;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+
+
+/**
+ * Store the s-address of KrbSafeBody.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreSenderAddress extends AbstractReadHostAddress
+{
+
+ public StoreSenderAddress()
+ {
+ super( "KRB-SAFE-BODY s-address" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setAddress( HostAddress hostAddress, Asn1Container container )
+ {
+ KrbSafeBodyContainer krbSafeBodyContainer = ( KrbSafeBodyContainer ) container;
+ krbSafeBodyContainer.getKrbSafeBody().setSenderAddress( hostAddress );
+
+ container.setGrammarEndAllowed( true );
+ }
+
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSeqNumber.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSeqNumber.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSeqNumber.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreSeqNumber.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.krbSafeBody.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadInteger;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.KrbSafeBodyContainer;
+
+
+/**
+ * The action used to store the KrbSafeBody seq-number
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreSeqNumber extends AbstractReadInteger
+{
+
+ /**
+ * Instantiates a new StoreSeqNumber action.
+ */
+ public StoreSeqNumber()
+ {
+ super( "KRB-SAFE-BODY seq-number" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setIntegerValue( int value, Asn1Container container )
+ {
+ KrbSafeBodyContainer krbSafeBodyContainer = ( KrbSafeBodyContainer ) container;
+ krbSafeBodyContainer.getKrbSafeBody().setSeqNumber( value );
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreTimestamp.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreTimestamp.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreTimestamp.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreTimestamp.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.krbSafeBody.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.KerberosTime;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadKerberosTime;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.KrbSafeBodyContainer;
+
+
+/**
+ * The action used to store the KrbSafeBody timemstamp
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreTimestamp extends AbstractReadKerberosTime
+{
+
+ /**
+ * Instantiates a new StoreCTime action.
+ */
+ public StoreTimestamp()
+ {
+ super( "KRB-SAFE-BODY timemstamp" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setKerberosTime( KerberosTime krbtime, Asn1Container container )
+ {
+ KrbSafeBodyContainer krbSafeBodyContainer = ( KrbSafeBodyContainer ) container;
+ krbSafeBodyContainer.getKrbSafeBody().setTimestamp( krbtime );
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUsec.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUsec.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUsec.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUsec.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.krbSafeBody.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadInteger;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.KrbSafeBodyContainer;
+
+
+/**
+ * The action used to store the KrbSafeBody usec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreUsec extends AbstractReadInteger
+{
+
+ /**
+ * Instantiates a new StoreUsec action.
+ */
+ public StoreUsec()
+ {
+ super( "KRB-SAFE-BODY usec" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setIntegerValue( int value, Asn1Container container )
+ {
+ KrbSafeBodyContainer krbSafeBodyContainer = ( KrbSafeBodyContainer ) container;
+ krbSafeBodyContainer.getKrbSafeBody().setUsec( value );
+ }
+
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUserData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUserData.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUserData.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/actions/StoreUserData.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,88 @@
+/*
+ * 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.krbSafeBody.actions;
+
+
+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.codec.krbSafeBody.KrbSafeBodyContainer;
+import org.apache.directory.shared.kerberos.components.KrbSafeBody;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to read the KrbSafeBody user-data
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreUserData extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( StoreUserData.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new StoreUserData action.
+ */
+ public StoreUserData()
+ {
+ super( "KRB-SAFE-BODY user-data" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void action( Asn1Container container ) throws DecoderException
+ {
+ KrbSafeBodyContainer krbSafeBodyContainer = ( KrbSafeBodyContainer ) container;
+
+ TLV tlv = krbSafeBodyContainer.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 ) );
+ }
+
+ // The value is the realm
+ Value value = tlv.getValue();
+
+ KrbSafeBody krbSafeBody = krbSafeBodyContainer.getKrbSafeBody();
+ krbSafeBody.setUserData( value.getData() );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "user-data: " + StringTools.dumpBytes( value.getData() ) );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KrbSafeBody.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KrbSafeBody.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KrbSafeBody.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KrbSafeBody.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,391 @@
+/*
+ * 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.components;
+
+
+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.KerberosTime;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * KRB-SAFE-BODY ::= SEQUENCE {
+ * user-data [0] OCTET STRING,
+ * timestamp [1] KerberosTime OPTIONAL,
+ * usec [2] Microseconds OPTIONAL,
+ * seq-number [3] UInt32 OPTIONAL,
+ * s-address [4] HostAddress,
+ * r-address [5] HostAddress OPTIONAL
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbSafeBody extends AbstractAsn1Object
+{
+ /** The logger */
+ private static final Logger log = LoggerFactory.getLogger( KrbSafeBody.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+ /** the user data */
+ private byte[] userData;
+
+ /** the current time of the sender */
+ private KerberosTime timestamp;
+
+ /** the microsecond part of the timestamp */
+ private Integer usec;
+
+ /** the sequence number */
+ private Integer seqNumber;
+
+ /** the sender's address */
+ private HostAddress senderAddress;
+
+ /** the recipient's address */
+ private HostAddress recipientAddress;
+
+ private transient int userDataLen;
+ private transient int timestampLen;
+ private transient int usecLen;
+ private transient int seqNumberLen;
+ private transient int senderAddressLen;
+ private transient int recipientAddressLen;
+ private transient int krbSafeBodySeqLen;
+
+
+ /**
+ * Compute the KRB-SAFE-BODY length:
+ *
+ * <pre>
+ * 0x30 L1 KRB-SAFE-BODY SEQ
+ * |
+ * +--> 0xA0 L2 user-data tag
+ * | |
+ * | +--> 0x04 L2-1 user-data (Octet String)
+ * |
+ * +--> 0xA1 0x11 timestamp tag
+ * | |
+ * | +--> 0x18 0x0F timestamp (KerberosTime)
+ * |
+ * +--> 0xA2 L3 usec tag
+ * | |
+ * | +--> 0x02 L3-1 usec (Microseconds)
+ * |
+ * +--> 0xA3 L4 seq-number tag
+ * | |
+ * | +--> 0x02 L4-1 seqnumber (UInt32)
+ * |
+ * +--> 0xA4 L5 s-address tag
+ * | |
+ * | +--> 0x30 L5-1 s-address (HostAddress)
+ * |
+ * +--> 0xA5 L6 r-address tag
+ * |
+ * +--> 0x30 L6-1 r-address (HostAddress)
+ * </pre>
+ */
+ @Override
+ public int computeLength()
+ {
+ userDataLen = 1 + TLV.getNbBytes( userData.length ) + userData.length;
+ krbSafeBodySeqLen = 1 + TLV.getNbBytes( userDataLen ) + userDataLen;
+
+ senderAddressLen = senderAddress.computeLength();
+ krbSafeBodySeqLen += 1 + TLV.getNbBytes( senderAddressLen ) + senderAddressLen;
+
+ if ( timestamp != null )
+ {
+ timestampLen = timestamp.getBytes().length;
+ timestampLen = 1 + TLV.getNbBytes( timestampLen ) + timestampLen;
+ krbSafeBodySeqLen += 1 + TLV.getNbBytes( timestampLen ) + timestampLen;
+ }
+
+ if ( usec != null )
+ {
+ usecLen = Value.getNbBytes( usec );
+ usecLen = 1 + TLV.getNbBytes( usecLen ) + usecLen;
+ krbSafeBodySeqLen += 1 + TLV.getNbBytes( usecLen ) + usecLen;
+ }
+
+ if ( seqNumber != null )
+ {
+ seqNumberLen = Value.getNbBytes( seqNumber );
+ seqNumberLen = 1 + TLV.getNbBytes( seqNumberLen ) + seqNumberLen;
+ krbSafeBodySeqLen += 1 + TLV.getNbBytes( seqNumberLen ) + seqNumberLen;
+ }
+
+ if ( recipientAddress != null )
+ {
+ recipientAddressLen = recipientAddress.computeLength();
+ krbSafeBodySeqLen += 1 + TLV.getNbBytes( recipientAddressLen ) + recipientAddressLen;
+ }
+
+ return 1 + TLV.getNbBytes( krbSafeBodySeqLen ) + krbSafeBodySeqLen;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if ( buffer == null )
+ {
+ throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+ }
+
+ try
+ {
+ buffer.put( UniversalTag.SEQUENCE.getValue() );
+ buffer.put( TLV.getBytes( krbSafeBodySeqLen ) );
+
+ // user-data
+ buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_USER_DATA_TAG );
+ buffer.put( TLV.getBytes( userDataLen ) );
+ Value.encode( buffer, userData );
+
+ if ( timestamp != null )
+ {
+ // timestamp tag
+ buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_TIMESTAMP_TAG );
+ buffer.put( TLV.getBytes( timestampLen ) );
+
+ // timestamp value
+ buffer.put( ( byte ) UniversalTag.GENERALIZED_TIME.getValue() );
+ buffer.put( ( byte ) 0x0F );
+ buffer.put( timestamp.getBytes() );
+ }
+
+ if ( usec != null )
+ {
+ // usec
+ buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_USEC_TAG );
+ buffer.put( TLV.getBytes( usecLen ) );
+ Value.encode( buffer, usec );
+ }
+
+ if ( seqNumber != null )
+ {
+ // seq-number
+ buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_SEQ_NUMBER_TAG );
+ buffer.put( TLV.getBytes( seqNumberLen ) );
+ Value.encode( buffer, seqNumber );
+ }
+
+ // s-address
+ buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG );
+ buffer.put( TLV.getBytes( senderAddressLen ) );
+ senderAddress.encode( buffer );
+
+ if ( recipientAddress != null )
+ {
+ // s-address
+ buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_RECIPIENT_ADDRESS_TAG );
+ buffer.put( TLV.getBytes( recipientAddressLen ) );
+ recipientAddress.encode( buffer );
+ }
+ }
+ catch ( BufferOverflowException boe )
+ {
+ log.error( I18n.err( I18n.ERR_735_CANNOT_ENCODE_KRBSAFEBODY, 1 + TLV.getNbBytes( krbSafeBodySeqLen )
+ + krbSafeBodySeqLen, buffer.capacity() ) );
+ throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+ }
+
+ if ( IS_DEBUG )
+ {
+ log.debug( "KrbSafeBody encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+ log.debug( "KrbSafeBody initial value : {}", toString() );
+ }
+
+ return buffer;
+ }
+
+
+ /**
+ * @return the userData
+ */
+ public byte[] getUserData()
+ {
+ return userData;
+ }
+
+
+ /**
+ * @param userData the userData to set
+ */
+ public void setUserData( byte[] userData )
+ {
+ this.userData = userData;
+ }
+
+
+ /**
+ * @return the timestamp
+ */
+ public KerberosTime getTimestamp()
+ {
+ return timestamp;
+ }
+
+
+ /**
+ * @param timestamp the timestamp to set
+ */
+ public void setTimestamp( KerberosTime timestamp )
+ {
+ this.timestamp = timestamp;
+ }
+
+
+ /**
+ * @return the usec
+ */
+ public int getUsec()
+ {
+ if ( usec == null )
+ {
+ return 0;
+ }
+
+ return usec;
+ }
+
+
+ /**
+ * @param usec the usec to set
+ */
+ public void setUsec( int usec )
+ {
+ this.usec = usec;
+ }
+
+
+ /**
+ * @return the seqNumber
+ */
+ public int getSeqNumber()
+ {
+ if ( seqNumber == null )
+ {
+ return 0;
+ }
+
+ return seqNumber;
+ }
+
+
+ /**
+ * @param seqNumber the seqNumber to set
+ */
+ public void setSeqNumber( int seqNumber )
+ {
+ this.seqNumber = seqNumber;
+ }
+
+
+ /**
+ * @return the senderAddress
+ */
+ public HostAddress getSenderAddress()
+ {
+ return senderAddress;
+ }
+
+
+ /**
+ * @param senderAddress the senderAddress to set
+ */
+ public void setSenderAddress( HostAddress senderAddress )
+ {
+ this.senderAddress = senderAddress;
+ }
+
+
+ /**
+ * @return the recipientAddress
+ */
+ public HostAddress getRecipientAddress()
+ {
+ return recipientAddress;
+ }
+
+
+ /**
+ * @param recipientAddress the recipientAddress to set
+ */
+ public void setRecipientAddress( HostAddress recipientAddress )
+ {
+ this.recipientAddress = recipientAddress;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "KrbSafeBody : {\n" );
+ sb.append( " user-data: " ).append( StringTools.dumpBytes( userData ) ).append( '\n' );
+
+ if ( timestamp != null )
+ {
+ sb.append( " timestamp: " ).append( timestamp.getDate() ).append( '\n' );
+ }
+
+ if ( usec != null )
+ {
+ sb.append( " usec: " ).append( usec ).append( '\n' );
+ }
+
+ if ( seqNumber != null )
+ {
+ sb.append( " seq-number: " ).append( seqNumber ).append( '\n' );
+ }
+
+ sb.append( " s-address: " ).append( senderAddress ).append( '\n' );
+
+ if ( recipientAddress != null )
+ {
+ sb.append( " r-address: " ).append( recipientAddress ).append( '\n' );
+ }
+
+ sb.append( "}\n" );
+
+ return sb.toString();
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java?rev=1037257&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java Sat Nov 20 16:23:38 2010
@@ -0,0 +1,124 @@
+/*
+ * 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.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+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.krbSafeBody.KrbSafeBodyContainer;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+import org.apache.directory.shared.kerberos.components.KrbSafeBody;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * TODO KrbSafeBodyDecoderTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbSafeBodyDecoderTest
+{
+ @Test
+ public void testDecodeKrbSafeBody() throws Exception
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+
+ int streamLen = 0x47;
+ ByteBuffer stream = ByteBuffer.allocate( streamLen );
+ stream.put( new byte[]
+ {
+ 0x30, 0x45,
+ (byte)0xA0, 0x4, // user-data
+ 0x04, 0x02, 0x00, 0x01,
+ (byte)0xA1, 0x11, // timestamp
+ 0x18, 0xF, '2', '0', '1', '0', '1', '1', '1', '9', '0', '8', '0', '0', '4', '3', 'Z',
+ (byte)0xA2, 0x03, // usec
+ 0x02, 0x01, 0x01,
+ (byte)0xA3, 0x03, // seq-number
+ 0x02, 0x01, 0x01,
+ (byte)0xA4, 0xF, // s-address
+ 0x30, 0x0D,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04, 127, 0, 0, 1,
+ (byte)0xA5, 0xF, // r-adress
+ 0x30, 0x0D,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04, 127, 0, 0, 1
+ } );
+
+ String decoded = StringTools.dumpBytes( stream.array() );
+ stream.flip();
+
+ KrbSafeBodyContainer container = new KrbSafeBodyContainer();
+ container.setStream( stream );
+
+ try
+ {
+ decoder.decode( stream, container );
+ }
+ catch( DecoderException e )
+ {
+ fail();
+ }
+
+ KrbSafeBody body = container.getKrbSafeBody();
+
+ String time = "20101119080043Z";
+ HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+
+ assertTrue( Arrays.equals( new byte[]{0,1}, body.getUserData() ) );
+ assertEquals( time, body.getTimestamp().getDate() );
+ assertEquals( 1, body.getUsec() );
+ assertEquals( 1, body.getSeqNumber() );
+ assertEquals( ad, body.getSenderAddress() );
+ assertEquals( ad, body.getRecipientAddress() );
+
+ int computedLen = body.computeLength();
+
+ assertEquals( streamLen, computedLen );
+
+ try
+ {
+ ByteBuffer bb = ByteBuffer.allocate( computedLen );
+
+ body.encode( bb );
+
+ String encoded = StringTools.dumpBytes( bb.array() );
+ assertEquals( decoded, encoded );
+ }
+ catch( EncoderException e )
+ {
+ fail();
+ }
+ }
+}