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 20:55:22 UTC
svn commit: r1039536 - in /directory/apacheds/trunk/kerberos-codec/src:
main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/
main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/
main/java/org/apache/directory/shared/kerb...
Author: elecharny
Date: Fri Nov 26 19:55:21 2010
New Revision: 1039536
URL: http://svn.apache.org/viewvc?rev=1039536&view=rev
Log:
Added the PA-ENC-TS-ENC grammar and tests
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncGrammar.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncStatesEnum.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/PaEncTsEncInit.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaTimestamp.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaUsec.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTsEnc.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTsEncDecoderTest.java
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncContainer.java?rev=1039536&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncContainer.java Fri Nov 26 19:55:21 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.paEncTsEnc;
+
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.components.PaEncTsEnc;
+
+
+/**
+ * The AdAndOr container stores the PA-ENC-TS-ENC decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PaEncTsEncContainer extends KdcReqContainer
+{
+ /** An PA-ENC-TS-ENC container */
+ private PaEncTsEnc paEncTsEnc = new PaEncTsEnc();
+
+ /**
+ * Creates a new PaEncTsEncContainer object.
+ */
+ public PaEncTsEncContainer()
+ {
+ super();
+ this.stateStack = new int[1];
+ this.grammar = PaEncTsEncGrammar.getInstance();
+ setTransition( PaEncTsEncStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the PaEncTsEnc.
+ */
+ public PaEncTsEnc getPaEncTsEnc()
+ {
+ return paEncTsEnc;
+ }
+
+
+ /**
+ * Set an PaEncTsEnc Object into the container. It will be completed by the
+ * KerberosDecoder.
+ *
+ * @param paEncTsEnc The PaEncTsEnc to set.
+ */
+ public void setPaEncTsEnc( PaEncTsEnc paEncTsEnc )
+ {
+ this.paEncTsEnc = paEncTsEnc;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncGrammar.java?rev=1039536&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncGrammar.java Fri Nov 26 19:55:21 2010
@@ -0,0 +1,126 @@
+/*
+ * 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.paEncTsEnc;
+
+
+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.paEncTsEnc.actions.PaEncTsEncInit;
+import org.apache.directory.shared.kerberos.codec.paEncTsEnc.actions.StorePaTimestamp;
+import org.apache.directory.shared.kerberos.codec.paEncTsEnc.actions.StorePaUsec;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the PaEncTsEnc 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 PaEncTsEncGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( PaEncTsEncGrammar.class );
+
+ /** A speedup for logger */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. PaEncTsEncGrammar is a singleton */
+ private static Grammar instance = new PaEncTsEncGrammar();
+
+
+ /**
+ * Creates a new PaEncTsEncrGrammar object.
+ */
+ private PaEncTsEncGrammar()
+ {
+ setName( PaEncTsEncGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[PaEncTsEncStatesEnum.LAST_PA_ENC_TS_ENC_STATE.ordinal()][256];
+
+ // ============================================================================================
+ // PaEncTsEnc
+ // ============================================================================================
+ // --------------------------------------------------------------------------------------------
+ // Transition from PaEncTsEnc init to PaEncTsEnc SEQ
+ // --------------------------------------------------------------------------------------------
+ // PA-ENC-TS-ENC ::= SEQUENCE {
+ super.transitions[PaEncTsEncStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ PaEncTsEncStatesEnum.START_STATE, PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE, UniversalTag.SEQUENCE.getValue(),
+ new PaEncTsEncInit() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from PaEncTsEnc SEQ to patimestamp tag
+ // --------------------------------------------------------------------------------------------
+ // PA-ENC-TS-ENC ::= SEQUENCE {
+ // patimestamp [0]
+ super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE.ordinal()][KerberosConstants.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG] = new GrammarTransition(
+ PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE, PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE, KerberosConstants.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from patimestamp tag to patimestamp value
+ // --------------------------------------------------------------------------------------------
+ // PA-ENC-TS-ENC ::= SEQUENCE {
+ // patimestamp [0] KerberosTime -- client's time --,
+ super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME.getValue()] = new GrammarTransition(
+ PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE, PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE, UniversalTag.GENERALIZED_TIME.getValue(),
+ new StorePaTimestamp() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from patimestamp value to pausec tag
+ // --------------------------------------------------------------------------------------------
+ // PA-ENC-TS-ENC ::= SEQUENCE {
+ // ...
+ // pausec [1]
+ super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE.ordinal()][KerberosConstants.PA_ENC_TS_ENC_PA_USEC_TAG] = new GrammarTransition(
+ PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE, PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE, KerberosConstants.PA_ENC_TS_ENC_PA_USEC_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from pausec tag to pausec value
+ // --------------------------------------------------------------------------------------------
+ // PA-ENC-TS-ENC ::= SEQUENCE {
+ // ...
+ // pausec [1] Microseconds OPTIONAL
+ // }
+ super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+ PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE, PaEncTsEncStatesEnum. PA_ENC_TS_ENC_PA_USEC_STATE, UniversalTag.INTEGER.getValue(),
+ new StorePaUsec() );
+ }
+
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the PA-ENC-TS-ENC Grammar
+ */
+ public static Grammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncStatesEnum.java?rev=1039536&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/PaEncTsEncStatesEnum.java Fri Nov 26 19:55:21 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.paEncTsEnc;
+
+
+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 PA-ENC-TS-ENC grammar's constants. It is also used for debugging
+ * purpose
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum PaEncTsEncStatesEnum implements States
+{
+ // Start
+ START_STATE, // 0
+
+ // ----- PA-ENC-TS-ENC message --------------------------------------
+ PA_ENC_TS_ENC_STATE, // 1
+
+ PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE, // 2
+ PA_ENC_TS_PA_TIMESTAMP_STATE, // 3
+
+ PA_ENC_TS_ENC_PA_USEC_TAG_STATE, // 4
+ PA_ENC_TS_ENC_PA_USEC_STATE, // 4
+
+ // End
+ LAST_PA_ENC_TS_ENC_STATE; // 5
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "PA_ENC_TS_ENC_GRAMMAR";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( Grammar grammar )
+ {
+ if ( grammar instanceof KerberosMessageGrammar )
+ {
+ return "PA_ENC_TS_ENC_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_PA_ENC_TS_ENC_STATE.ordinal() ) ? "PA_ENC_TS_ENC_END_STATE" : name() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == LAST_PA_ENC_TS_ENC_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public PaEncTsEncStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/PaEncTsEncInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/PaEncTsEncInit.java?rev=1039536&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/PaEncTsEncInit.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/PaEncTsEncInit.java Fri Nov 26 19:55:21 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.paEncTsEnc.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.paEncTsEnc.PaEncTsEncContainer;
+import org.apache.directory.shared.kerberos.components.PaEncTsEnc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the PA-ENC-TS-ENC object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PaEncTsEncInit extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( PaEncTsEncInit.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new PaEncTsEncInit action.
+ */
+ public PaEncTsEncInit()
+ {
+ super( "Creates an PaEncTsEncInit instance" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ PaEncTsEncContainer encApRepPartContainer = ( PaEncTsEncContainer ) container;
+
+ TLV tlv = encApRepPartContainer.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 ) );
+ }
+
+ PaEncTsEnc paEncTsEnc = new PaEncTsEnc();
+ encApRepPartContainer.setPaEncTsEnc( paEncTsEnc );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "PaEncTsEnc created" );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaTimestamp.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaTimestamp.java?rev=1039536&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaTimestamp.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaTimestamp.java Fri Nov 26 19:55:21 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.paEncTsEnc.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.paEncTsEnc.PaEncTsEncContainer;
+
+
+/**
+ * The action used to store the patimestamp KerberosTime
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StorePaTimestamp extends AbstractReadKerberosTime
+{
+
+ /**
+ * Instantiates a new StoreCTime action.
+ */
+ public StorePaTimestamp()
+ {
+ super( "Stores the CTime" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setKerberosTime( KerberosTime krbtime, Asn1Container container )
+ {
+ PaEncTsEncContainer paEncTsEncContainer = ( PaEncTsEncContainer ) container;
+ paEncTsEncContainer.getPaEncTsEnc().setPaTimestamp( krbtime );
+ paEncTsEncContainer.setGrammarEndAllowed( true );
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaUsec.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaUsec.java?rev=1039536&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaUsec.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTsEnc/actions/StorePaUsec.java Fri Nov 26 19:55:21 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.paEncTsEnc.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.paEncTsEnc.PaEncTsEncContainer;
+
+
+/**
+ * The action used to store the pausec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StorePaUsec extends AbstractReadInteger
+{
+
+ /**
+ * Instantiates a new StoreCusec action.
+ */
+ public StorePaUsec()
+ {
+ super( "EncApRepPart pausec" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setIntegerValue( int value, Asn1Container container )
+ {
+ PaEncTsEncContainer paEncTsEncContainer = ( PaEncTsEncContainer ) container;
+ paEncTsEncContainer.getPaEncTsEnc().setPausec( value );
+ paEncTsEncContainer.setGrammarEndAllowed( true );
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTsEnc.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTsEnc.java?rev=1039536&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTsEnc.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTsEnc.java Fri Nov 26 19:55:21 2010
@@ -0,0 +1,251 @@
+/*
+ * 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;
+
+
+/**
+ * The PaEncTsEnc structure is used to store a PA-ENC-TS-ENC associated to a type.
+ *
+ * The ASN.1 grammar is :
+ * <pre>
+ * PA-ENC-TS-ENC ::= SEQUENCE {
+ * patimestamp [0] KerberosTime -- client's time --,
+ * pausec [1] Microseconds OPTIONAL
+ * }
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PaEncTsEnc extends AbstractAsn1Object
+{
+ /** The logger */
+ private static final Logger log = LoggerFactory.getLogger( PaEncTsEnc.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+ /** The patimestamp */
+ private KerberosTime patimestamp;
+
+ /** The pausec */
+ private Integer pausec;
+
+ // Storage for computed lengths
+ private transient int paTimestampLength;
+ private transient int paUsecLength;
+ private transient int paEncTsEncLength;
+
+
+ /**
+ * Creates a new instance of PaEncTsEnc.
+ */
+ public PaEncTsEnc()
+ {
+ }
+
+
+ /**
+ * Returns the patimestamp value.
+ *
+ * @return The patimestamp value.
+ */
+ public KerberosTime getPaTimestamp()
+ {
+ return patimestamp;
+ }
+
+
+ /**
+ * Set the patimestamp.
+ *
+ * @param patimestamp The patimestamp value
+ */
+ public void setPaTimestamp( KerberosTime patimestamp )
+ {
+ this.patimestamp = patimestamp;
+ }
+
+
+ /**
+ * @return the pausec
+ */
+ public int getPausec()
+ {
+ if ( pausec == null )
+ {
+ return -1;
+ }
+
+ return pausec;
+ }
+
+
+ /**
+ * @param pausec the pausec to set
+ */
+ public void setPausec( int pausec )
+ {
+ this.pausec = pausec;
+ }
+
+
+ /**
+ * Compute the PA-ENC-TS-ENC length
+ * <pre>
+ * PA-ENC-TS-ENC :
+ *
+ * 0x30 L1 PA-ENC-TS-ENC sequence
+ * |
+ * +--> 0xA0 0x11 patimestamp tag
+ * | |
+ * | +--> 0x18 0x0F patimestamp value (KerberosTime)
+ * |
+ * +--> 0xA1 L2 pausec tag
+ * |
+ * +--> 0x02 L2-1 pausec (INTEGER)
+ *
+ * </pre>
+ */
+ public int computeLength()
+ {
+ // The paTimestamp
+ paTimestampLength = 0x11;
+
+ paEncTsEncLength = 1 + TLV.getNbBytes( paTimestampLength ) + paTimestampLength;
+
+ // The pausec, if any
+ if ( pausec != null )
+ {
+ int pausecLength = Value.getNbBytes( pausec );
+ paUsecLength = 1 + TLV.getNbBytes( pausecLength ) + pausecLength;
+ paEncTsEncLength += 1 + TLV.getNbBytes( paUsecLength ) + paUsecLength;
+ }
+
+ // Compute the whole sequence length
+ return 1 + Value.getNbBytes( paEncTsEncLength ) + paEncTsEncLength;
+ }
+
+
+ /**
+ * Encode the PA-ENC-TS-ENC message to a PDU.
+ *
+ * <pre>
+ * PA-ENC-TS-ENC :
+ *
+ * 0x30 LL
+ * 0xA0 0x11
+ * 0x18 0x0F patimestamp
+ * [0xA1 LL
+ * 0x02 LL pausec]
+ * </pre>
+ * @param buffer The buffer where to put the PDU. It should have been allocated
+ * before, with the right size.
+ * @return The constructed PDU.
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if ( buffer == null )
+ {
+ throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+ }
+
+ try
+ {
+ // The PA-ENC-TS-ENC SEQ Tag
+ buffer.put( UniversalTag.SEQUENCE.getValue() );
+ buffer.put( TLV.getBytes( paEncTsEncLength ) );
+
+ // The patimestamp, first the tag, then the value
+ buffer.put( ( byte ) KerberosConstants.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG );
+ buffer.put( (byte)0x11 );
+
+ buffer.put( ( byte ) UniversalTag.GENERALIZED_TIME.getValue() );
+ buffer.put( ( byte ) 0x0F );
+ buffer.put( patimestamp.getBytes() );
+
+ // The pausec, first the tag, then the value, if any
+ if ( pausec != null )
+ {
+ buffer.put( ( byte ) KerberosConstants.PA_ENC_TS_ENC_PA_USEC_TAG );
+ buffer.put( TLV.getBytes( paUsecLength ) );
+ Value.encode( buffer, pausec );
+ }
+ }
+ catch ( BufferOverflowException boe )
+ {
+ log.error( I18n.err( I18n.ERR_140, 1 + TLV.getNbBytes( paEncTsEncLength ) + paEncTsEncLength,
+ buffer.capacity() ) );
+ throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+ }
+
+ if ( IS_DEBUG )
+ {
+ log.debug( "Checksum encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+ log.debug( "Checksum initial value : {}", toString() );
+ }
+
+ return buffer;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ return toString( "" );
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString( String tabs )
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( tabs ).append( "PA-ENC-TS-ENC : {\n" );
+ sb.append( tabs ).append( " patimestamp : " ).append( patimestamp ).append( '\n' );
+
+ if ( pausec != null )
+ {
+ sb.append( tabs + " pausec :" ).append( pausec ).append( '\n' );
+ }
+
+ sb.append( tabs + "}\n" );
+
+ return sb.toString();
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTsEncDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTsEncDecoderTest.java?rev=1039536&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTsEncDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTsEncDecoderTest.java Fri Nov 26 19:55:21 2010
@@ -0,0 +1,240 @@
+/*
+ * 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.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.paEncTsEnc.PaEncTsEncContainer;
+import org.apache.directory.shared.kerberos.components.PaEncTsEnc;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for PaEncTsEnc codec.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PaEncTsEncDecoderTest
+{
+ @Test
+ public void testDecodeFullPaEncTsEnc()
+ {
+ Asn1Decoder krbDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x1A );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x18,
+ (byte)0xA0, 0x11, // PaTimestamp
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '0', '1', '0', '2', '3', '4', '5', '4', '5', 'Z',
+ (byte)0xA1, 0x03, // PaUsec
+ 0x02, 0x01, 0x01
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( stream.array() );
+ stream.flip();
+
+ PaEncTsEncContainer paEncTsEncContainer = new PaEncTsEncContainer();
+
+ try
+ {
+ krbDecoder.decode( stream, paEncTsEncContainer );
+ }
+ catch ( DecoderException de )
+ {
+ fail( de.getMessage() );
+ }
+
+ PaEncTsEnc paEncTsEnc = paEncTsEncContainer.getPaEncTsEnc();
+
+ assertEquals( "20101010234545Z", paEncTsEnc.getPaTimestamp().toString() );
+ assertEquals( 1, paEncTsEnc.getPausec() );
+
+ ByteBuffer bb = ByteBuffer.allocate( paEncTsEnc.computeLength() );
+
+ try
+ {
+ bb = paEncTsEnc.encode( bb );
+
+ // Check the length
+ assertEquals( 0x1A, bb.limit() );
+
+ String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ fail();
+ }
+ }
+
+
+ @Test( expected = DecoderException.class )
+ public void testDecodePaEncTsEncWithEmptySeq() throws DecoderException
+ {
+ Asn1Decoder krbDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 2 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x0
+ } );
+
+ stream.flip();
+
+ PaEncTsEncContainer paEncTsEncContainer = new PaEncTsEncContainer();
+
+ krbDecoder.decode( stream, paEncTsEncContainer );
+ fail();
+ }
+
+
+ @Test( expected = DecoderException.class )
+ public void testDecodePaEncTsEncEmptyPaTimestamp() throws DecoderException
+ {
+ Asn1Decoder krbDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 4 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x02,
+ (byte)0xA0, 0x00
+ } );
+
+ stream.flip();
+
+ PaEncTsEncContainer paEncTsEncContainer = new PaEncTsEncContainer();
+
+ krbDecoder.decode( stream, paEncTsEncContainer );
+ fail();
+ }
+
+
+ @Test( expected = DecoderException.class )
+ public void testDecodeAdAndOrNullPaTimestamp() throws DecoderException
+ {
+ Asn1Decoder krbDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 6 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x04,
+ (byte)0xA0, 0x02,
+ 0x18, 0x00
+ } );
+
+ stream.flip();
+
+ PaEncTsEncContainer paEncTsEncContainer = new PaEncTsEncContainer();
+
+ krbDecoder.decode( stream, paEncTsEncContainer );
+ fail();
+ }
+
+
+ @Test( expected = DecoderException.class )
+ public void testDecodeAdAndOrNoPaTimestamp() throws DecoderException
+ {
+ Asn1Decoder krbDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x05,
+ (byte)0xA1, 0x03, // PaUsec
+ 0x02, 0x01, 0x01
+ } );
+
+ stream.flip();
+
+ PaEncTsEncContainer paEncTsEncContainer = new PaEncTsEncContainer();
+
+ krbDecoder.decode( stream, paEncTsEncContainer );
+ fail();
+ }
+
+
+ @Test
+ public void testDecodePaEncTsEncNoPaUsec()
+ {
+ Asn1Decoder krbDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x15 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x13,
+ (byte)0xA0, 0x11, // PaTimestamp
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '0', '1', '0', '2', '3', '4', '5', '4', '5', 'Z',
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( stream.array() );
+ stream.flip();
+
+ PaEncTsEncContainer paEncTsEncContainer = new PaEncTsEncContainer();
+
+ try
+ {
+ krbDecoder.decode( stream, paEncTsEncContainer );
+ }
+ catch ( DecoderException de )
+ {
+ fail( de.getMessage() );
+ }
+
+ PaEncTsEnc paEncTsEnc = paEncTsEncContainer.getPaEncTsEnc();
+
+ assertEquals( "20101010234545Z", paEncTsEnc.getPaTimestamp().toString() );
+ assertEquals( -1, paEncTsEnc.getPausec() );
+
+ ByteBuffer bb = ByteBuffer.allocate( paEncTsEnc.computeLength() );
+
+ try
+ {
+ bb = paEncTsEnc.encode( bb );
+
+ // Check the length
+ assertEquals( 0x15, bb.limit() );
+
+ String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ fail();
+ }
+ }
+}