Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 243 invoked from network); 24 Nov 2010 14:32:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 24 Nov 2010 14:32:15 -0000 Received: (qmail 32770 invoked by uid 500); 24 Nov 2010 14:32:47 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 32712 invoked by uid 500); 24 Nov 2010 14:32:47 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 32547 invoked by uid 99); 24 Nov 2010 14:32:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Nov 2010 14:32:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Nov 2010 14:32:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DB96D238890D; Wed, 24 Nov 2010 14:31:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ ... Date: Wed, 24 Nov 2010 14:31:06 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101124143106.DB96D238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Apache Directory Project + */ +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 Apache Directory Project + */ +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 Apache Directory Project + */ +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 Apache Directory Project + */ +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 Apache Directory Project + */ +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 Apache Directory Project + */ +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 : + *
+ * LastReq         ::=     SEQUENCE OF SEQUENCE {
+ *         lr-type         [0] Int32,
+ *         lr-value        [1] KerberosTime
+ * }
+ * 
+ * @author Apache Directory Project + */ +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 lastReqs = new ArrayList(); + + /** 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 getLastReqs() + { + return lastReqs; + } + + + /** + * Compute the LastReq length + * + *
+     * 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)
+     *  
+ */ + 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. + * + *
+     * LastReq :
+     * 
+     * 0x30 LL
+     *   0x30 LL
+     *     0xA0 LL 
+     *       0x02 0x01 lrType
+     *     0xA1 0x11 
+     *       0x18 0x0F lrValue
+     * 
+ * + * @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 Apache Directory Project + */ +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(); + } +}