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/24 15:31:06 UTC
svn commit: r1038623 - in /directory/apacheds/trunk/kerberos-codec/src:
main/java/org/apache/directory/shared/kerberos/
main/java/org/apache/directory/shared/kerberos/codec/lastReq/
main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/ ...
Author: elecharny
Date: Wed Nov 24 14:31:06 2010
New Revision: 1038623
URL: http://svn.apache.org/viewvc?rev=1038623&view=rev
Log:
Added the LastReq grammar and tests
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqGrammar.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqStatesEnum.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/LastReqInit.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrType.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrValue.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/LastReq.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/LastReqDecoderTest.java
Modified:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/types/LastReqType.java
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java?rev=1038623&r1=1038622&r2=1038623&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java Wed Nov 24 14:31:06 2010
@@ -199,6 +199,10 @@ public class KerberosConstants
public static final int KRB_SAFE_BODY_SENDER_ADDRESS_TAG = 0xA4;
public static final int KRB_SAFE_BODY_RECIPIENT_ADDRESS_TAG = 0xA5;
+ /** LastRequest tags */
+ public static final int LAST_REQ_LR_TYPE_TAG = 0xA0;
+ public static final int LAST_REQ_LR_VALUE_TAG = 0xA1;
+
/** PaData tags */
public static final int PADATA_TYPE_TAG = 0xA1;
public static final int PADATA_VALUE_TAG = 0xA2;
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqContainer.java?rev=1038623&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqContainer.java Wed Nov 24 14:31:06 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.lastReq;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.LastReq;
+
+
+/**
+ * The LastReq container stores the LastReq decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LastReqContainer extends AbstractContainer
+{
+ /** An LastReq container */
+ private LastReq lastReq;
+
+ /**
+ * Creates a new LastReqContainer object.
+ */
+ public LastReqContainer()
+ {
+ super();
+ this.stateStack = new int[1];
+ this.grammar = LastReqGrammar.getInstance();
+ setTransition( LastReqStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the LastReq.
+ */
+ public LastReq getLastReq()
+ {
+ return lastReq;
+ }
+
+
+ /**
+ * Set a LastReq Object into the container. It will be completed by the
+ * KerberosDecoder.
+ *
+ * @param lastReq The LastReq to set.
+ */
+ public void setLastReq( LastReq lastReq )
+ {
+ this.lastReq = lastReq;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqGrammar.java?rev=1038623&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqGrammar.java Wed Nov 24 14:31:06 2010
@@ -0,0 +1,144 @@
+/*
+ * 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.lastReq;
+
+
+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.lastReq.actions.LastReqInit;
+import org.apache.directory.shared.kerberos.codec.lastReq.actions.StoreLrType;
+import org.apache.directory.shared.kerberos.codec.lastReq.actions.StoreLrValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the LastReq 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 LastReqGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( LastReqGrammar.class );
+
+ /** A speedup for logger */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. LastReqGrammar is a singleton */
+ private static Grammar instance = new LastReqGrammar();
+
+
+ /**
+ * Creates a new LastReqGrammar object.
+ */
+ private LastReqGrammar()
+ {
+ setName( LastReqGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[LastReqStatesEnum.LAST_LAST_REQ_STATE.ordinal()][256];
+
+ // ============================================================================================
+ // LastReq
+ // ============================================================================================
+ // --------------------------------------------------------------------------------------------
+ // Transition from LastReq init to LastReq SEQ OF
+ // --------------------------------------------------------------------------------------------
+ // LastReq ::= SEQUENCE OF
+ super.transitions[LastReqStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ LastReqStatesEnum.START_STATE, LastReqStatesEnum.LAST_REQ_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+ new LastReqInit() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from LastReq SEQ OF to LastReq SEQ OF SEQ
+ // --------------------------------------------------------------------------------------------
+ // LastReq ::= SEQUENCE OF SEQUENCE {
+ super.transitions[LastReqStatesEnum.LAST_REQ_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ LastReqStatesEnum.LAST_REQ_SEQ_STATE, LastReqStatesEnum.LAST_REQ_SEQ_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from LastReq SEQ OF SEQ to lr-type tag
+ // --------------------------------------------------------------------------------------------
+ // LastReq ::= SEQUENCE OF SEQUENCE {
+ // lr-type [0]
+ super.transitions[LastReqStatesEnum.LAST_REQ_SEQ_SEQ_STATE.ordinal()][KerberosConstants.LAST_REQ_LR_TYPE_TAG] = new GrammarTransition(
+ LastReqStatesEnum.LAST_REQ_SEQ_SEQ_STATE, LastReqStatesEnum.LAST_REQ_LR_TYPE_TAG_STATE, KerberosConstants.LAST_REQ_LR_TYPE_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from lr-type tag to lr-type value
+ // --------------------------------------------------------------------------------------------
+ // LastReq ::= SEQUENCE OF SEQUENCE {
+ // lr-type [0] Int32,
+ super.transitions[LastReqStatesEnum.LAST_REQ_LR_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+ LastReqStatesEnum.LAST_REQ_LR_TYPE_TAG_STATE, LastReqStatesEnum.LAST_REQ_LR_TYPE_STATE, UniversalTag.INTEGER.getValue(),
+ new StoreLrType() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from lr-type value lr-value tag
+ // --------------------------------------------------------------------------------------------
+ // LastReq ::= SEQUENCE OF SEQUENCE {
+ // ...
+ // lr-value [1]
+ super.transitions[LastReqStatesEnum.LAST_REQ_LR_TYPE_STATE.ordinal()][KerberosConstants.LAST_REQ_LR_VALUE_TAG] = new GrammarTransition(
+ LastReqStatesEnum.LAST_REQ_LR_TYPE_STATE, LastReqStatesEnum.LAST_REQ_LR_VALUE_TAG_STATE, KerberosConstants.LAST_REQ_LR_VALUE_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from lr-value tag to lr-value value
+ // --------------------------------------------------------------------------------------------
+ // LastReq ::= SEQUENCE OF SEQUENCE {
+ // ...
+ // lr-value [1] KerberosTime
+ super.transitions[LastReqStatesEnum.LAST_REQ_LR_VALUE_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME.getValue()] = new GrammarTransition(
+ LastReqStatesEnum.LAST_REQ_LR_VALUE_TAG_STATE, LastReqStatesEnum.LAST_REQ_LR_VALUE_STATE, UniversalTag.GENERALIZED_TIME.getValue(),
+ new StoreLrValue() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from lr-value value to SEQ OF SEQ
+ // --------------------------------------------------------------------------------------------
+ // LastReq ::= SEQUENCE OF SEQUENCE {
+ // ...
+ // lr-value [1] KerberosTime
+ // }
+ super.transitions[LastReqStatesEnum.LAST_REQ_LR_VALUE_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ LastReqStatesEnum.LAST_REQ_LR_VALUE_STATE, LastReqStatesEnum.LAST_REQ_SEQ_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+ new CheckNotNullLength() );
+ }
+
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the LastReq Grammar
+ */
+ public static Grammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqStatesEnum.java?rev=1038623&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/LastReqStatesEnum.java Wed Nov 24 14:31:06 2010
@@ -0,0 +1,112 @@
+/*
+ * 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.lastReq;
+
+
+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 LastRequest grammar's constants. It is also used for debugging
+ * purpose
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum LastReqStatesEnum implements States
+{
+ // Start
+ START_STATE, // 0
+
+ LAST_REQ_SEQ_STATE, // 1
+
+ LAST_REQ_SEQ_SEQ_STATE, // 2
+
+ LAST_REQ_LR_TYPE_TAG_STATE, // 3
+ LAST_REQ_LR_TYPE_STATE, // 4
+
+ LAST_REQ_LR_VALUE_TAG_STATE, // 5
+ LAST_REQ_LR_VALUE_STATE, // 6
+
+ // End
+ LAST_LAST_REQ_STATE; // 7
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "LAST_REQ_GRAMMAR";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( Grammar grammar )
+ {
+ if ( grammar instanceof KerberosMessageGrammar )
+ {
+ return "LAST_REQ_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_LAST_REQ_STATE.ordinal() ) ? "LAST_LAST_REQ_STATE" : name() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == LAST_LAST_REQ_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public LastReqStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/LastReqInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/LastReqInit.java?rev=1038623&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/LastReqInit.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/LastReqInit.java Wed Nov 24 14:31:06 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.lastReq.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.lastReq.LastReqContainer;
+import org.apache.directory.shared.kerberos.components.LastReq;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the LastReq object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LastReqInit extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( LastReqInit.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new LastReqInit action.
+ */
+ public LastReqInit()
+ {
+ super( "Creates a LastReq instance" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ LastReqContainer lastReqContainer = ( LastReqContainer ) container;
+
+ TLV tlv = lastReqContainer.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 ) );
+ }
+
+ LastReq lastReq = new LastReq();
+ lastReqContainer.setLastReq( lastReq );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "LastReq created" );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrType.java?rev=1038623&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrType.java Wed Nov 24 14:31:06 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.lastReq.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.lastReq.LastReqContainer;
+import org.apache.directory.shared.kerberos.codec.types.LastReqType;
+import org.apache.directory.shared.kerberos.components.LastReq;
+
+
+/**
+ * The action used to store the LastReq lrType
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreLrType extends AbstractReadInteger
+{
+ /**
+ * Instantiates a new LastReqLrType action.
+ */
+ public StoreLrType()
+ {
+ super( "LastReq lrType" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setIntegerValue( int value, Asn1Container container )
+ {
+ LastReqContainer lastReqContainer = ( LastReqContainer ) container;
+
+ LastReqType lrType = LastReqType.getTypeByValue( value );
+
+ LastReq lastReq = lastReqContainer.getLastReq();
+ lastReq.createNewLR();
+ lastReq.setCurrentLrType( lrType );
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrValue.java?rev=1038623&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrValue.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/lastReq/actions/StoreLrValue.java Wed Nov 24 14:31:06 2010
@@ -0,0 +1,57 @@
+/*
+ * 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.lastReq.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.lastReq.LastReqContainer;
+
+
+/**
+ * The action used to store the LastReq value
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreLrValue extends AbstractReadKerberosTime
+{
+
+ /**
+ * Instantiates a new StoreLrValue action.
+ */
+ public StoreLrValue()
+ {
+ super( "LastReq lr-value" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setKerberosTime( KerberosTime krbtime, Asn1Container container )
+ {
+ LastReqContainer lastReqContainer = ( LastReqContainer ) container;
+ lastReqContainer.getLastReq().setCurrentLrValue( krbtime );
+
+ lastReqContainer.setGrammarEndAllowed( true );
+ }
+}
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/types/LastReqType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/types/LastReqType.java?rev=1038623&r1=1038622&r2=1038623&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/types/LastReqType.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/types/LastReqType.java Wed Nov 24 14:31:06 2010
@@ -88,10 +88,10 @@ public enum LastReqType
/**
* Returns the last request type when specified by its ordinal.
*
- * @param type
+ * @param type The numeric type
* @return The last request type.
*/
- public static LastReqType getTypeByOrdinal( int type )
+ public static LastReqType getTypeByValue( int type )
{
for ( LastReqType lrt : LastReqType.values() )
{
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/LastReq.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/LastReq.java?rev=1038623&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/LastReq.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/LastReq.java Wed Nov 24 14:31:06 2010
@@ -0,0 +1,309 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+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.kerberos.codec.types.LastReqType;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The LastReq structure.
+ *
+ * The ASN.1 grammar is :
+ * <pre>
+ * LastReq ::= SEQUENCE OF SEQUENCE {
+ * lr-type [0] Int32,
+ * lr-value [1] KerberosTime
+ * }
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LastReq extends AbstractAsn1Object
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( LastReq.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ // The inner class storing the individual LastReqs
+ public class LR
+ {
+ /** The LastReq type. */
+ private LastReqType lrType;
+
+ /** The LastReq value */
+ private KerberosTime lrValue;
+
+
+ /**
+ * @return the LastReqType
+ */
+ public LastReqType getLrType()
+ {
+ return lrType;
+ }
+
+ /**
+ * @return the lr-value
+ */
+ public KerberosTime getLrValue()
+ {
+ return lrValue;
+ }
+ }
+
+ /** The list of LastReq elements */
+ private List<LR> lastReqs = new ArrayList<LR>();
+
+ /** The current LR being processed */
+ private LR currentLR;
+
+
+ // Storage for computed lengths
+ private transient int lrTypeTagLen[];
+ private transient int lrValueTagLen[];
+ private transient int lastReqSeqLen[];
+ private transient int lastReqSeqSeqLen;
+
+
+ /**
+ * Creates a new instance of LastReq.
+ */
+ public LastReq()
+ {
+ }
+
+
+ /**
+ * @return the CurrentLr type
+ */
+ public LastReqType getCurrentLrType()
+ {
+ return currentLR.lrType;
+ }
+
+
+ /**
+ * Set the CurrentLr type
+ */
+ public void setCurrentLrType( LastReqType lrType )
+ {
+ currentLR.lrType = lrType;
+ }
+
+
+ /**
+ * @return the CurrentLr value
+ */
+ public KerberosTime getCurrentLrValue()
+ {
+ return currentLR.lrValue;
+ }
+
+
+ /**
+ * Set the CurrentLr value
+ */
+ public void setCurrentLrValue( KerberosTime lrValue )
+ {
+ currentLR.lrValue = lrValue;
+ }
+
+
+ /**
+ * @return the CurrentLR
+ */
+ public LR getCurrentLR()
+ {
+ return currentLR;
+ }
+
+
+ /**
+ * Create a new currentLR
+ */
+ public void createNewLR()
+ {
+ currentLR = new LR();
+ lastReqs.add( currentLR );
+ }
+
+
+ /**
+ * @return the LastReqs
+ */
+ public List<LR> getLastReqs()
+ {
+ return lastReqs;
+ }
+
+
+ /**
+ * Compute the LastReq length
+ *
+ * <pre>
+ * LastReq :
+ *
+ * 0x30 L1 LastReq
+ * |
+ * +--> 0x30 L2
+ * |
+ * +--> 0xA0 L3 lr-type tag
+ * | |
+ * | +--> 0x02 L3-1 lrType (int)
+ * |
+ * +--> 0xA1 0x11 lr-value tag
+ * |
+ * +--> 0x18 0x0F ttt (KerberosString)
+ * </pre>
+ */
+ public int computeLength()
+ {
+ int i = 0;
+ lastReqSeqLen = new int[lastReqs.size()];
+ lrTypeTagLen = new int[lastReqs.size()];
+ lrValueTagLen = new int[lastReqs.size()];
+ lastReqSeqLen = new int[lastReqs.size()];
+
+ for ( LR lr : lastReqs )
+ {
+ int lrTypeLen = Value.getNbBytes( lr.lrType.getValue() );
+ lrTypeTagLen[i] = 1 + TLV.getNbBytes( lrTypeLen ) + lrTypeLen;
+ byte[] lrValyeBytes = lr.lrValue.getBytes();
+ lrValueTagLen[i] = 1 + TLV.getNbBytes( lrValyeBytes.length ) + lrValyeBytes.length;
+
+ lastReqSeqLen[i] = 1 + TLV.getNbBytes( lrTypeTagLen[i] ) + lrTypeTagLen[i] +
+ 1 + TLV.getNbBytes( lrValueTagLen[i] ) + lrValueTagLen[i];
+
+ lastReqSeqSeqLen += 1 + TLV.getNbBytes( lastReqSeqLen[i] ) + lastReqSeqLen[i];
+ i++;
+ }
+
+ return 1 + TLV.getNbBytes( lastReqSeqSeqLen ) + lastReqSeqSeqLen;
+ }
+
+
+ /**
+ * Encode the LastReq message to a PDU.
+ *
+ * <pre>
+ * LastReq :
+ *
+ * 0x30 LL
+ * 0x30 LL
+ * 0xA0 LL
+ * 0x02 0x01 lrType
+ * 0xA1 0x11
+ * 0x18 0x0F lrValue
+ * </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 lastRequest SEQ OF Tag
+ buffer.put( UniversalTag.SEQUENCE.getValue() );
+ buffer.put( TLV.getBytes( lastReqSeqSeqLen ) );
+
+ int i = 0;
+
+ for ( LR lr : lastReqs )
+ {
+ buffer.put( UniversalTag.SEQUENCE.getValue() );
+ buffer.put( TLV.getBytes( lastReqSeqLen[i] ) );
+
+ // the lrType
+ buffer.put( ( byte ) KerberosConstants.LAST_REQ_LR_TYPE_TAG );
+ buffer.put( TLV.getBytes( lrTypeTagLen[i] ) );
+ Value.encode( buffer, lr.lrType.getValue() );
+
+ // the lrValue tag
+ buffer.put( ( byte ) KerberosConstants.LAST_REQ_LR_VALUE_TAG );
+ buffer.put( TLV.getBytes( lrValueTagLen[i] ) );
+
+ // the lrValue value
+ buffer.put( ( byte ) UniversalTag.GENERALIZED_TIME.getValue() );
+ buffer.put( ( byte ) 0x0F );
+ buffer.put( lr.lrValue.getBytes() );
+ }
+ }
+ catch ( BufferOverflowException boe )
+ {
+ LOG.error( I18n.err( I18n.ERR_139, 1 + TLV.getNbBytes( lastReqSeqSeqLen )
+ + lastReqSeqSeqLen, buffer.capacity() ) );
+ throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+ }
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "LastReq encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+ LOG.debug( "LastReq initial value : {}", toString() );
+ }
+
+ return buffer;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "LastReq : {\n" );
+
+ for ( LR lr : lastReqs )
+ {
+ sb.append( " {\n" );
+ sb.append( " lr-type: " ).append( lr.lrType ).append( '\n' );
+ sb.append( " lr-value: " ).append( lr.lrValue ).append( '\n');
+ sb.append( " }\n" );
+ }
+
+ return sb.toString();
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/LastReqDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/LastReqDecoderTest.java?rev=1038623&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/LastReqDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/LastReqDecoderTest.java Wed Nov 24 14:31:06 2010
@@ -0,0 +1,231 @@
+/*
+ * 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.assertNotNull;
+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.lastReq.LastReqContainer;
+import org.apache.directory.shared.kerberos.codec.types.LastReqType;
+import org.apache.directory.shared.kerberos.components.LastReq;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for LastReq decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LastReqDecoderTest
+{
+
+ @Test
+ public void testLastReqData()
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x36 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x34,
+ 0x30, 0x18,
+ (byte)0xA0, 0x03, // lr-type
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x11, // lr-value
+ 0x18, 0x0F, '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ 0x30, 0x18,
+ (byte)0xA0, 0x03, // lr-type
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x11, // lr-value
+ 0x18, 0x0F, '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '6', 'Z'
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( stream.array() );
+ stream.flip();
+
+ LastReqContainer lastReqContainer = new LastReqContainer();
+
+ // Decode the LastReq PDU
+ try
+ {
+ kerberosDecoder.decode( stream, lastReqContainer );
+ }
+ catch ( DecoderException de )
+ {
+ fail( de.getMessage() );
+ }
+
+ LastReq lastReq = lastReqContainer.getLastReq();
+
+ assertNotNull( lastReq.getLastReqs().size() );
+ assertEquals( 2, lastReq.getLastReqs().size() );
+
+ String[] expected = new String[]{ "20101110154525Z", "20101110154526Z" };
+ int i = 0;
+
+ for ( LastReq.LR lr : lastReq.getLastReqs() )
+ {
+ assertEquals( LastReqType.TIME_OF_INITIAL_REQ, lr.getLrType() );
+ assertEquals( expected[i++], lr.getLrValue().toString() );
+
+ }
+
+ // Check the encoding
+ ByteBuffer bb = ByteBuffer.allocate( lastReq.computeLength() );
+
+ try
+ {
+ bb = lastReq.encode( bb );
+
+ // Check the length
+ assertEquals( 0x36, bb.limit() );
+
+ String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ fail();
+ }
+ }
+
+
+ @Test( expected = DecoderException.class)
+ public void testLastReqWithoutType() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x15 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x13,
+ (byte)0xA1, 0x11, // lr-value
+ 0x18, 0x0F, '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '6', 'Z'
+ } );
+
+ stream.flip();
+
+ LastReqContainer lastReqContainer = new LastReqContainer();
+
+ kerberosDecoder.decode( stream, lastReqContainer );
+ fail();
+ }
+
+
+ @Test( expected = DecoderException.class)
+ public void testLastReqWithoutValue() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+
+ stream.put( new byte[]
+ { 0x30, 0x05,
+ (byte)0xA0, 0x03, // lr-type
+ 0x02, 0x01, 0x02
+ } );
+
+ stream.flip();
+
+ LastReqContainer lastReqContainer = new LastReqContainer();
+
+ kerberosDecoder.decode( stream, lastReqContainer );
+ fail();
+ }
+
+
+ @Test( expected = DecoderException.class)
+ public void testLastReqWithIncorrectPdu() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+
+ stream.put( new byte[]
+ { 0x30, 0x00 } );
+
+ stream.flip();
+
+ LastReqContainer lastReqContainer = new LastReqContainer();
+
+ kerberosDecoder.decode( stream, lastReqContainer );
+ fail();
+ }
+
+
+ @Test( expected = DecoderException.class)
+ public void testLastReqWithEmptyValue() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0xB );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x09,
+ (byte)0xA0, 0x03, // lr-type
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x02, // lr-value
+ 0x18, 0x00
+ } );
+
+ stream.flip();
+
+ LastReqContainer lastReqContainer = new LastReqContainer();
+
+ kerberosDecoder.decode( stream, lastReqContainer );
+ fail();
+ }
+
+
+ @Test( expected = DecoderException.class)
+ public void testLastReqWithEmptyType() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x19 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x17,
+ (byte)0xA0, 0x02, // lr-type
+ 0x02, 0x00,
+ (byte)0xA1, 0x11, // lr-value
+ 0x18, 0x0F, '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '6', 'Z'
+ } );
+
+ stream.flip();
+
+ LastReqContainer lastReqContainer = new LastReqContainer();
+
+ kerberosDecoder.decode( stream, lastReqContainer );
+ fail();
+ }
+}