From commits-return-4275-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Fri Apr 15 05:42:30 2005 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 53489 invoked from network); 15 Apr 2005 05:42:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Apr 2005 05:42:29 -0000 Received: (qmail 33388 invoked by uid 500); 15 Apr 2005 05:42:27 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 33287 invoked by uid 500); 15 Apr 2005 05:42:27 -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 33257 invoked by uid 99); 15 Apr 2005 05:42:26 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 14 Apr 2005 22:42:25 -0700 Received: (qmail 53386 invoked by uid 65534); 15 Apr 2005 05:42:24 -0000 Message-ID: <20050415054224.53385.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Fri, 15 Apr 2005 05:42:24 -0000 Subject: svn commit: r161400 [1/2] - in directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars: ./ BindRequestGrammar.java BindResponseGrammar.java LdapControlGrammar.java LdapMessageGrammar.java LdapResultGrammar.java To: commits@directory.apache.org From: elecharny@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Thu Apr 14 22:42:23 2005 New Revision: 161400 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D161400 Log: Created the LdapResultGrammar, LdapControlGrammar and the BindResponseGramm= ar. A lot of changes done in LdapMessageGrammar and BindRequestGrammar. Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/BindRequestGrammar.java directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/BindResponseGrammar.java directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/LdapControlGrammar.java directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/LdapMessageGrammar.java - copied, changed from r160136, directory/sandbox/trunk/asn1-new-code= c/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/LdapResultGrammar.java Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap= /codec/grammars/BindRequestGrammar.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/s= rc/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java?view=3D= auto&rev=3D161400 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/BindRequestGrammar.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/BindRequestGrammar.java Thu Apr 14 22:42:23 2005 @@ -0,0 +1,541 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.asn1.ldap.codec.grammars; + +import org.apache.asn1.ber.containers.IAsn1Container; +import org.apache.asn1.ber.grammar.AbstractGrammar; +import org.apache.asn1.ber.grammar.GrammarAction; +import org.apache.asn1.ber.grammar.GrammarTransition; +import org.apache.asn1.ber.grammar.IGrammar; +import org.apache.asn1.ber.grammar.StatesEnum; +import org.apache.asn1.ber.tlv.TLV; +import org.apache.asn1.ber.tlv.Value; +import org.apache.asn1.ldap.codec.DecoderException; +import org.apache.asn1.ldap.codec.LdapMessageContainer; +import org.apache.asn1.ldap.codec.primitives.LdapDN; +import org.apache.asn1.ldap.codec.primitives.LdapString; +import org.apache.asn1.ldap.codec.utils.IntegerDecoder; +import org.apache.asn1.ldap.pojo.BindRequestPOJO; +import org.apache.asn1.ldap.pojo.LdapMessagePOJO; +import org.apache.asn1.ldap.pojo.SaslAuthenticationPOJO; +import org.apache.asn1.ldap.pojo.SimpleAuthenticationPOJO; +import org.apache.asn1.util.MutableString; +import org.apache.asn1.util.pools.PoolEnum; +import org.apache.asn1.util.pools.PoolException; + +import org.apache.log4j.Logger; + + +/** + * This class implements the LdapMessage. All the actions are declared in = this + * class. As it is a singleton, these declaration are only done once. + *=20 + * If an action is to be added or modified, this is where the work is to b= e done ! + *=20 + * @author Apache Directory Pr= oject + */ +public class BindRequestGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ---------------------------------------= -------------------------- + + /** The logger */ + private static final Logger log =3D Logger.getLogger( BindRequestGramm= ar.class ); + + /** Logging speed up */ + private static final boolean DEBUG =3D log.isDebugEnabled(); + + /** The instance of grammar. BindRequestGrammar is a singleton */ + private static IGrammar instance =3D new BindRequestGrammar(); + + //~ Methods ----------------------------------------------------------= -------------------------- + + /** + * Get the instance of this grammar + * + * @return An instance on the BindRequest Grammar + */ + public static IGrammar getInstance() + { + return instance; + } + + //~ Constructors -----------------------------------------------------= -------------------------- + + /** + * Creates a new LdapMessageGrammar object. + */ + private BindRequestGrammar() + { + + name =3D BindRequestGrammar.class.getName(); + + // We have 17 differents states, so 16 transitions between states. + super.transitions =3D new GrammarTransition[StatesEnum.LAST_BIND_R= EQUEST_STATE][256]; + + //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + // protocolOp : Bind Request + //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + // We have to allocate a BindRequestPOJO + // LdapMessage ::=3D ... BindRequest ... + // BindRequest ::=3D [APPLICATION 0] SEQUENCE { ... (Length) + super.transitions[StatesEnum.BIND_REQUEST_TAG][0x60] =3D new Gr= ammarTransition( + StatesEnum.BIND_REQUEST_TAG, StatesEnum.BIND_REQUEST_LENGT= H, null ); + + super.transitions[StatesEnum.BIND_REQUEST_LENGTH][0x60] =3D new Gr= ammarTransition( + StatesEnum.BIND_REQUEST_LENGTH, StatesEnum.BIND_REQUEST_VA= LUE, + new GrammarAction( "Init BindRequest" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + LdapMessagePOJO ldapMessage =3D + ldapMessageContainer.getLdapMessage(); + + checkLength( ldapMessageContainer.getLdapMessage(), + ldapMessageContainer.getCurrentTLV() ); + + try + { + + // Now, we can allocate the BindRequest POJO + BindRequestPOJO bindRequest =3D ( BindRequestP= OJO ) + ldapMessageContainer.getPoolManager().allo= cate( + PoolEnum.BIND_REQUEST_POJO_POOL ); + + // As this is a new Constructed object, we hav= e to init its length + TLV tlv =3D ldapMessageContainer.ge= tCurrentTLV(); + int expectedLength =3D tlv.getLength().getLeng= th(); + + bindRequest.setExpectedLength( expectedLength = ); + bindRequest.setCurrentLength( 0 ); + bindRequest.setFather( ldapMessage ); + + // And we associate it to the ldapMessage POJO + ldapMessage.setProtocolOP( bindRequest ); + + } + catch ( PoolException pe ) + { + throw new DecoderException( + "Cannot allocate a BindRequest Pojo : " + = pe.getMessage() ); + } + } + } ); + + // LdapMessage ::=3D ... BindRequest ... + // BindRequest ::=3D [APPLICATION 0] SEQUENCE { ... (Value) + // Nothing to do, the Value is empty, this is a constructed TLV. W= e now can swith to the BindRequest Grammar + super.transitions[StatesEnum.BIND_REQUEST_VALUE][0x60] =3D new Gra= mmarTransition( + StatesEnum.BIND_REQUEST_VALUE, StatesEnum.BIND_REQUEST_VER= SION_TAG, null ); + + // BindRequest ::=3D ... version INTEGER (1 .. 127 ), ... (Tag) + // Nothing to do. + super.transitions[StatesEnum.BIND_REQUEST_VERSION_TAG][0x02] =3D n= ew GrammarTransition( + StatesEnum.BIND_REQUEST_VERSION_TAG, StatesEnum.BIND_REQUE= ST_VERSION_LENGTH, null ); + + // BindRequest ::=3D ... version INTEGER (1 .. 127 ), ... (Length) + // Checks the length + super.transitions[StatesEnum.BIND_REQUEST_VERSION_LENGTH][0x02] = =3D new GrammarTransition( + StatesEnum.BIND_REQUEST_VERSION_LENGTH, StatesEnum.BIND_RE= QUEST_VERSION_VALUE, + new GrammarAction( "Store version" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + checkLength( ldapMessageContainer.getLdapMessage()= .getProtocolOp(), + ldapMessageContainer.getCurrentTLV() ); + return; + } + } ); + + // BindRequest ::=3D ... version INTEGER (1 .. 127 ), ... (value) + // Checks that the Version is in [1, 127] + super.transitions[StatesEnum.BIND_REQUEST_VERSION_VALUE][0x02] =3D= new GrammarTransition( + StatesEnum.BIND_REQUEST_VERSION_VALUE, StatesEnum.BIND_REQ= UEST_NAME_TAG, + new GrammarAction( "Store version" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + BindRequestPOJO bindRequestMessage =3D ( Bi= ndRequestPOJO ) + ldapMessageContainer.getLdapMessage().getProto= colOp(); + + // The current TLV should be a integer between 1 a= nd 127 + // We get it and store it in Version + TLV tlv =3D ldapMessageContainer.getCurrentT= LV(); + + Value value =3D tlv.getValue(); + + int version =3D IntegerDecoder.parse( value, 1, = 127 ); + + bindRequestMessage.setVersion( version ); + + return; + } + } ); + + // BindRequest ::=3D ... name LDAPDN, ... (Tag) + // Nothing to do. The tag is supposed to be 0x04 + super.transitions[StatesEnum.BIND_REQUEST_NAME_TAG][0x04] =3D new = GrammarTransition( + StatesEnum.BIND_REQUEST_NAME_TAG, StatesEnum.BIND_REQUEST_= NAME_LENGTH, null ); + + // BindRequest ::=3D ... name LDAPDN, ... (Length) + // We just check the length. + super.transitions[StatesEnum.BIND_REQUEST_NAME_LENGTH][0x04] =3D n= ew GrammarTransition( + StatesEnum.BIND_REQUEST_NAME_LENGTH, StatesEnum.BIND_REQUE= ST_NAME_VALUE, + new GrammarAction( "Check Bind Name Length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + BindRequestPOJO bindRequestMessage =3D ( BindReque= stPOJO ) + ldapMessageContainer.getLdapMessage().getProtocolO= p(); + =20 + TLV tlv =3D + ldapMessageContainer.getCurrentTLV(); + + + checkLength( bindRequestMessage, tlv ); + =20 + // We have to handle the special case of a 0 lengt= h name + if (tlv.getLength().getLength() =3D=3D 0) + { + bindRequestMessage.setName( MutableString.EMPT= Y_STRING ); + } + =20 + return; + } + } ); + + // BindRequest ::=3D ... name LDAPDN, ... (Value) + // We have to store the name + super.transitions[StatesEnum.BIND_REQUEST_NAME_VALUE][0x04] =3D ne= w GrammarTransition( + StatesEnum.BIND_REQUEST_NAME_VALUE, + StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG, + new GrammarAction( "Store Bind Name value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + BindRequestPOJO bindRequestMessage =3D ( BindReque= stPOJO ) + ldapMessageContainer.getLdapMessage().getProtocolO= p(); + + // Get the Value and store it in the BindRequest + TLV tlv =3D ldapMessage= Container.getCurrentTLV(); + + + bindRequestMessage.setName( LdapDN.parseDN( + ldapMessageContainer.getPoolManager(), tlv= .getValue().getData() ) ); + return; + } + } ); + + // BindRequest ::=3D ... authentication AuthenticationChoice } + // AuthenticationChoice ::=3D CHOICE { + // The tag might be either 0x80 (SimpleAuthentication) or 0x83 (Sa= slAuthentication) + //----------------------------------------------------------------= ---------------------------- + // If it's 0x80, it is a SimpleAuthentication. + //----------------------------------------------------------------= ---------------------------- + // Nothing to do. + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TA= G][( 0x80 & 0x00FF )] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= CHOICE_TAG, + StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH, null= ); + + // AuthenticationChoice ::=3D CHOICE { + // simple [0] OCTET STRING, (Length) + // We just have to check the length, and to allocate an authentica= tion POJO + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LE= NGTH][( 0x80 & 0x00FF )] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= SIMPLE_LENGTH, + StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE, + new GrammarAction( "Check simple authentication length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + BindRequestPOJO bindRequestMessage =3D ( BindReque= stPOJO ) + ldapMessageContainer.getLdapMessage().getProtocolO= p(); + =20 + TLV tlv =3D ldapMessage= Container.getCurrentTLV(); + + checkLength( bindRequestMessage, tlv ); + + // Allocate the Authentication POJO + SimpleAuthenticationPOJO authentication =3D null; + =20 + try + { + + authentication =3D ( SimpleAuthenticationPOJO ) + ldapMessageContainer.getPoolManager().allo= cate( + PoolEnum.SIMPLE_AUTH_POJO_POOL ); + + authentication.setFather( bindRequestMessage ); + + bindRequestMessage.setAuthentication( authenti= cation ); + } + catch ( PoolException pe ) + { + throw new DecoderException( + "Cannot allocate a SimpleAuthentication Po= jo : " + pe.getMessage() ); + } + + // We have to handle the special case of a 0 lengt= h simple + if (tlv.getLength().getLength() =3D=3D 0) + { + authentication.setSimple( new byte[]{} ); + } + =20 + return; + } + } ); + + // AuthenticationChoice ::=3D CHOICE { + // simple [0] OCTET STRING, (Value) + // We have to create an Authentication POJO to store the credentia= ls. + // The nextState is GRAMMAR_END + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VA= LUE][( 0x80 & 0x00FF )] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= SIMPLE_VALUE, + StatesEnum.GRAMMAR_END, + new GrammarAction( "Store Bind Simple Authentication value= " ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + =20 + BindRequestPOJO bindRequestMessage =3D ( BindReque= stPOJO ) + ldapMessageContainer.getLdapMessage().getProtocolO= p(); + =20 + SimpleAuthenticationPOJO simpleAuthentication =3D = (SimpleAuthenticationPOJO)bindRequestMessage.getAuthentication(); + + TLV tlv =3D ldapMessageContainer.getC= urrentTLV(); + + // Get the simple value + // Store the simple in the authentication + simpleAuthentication.setSimple( tlv.getValue().get= Data() ); + } + } ); + + //----------------------------------------------------------------= ---------------------------- + // If it's 0x83, it is a Sasl Credentials. + // AuthenticationChoice ::=3D CHOICE { + // ... + // sasl [3] SaslCredentials } + // + // SaslCredentials ::=3D SEQUENCE { + // mechanism LDAPSTRING, + // credentials OCTET STRING OPTIONNAL } + //----------------------------------------------------------------= ---------------------------- + // AuthenticationChoice ::=3D CHOICE { + // sasl [3] saslCredentials, (Tag) + // Nothing to do. In fact, 0x83 is the mechanism tag.=20 + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TA= G][( 0x83 & 0x00FF )] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= CHOICE_TAG, + StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_LENGTH, n= ull ); + + // AuthenticationChoice ::=3D CHOICE { + // sasl [3] saslCredentials } + // + // SaslCredentials ::=3D SEQUENCE { + // mechanism LDAPSTRING, (Length) + // ... + // We just have to check the length. + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM= _LENGTH][( 0x83 & 0x00FF )] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= MECHANISM_LENGTH, + StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE, + new GrammarAction( "Check sasl authentication mechanism le= ngth" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + BindRequestPOJO bindRequestMessage =3D ( BindReque= stPOJO ) + ldapMessageContainer.getLdapMessage().getProtocolO= p(); + + TLV tlv =3D ldapMessageContainer.getC= urrentTLV(); + =20 + checkLength( bindRequestMessage, tlv ); + + // Create the SaslAuthentication POJO + SaslAuthenticationPOJO authentication =3D null; + + try + { + authentication =3D ( SaslAuthenticationPOJO ) + ldapMessageContainer.getPoolManager().allo= cate( + PoolEnum.SASL_AUTH_POJO_POOL ); + + authentication.setFather( bindRequestMessage ); + + bindRequestMessage.setAuthentication( authenti= cation ); + } + catch ( PoolException pe ) + { + throw new DecoderException( + "Cannot allocate a SaslAuthentication Pojo= : " + pe.getMessage() ); + } + + // We have to handle the special case of a 0 lengt= h mechanism + if (tlv.getLength().getLength() =3D=3D 0) + { + authentication.setMechanism( MutableString.EMP= TY_STRING ); + } + + return; + } + } ); + + // AuthenticationChoice ::=3D CHOICE { + // sasl [3] saslCredentials } + // + // SaslCredentials ::=3D SEQUENCE { + // mechanism LDAPSTRING, (Value) + // ... + // We have to store the mechanism. + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM= _VALUE][( 0x83 & 0x00FF )] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= MECHANISM_VALUE, + StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG, + new GrammarAction( "Create Bind sasl Authentication POJO" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( = LdapMessageContainer ) + container; + + BindRequestPOJO bindRequestMessage =3D ( Bi= ndRequestPOJO ) + ldapMessageContainer.getLdapMessage().getProto= colOp(); + =20 + SaslAuthenticationPOJO saslAuthentication =3D (Sas= lAuthenticationPOJO)bindRequestMessage.getAuthentication(); + + MutableString mechanism =3D LdapString.parse( + ldapMessageContainer.getPoolManager(), + ldapMessageContainer.getCurrentTLV().getVa= lue().getData() ); + =20 + saslAuthentication.setMechanism( mechanism ); + =20 + return; + } + } ); + + //----------------------------------------------------------------= ---------------------------- + // SaslCredentials ::=3D SEQUENCE { + // ... + // credentials OCTET STRING OPTIONAL } (Tag) + //----------------------------------------------------------------= ---------------------------- + // We may have a credential, or nothing, as it's an optional eleme= nt. + // The tag will have one of those values : + // - 0x04 if it's a credentials + // - 0x80 if it's a control + // - any other value is an error. + // + // It's a credential if it's 0x04 + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIA= LS_TAG][0x04] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= CREDENTIALS_TAG, + StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_LENGTH,= null ); + + // It's a control if it's 0x80 + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIA= LS_TAG][(0x80 & 0x00FF)] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= CREDENTIALS_TAG, + StatesEnum.GRAMMAR_END, null ); + =20 + // SaslCredentials ::=3D SEQUENCE { + // ... + // credentials OCTET STRING OPTIONAL } (Length) + // We just have to check the length + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIA= LS_LENGTH][0x04] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= CREDENTIALS_LENGTH, + StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE, + new GrammarAction( "Check sasl authentication credentials = length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + =20 + BindRequestPOJO bindRequestMessage =3D ( Bi= ndRequestPOJO ) + ldapMessageContainer.getLdapMessage().getProtocolO= p(); + + TLV tlv =3D ldapMessageContainer.getC= urrentTLV(); + =20 + checkLength( bindRequestMessage, tlv ); + + // We have to handle the special case of a 0 lengt= h credentials + if (tlv.getLength().getLength() =3D=3D 0) + { + SaslAuthenticationPOJO saslAuthentication =3D = ( SaslAuthenticationPOJO ) ( bindRequestMessage + .getAuthentication() ); + + saslAuthentication.setCredentials( new byte[]{= } ); + } + + return; + } + } ); + + // SaslCredentials ::=3D SEQUENCE { + // ... + // credentials OCTET STRING OPTIONAL } (Value) + // + // We have to get the Credentials and store it in the SaslAuthenti= cationPOJO. + // Two different following states are possible : + // - a Controls tag (0x80) + // - or nothing at all (end of the BindRequest). + // We just have to transit to the first case, which will accept or= not the transition. + // This is done by transiting to the GRAMMAR_END state + super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIA= LS_VALUE][0x04] =3D + new GrammarTransition( StatesEnum.BIND_REQUEST_AUTHENTICATION_= CREDENTIALS_VALUE, + StatesEnum.GRAMMAR_END, + new GrammarAction( "Store Bind sasl Authentication credent= ials value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + BindRequestPOJO bindRequestMessage =3D ( Bi= ndRequestPOJO ) + ldapMessageContainer.getLdapMessage().getProtocolO= p(); + =20 + SaslAuthenticationPOJO saslAuthentication =3D ( Sa= slAuthenticationPOJO ) ( bindRequestMessage + .getAuthentication() ); + + // Get the Value and store it in the BindRequest + TLV tlv =3D ldapMessageContainer= .getCurrentTLV(); + + saslAuthentication.setCredentials( tlv.getValue().= getData() ); + return; + } + } ); + } +} Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap= /codec/grammars/BindResponseGrammar.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/s= rc/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java?view= =3Dauto&rev=3D161400 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/BindResponseGrammar.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/BindResponseGrammar.java Thu Apr 14 22:42:23 2005 @@ -0,0 +1,227 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.asn1.ldap.codec.grammars; + +import org.apache.asn1.ber.containers.IAsn1Container; +import org.apache.asn1.ber.grammar.AbstractGrammar; +import org.apache.asn1.ber.grammar.GrammarAction; +import org.apache.asn1.ber.grammar.GrammarTransition; +import org.apache.asn1.ber.grammar.IGrammar; +import org.apache.asn1.ber.grammar.StatesEnum; +import org.apache.asn1.ber.tlv.TLV; +import org.apache.asn1.ldap.codec.DecoderException; +import org.apache.asn1.ldap.codec.LdapMessageContainer; +import org.apache.asn1.ldap.pojo.BindResponsePOJO; +import org.apache.asn1.ldap.pojo.LdapMessagePOJO; +import org.apache.asn1.util.pools.PoolEnum; +import org.apache.asn1.util.pools.PoolException; + +import org.apache.log4j.Logger; + + +/** + * This class implements the LdapMessage. All the actions are declared in = this + * class. As it is a singleton, these declaration are only done once. + *=20 + * If an action is to be added or modified, this is where the work is to b= e done ! + *=20 + * @author Apache Directory Pr= oject + */ +public class BindResponseGrammar extends AbstractGrammar implements IGramm= ar +{ + //~ Static fields/initializers ---------------------------------------= -------------------------- + + /** The logger */ + private static final Logger log =3D Logger.getLogger( BindResponseGram= mar.class ); + + /** Logging speed up */ + private static final boolean DEBUG =3D log.isDebugEnabled(); + + /** The instance of grammar. LdapMessage is a singleton */ + private static IGrammar instance =3D new BindResponseGrammar(); + + //~ Constructors -----------------------------------------------------= -------------------------- + + /** + * Creates a new LdapMessageGrammar object. + */ + private BindResponseGrammar() + { + name =3D BindResponseGrammar.class.getName(); + + // We have 17 differents states, so 16 transitions between states. + super.transitions =3D new GrammarTransition[StatesEnum.LAST_LDAP_S= TATE][256]; + + //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + // BindResponse Message + //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + // BindResponse ::=3D APPLICATION 1] SEQUENCE { + // COMPONENTS OF LDAPResult, + // ... + // Nothing to do + super.transitions[StatesEnum.BIND_RESPONSE_TAG][0x61] =3D new Gram= marTransition( + StatesEnum.BIND_RESPONSE_TAG, StatesEnum.BIND_RESPONSE_LEN= GTH, null ); + + // We have to allocate a BindRequestPOJO + // LdapMessage ::=3D ... BindResponse ... + // BindResponse ::=3D [APPLICATION 1] SEQUENCE { ... (Length) + super.transitions[StatesEnum.BIND_RESPONSE_LENGTH][0x61] =3D new G= rammarTransition( + StatesEnum.BIND_RESPONSE_LENGTH, StatesEnum.BIND_RESPONSE_= VALUE, + new GrammarAction( "Init BindReponse" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + LdapMessagePOJO ldapMessage =3D + ldapMessageContainer.getLdapMessage(); + + checkLength( ldapMessageContainer.getLdapMessage(), + ldapMessageContainer.getCurrentTLV() ); + + try + { + + // Now, we can allocate the BindRequest POJO + BindResponsePOJO bindResponse =3D ( BindRespon= sePOJO ) + ldapMessageContainer.getPoolManager().allo= cate( + PoolEnum.BIND_RESPONSE_POJO_POOL ); + + // As this is a new Constructed object, we hav= e to init its length + TLV tlv =3D ldapMessageContainer.ge= tCurrentTLV(); + int expectedLength =3D tlv.getLength().getLeng= th(); + bindResponse.setExpectedLength( expectedLength= ); + bindResponse.setCurrentLength( 0 ); + bindResponse.setFather( ldapMessage ); + + // And we associate it to the ldapMessage POJO + ldapMessage.setProtocolOP( bindResponse ); + + } + catch ( PoolException pe ) + { + throw new DecoderException( + "Cannot allocate a BindResponse Pojo : " += pe.getMessage() ); + } + } + } ); + + // LdapMessage ::=3D ... BindResponse ... + // BindResponse ::=3D [APPLICATION 1] SEQUENCE { ... (Value) + // The first Tag will be the LDAPResult Tag (0x0A). So we have to = switch the grammar. + super.transitions[StatesEnum.BIND_RESPONSE_VALUE][0x61] =3D new Gr= ammarTransition( + StatesEnum.BIND_RESPONSE_VALUE, StatesEnum.BIND_RESPONSE_L= DAP_RESULT, null ); + + // LdapMessage ::=3D ... BindResponse ... + // BindResponse ::=3D [APPLICATION 1] SEQUENCE { ... (Value) + // The first Tag will be the LDAPResult Tag (0x0A). So we have to = switch the grammar. + super.transitions[StatesEnum.BIND_RESPONSE_LDAP_RESULT][0x0A] =3D = new GrammarTransition( + StatesEnum.BIND_RESPONSE_LDAP_RESULT, StatesEnum.LDAP_RESU= LT_GRAMMAR_SWITCH, null ); + + // BindResponse ::=3D APPLICATION 1] SEQUENCE { + // ... + // serverSaslCreds [7] OCTET STRING OPTIONAL } (Tag) + // It's a server sasl credential if the tag is 0x87 + // Otherwise, if the tag is 0x80, it's a control + super.transitions[StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG][= 0x87] =3D + new GrammarTransition( StatesEnum.BIND_RESPONSE_SERVER_SASL_CR= EDS_TAG, + StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_LENGTH, null ); + + // It's a control if it's 0x80. We have to quit this grammar. + super.transitions[StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG][= ( 0x80 & 0x00FF )] =3D + new GrammarTransition( StatesEnum.BIND_RESPONSE_SERVER_SASL_CR= EDS_TAG, + StatesEnum.GRAMMAR_END, null ); + + // BindResponse ::=3D APPLICATION 1] SEQUENCE { + // ... + // serverSaslCreds [7] OCTET STRING OPTIONAL } (Length) + // We have to check the length + super.transitions[StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_LENGT= H][0x87] =3D + new GrammarTransition( StatesEnum.BIND_RESPONSE_SERVER_SASL_CR= EDS_LENGTH, + StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE, + new GrammarAction( "Check server sasl credentials length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + BindResponsePOJO bindResponseMessage =3D ( Bin= dResponsePOJO ) + ldapMessageContainer.getLdapMessage().getProto= colOp(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + checkLength( bindResponseMessage, tlv ); + + // We have to handle the special case of a 0 lengt= h server sasl credentials + if ( tlv.getLength().getLength() =3D=3D 0 ) + { + bindResponseMessage.setServerSaslCreds( new by= te[] {} ); + } + + return; + } + } ); + + // BindResponse ::=3D APPLICATION 1] SEQUENCE { + // ... + // serverSaslCreds [7] OCTET STRING OPTIONAL } (Length) + // + // We have to get the server sasl Credentials and store it in the = BindResponse POJO. + // Two different following states are possible : + // - a Controls tag (0x80) + // - nothing at all (end of the BindResponse). + // We just have to transit to the first case, which will accept or= not the transition. + // This is done by transiting to the GRAMMAR_END state + super.transitions[StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE= ][0x87] =3D + new GrammarTransition( StatesEnum.BIND_RESPONSE_SERVER_SASL_CR= EDS_VALUE, + StatesEnum.GRAMMAR_END, + new GrammarAction( "Store server sasl credentials value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + BindResponsePOJO bindResponseMessage =3D ( Bin= dResponsePOJO ) + ldapMessageContainer.getLdapMessage().getProto= colOp(); + + // Get the Value and store it in the BindRequest + TLV tlv =3D ldapMessageContainer.getCurrentTLV(); + + bindResponseMessage.setServerSaslCreds( tlv.getVal= ue().getData() ); + return; + } + } ); + + } + + //~ Methods ----------------------------------------------------------= -------------------------- + + /** + * Get the instance of this grammar + * + * @return An instance on the LdapMessage Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +} Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap= /codec/grammars/LdapControlGrammar.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/s= rc/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java?view=3D= auto&rev=3D161400 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/LdapControlGrammar.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/LdapControlGrammar.java Thu Apr 14 22:42:23 2005 @@ -0,0 +1,69 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.asn1.ldap.codec.grammars; + +import org.apache.asn1.ber.grammar.AbstractGrammar; +import org.apache.asn1.ber.grammar.GrammarTransition; +import org.apache.asn1.ber.grammar.IGrammar; +import org.apache.asn1.ber.grammar.StatesEnum; + +import org.apache.log4j.Logger; + + +/** + * This class implements the LdapMessage. All the actions are declared in = this + * class. As it is a singleton, these declaration are only done once. + *=20 + * If an action is to be added or modified, this is where the work is to b= e done ! + *=20 + * @author Apache Directory Pr= oject + */ +public class LdapControlGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ---------------------------------------= -------------------------- + + /** The logger */ + private static final Logger log =3D Logger.getLogger( LdapControlGramm= ar.class ); + + /** Logging speed up */ + private static final boolean DEBUG =3D log.isDebugEnabled(); + + /** The instance of grammar. LdapControlGrammar is a singleton */ + private static IGrammar instance =3D new LdapControlGrammar(); + + /** + * Get the instance of this grammar + * + * @return An instance on the LdapControl Grammar + */ + public static IGrammar getInstance() + { + return instance; + } + =20 + //~ Constructors -----------------------------------------------------= -------------------------- + /** + * Creates a new LdapControlGrammar object. + */ + private LdapControlGrammar() + { + name =3D LdapControlGrammar.class.getName(); + + super.transitions =3D new GrammarTransition[StatesEnum.CONTROL_LAS= T_STATE][256]; + + } +} Copied: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/lda= p/codec/grammars/LdapMessageGrammar.java (from r160136, directory/sandbox/t= runk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.= java) URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/s= rc/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java?view=3D= diff&rev=3D161400&p1=3Ddirectory/sandbox/trunk/asn1-new-codec/src/java/org/= apache/asn1/ldap/codec/LdapMessageGrammar.java&r1=3D160136&p2=3Ddirectory/s= andbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/Ld= apMessageGrammar.java&r2=3D161400 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/LdapMessageGrammar.java (original) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/LdapMessageGrammar.java Thu Apr 14 22:42:23 2005 @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.apache.asn1.ldap.codec; +package org.apache.asn1.ldap.codec.grammars; =20 import org.apache.asn1.ber.containers.IAsn1Container; import org.apache.asn1.ber.grammar.AbstractGrammar; @@ -24,14 +24,10 @@ import org.apache.asn1.ber.grammar.StatesEnum; import org.apache.asn1.ber.tlv.TLV; import org.apache.asn1.ber.tlv.Value; +import org.apache.asn1.ldap.codec.DecoderException; +import org.apache.asn1.ldap.codec.LdapMessageContainer; import org.apache.asn1.ldap.codec.utils.IntegerDecoder; -import org.apache.asn1.ldap.pojo.AbstractPOJO; -import org.apache.asn1.ldap.pojo.BindRequestPOJO; -import org.apache.asn1.ldap.pojo.BindResponsePOJO; import org.apache.asn1.ldap.pojo.LdapMessagePOJO; -import org.apache.asn1.ldap.pojo.LdapPOJO; -import org.apache.asn1.ldap.pojo.SimpleAuthenticationPOJO; -import org.apache.asn1.util.MutableString; import org.apache.asn1.util.pools.PoolEnum; import org.apache.asn1.util.pools.PoolException; =20 @@ -56,51 +52,37 @@ /** Logging speed up */ private static final boolean DEBUG =3D log.isDebugEnabled(); =20 - /** The instance of grammar. LdapMessage is a singleton */ + /** The instance of grammar. LdapMessageGrammar is a singleton */ private static IGrammar instance =3D new LdapMessageGrammar(); - =20 - static - { - getInstance().setName("LdapMessageGrammar"); - } =20 - //~ Constructors -----------------------------------------------------= -------------------------- /** - * DOCUMENT ME! + * Get the instance of this grammar * - * @return DOCUMENT ME! + * @return An instance on the LdapMessage Grammar */ public static IGrammar getInstance() { return instance; } - - private void checkLength(LdapPOJO ldapPOJO, TLV tlv) throws DecoderExc= eption - { - // Create a new expected Length - int expectedLength =3D tlv.getLength().getLength(); - =20 - int tlvLength =3D tlv.getSize(); -=09 - // An exception will be thrown if the current length exceed the expec= ted length - ((AbstractPOJO)ldapPOJO).addLength(expectedLength + tlvLength); - } - + =20 + //~ Constructors -----------------------------------------------------= -------------------------- /** * Creates a new LdapMessageGrammar object. */ private LdapMessageGrammar() { =20 - // We have 17 differents states, so 16 transitions between states. - super.transitions =3D new GrammarTransition[StatesEnum.LAST_LDAP_S= TATE][256]; + name =3D LdapMessageGrammar.class.getName(); + + // We have 9 differents states, so 8 transitions between states. + super.transitions =3D new GrammarTransition[StatesEnum.LAST_LDAP_M= ESSAGE_STATE][256]; =20 //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D // LdapMessage=20 //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D // LDAPMessage --> SEQUENCE { ... (Tag) // We have a LDAPMessage, and the tag must be 0x30 - super.transitions[StatesEnum.LDAP_MESSAGE_TAG][0x30] =3D new Gramm= arTransition( "LdapMessage Tag", + super.transitions[StatesEnum.LDAP_MESSAGE_TAG][0x30] =3D new Gramm= arTransition( StatesEnum.LDAP_MESSAGE_TAG, StatesEnum.LDAP_MESSAGE_LENGTH, new GrammarAction( "LdapMe= ssage Tag" ) { public void action( IAsn1Container container ) throws = DecoderException @@ -128,7 +110,7 @@ =20 // LDAPMessage --> SEQUENCE { ... (Length) // Ok, get the LdapMessage length - super.transitions[StatesEnum.LDAP_MESSAGE_LENGTH][0x30] =3D new Gr= ammarTransition( "LdapMessage Length", + super.transitions[StatesEnum.LDAP_MESSAGE_LENGTH][0x30] =3D new Gr= ammarTransition( StatesEnum.LDAP_MESSAGE_LENGTH, StatesEnum.LDAP_MESSAGE_VALUE, new GrammarAction( "LdapMes= sage Length" ) { public void action( IAsn1Container container ) throws = DecoderException @@ -145,24 +127,25 @@ } ); =20 // LDAPMessage --> SEQUENCE { ... (Value) - // Nothing to do, it's a constructed TLV - super.transitions[StatesEnum.LDAP_MESSAGE_VALUE][0x30] =3D new Gra= mmarTransition( "LdapMessage Value", StatesEnum.LDAP_MESSAGE_ID_TAG, null); + // Nothing to do, it's a constructed TLV. It's just a phantom tran= sition ... + super.transitions[StatesEnum.LDAP_MESSAGE_VALUE][0x30] =3D new Gra= mmarTransition( StatesEnum.LDAP_MESSAGE_VALUE, StatesEnum.LDAP_MESSAGE_ID_T= AG, null); =20 - //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + //----------------------------------------------------------------= ---------------------------- // LdapMessage Message ID=20 - //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + //----------------------------------------------------------------= ---------------------------- // LDAPMessage --> ... MessageId ...(Tag) // The tag must be 0x02. Nothing special to do. - super.transitions[StatesEnum.LDAP_MESSAGE_ID_TAG][0x02] =3D new Gr= ammarTransition( "MessageId Tag", StatesEnum.LDAP_MESSAGE_ID_LENGTH, null); + super.transitions[StatesEnum.LDAP_MESSAGE_ID_TAG][0x02] =3D new Gr= ammarTransition( StatesEnum.LDAP_MESSAGE_ID_TAG, StatesEnum.LDAP_MESSAGE_ID= _LENGTH, null); =20 // LDAPMessage --> ... MessageId ...(Length) // Checks the length - super.transitions[StatesEnum.LDAP_MESSAGE_ID_LENGTH][0x02] =3D new= GrammarTransition( "MessageId Length", StatesEnum.LDAP_MESSAGE_ID_VALUE,=20 + super.transitions[StatesEnum.LDAP_MESSAGE_ID_LENGTH][0x02] =3D new= GrammarTransition( StatesEnum.LDAP_MESSAGE_ID_LENGTH, StatesEnum.LDAP_MESS= AGE_ID_VALUE,=20 new GrammarAction( "Check MessageId Length " ) { public void action( IAsn1Container container ) throws = DecoderException { - checkLength(((LdapMessageContainer)container).getLdap= Message(), ((LdapMessageContainer)container).getCurrentTLV()); + LdapMessageContainer ldapMessageContainer =3D ((Ld= apMessageContainer)container); + checkLength(ldapMessageContainer.getLdapMessage(), ld= apMessageContainer.getCurrentTLV()); =20 return; } @@ -170,7 +153,8 @@ =20 // LDAPMessage --> ... MessageId ...(Value) // Checks that MessageId is in [0 .. 2147483647] and store the val= ue in the LdapMessage POJO - super.transitions[StatesEnum.LDAP_MESSAGE_ID_VALUE][0x02] =3D new = GrammarTransition( "MessageId Value", StatesEnum.PROTOCOL_OP_TAG, + // (2147483647 =3D Integer.MAX_VALUE) + super.transitions[StatesEnum.LDAP_MESSAGE_ID_VALUE][0x02] =3D new = GrammarTransition( StatesEnum.LDAP_MESSAGE_ID_VALUE, StatesEnum.PROTOCOL_OP= _TAG, new GrammarAction( "Store MessageId" ) { public void action( IAsn1Container container ) throws = DecoderException @@ -185,9 +169,9 @@ =20 Value value =3D tlv.getValue(); =20 - int messageId =3D IntegerDecoder.parse( value , = 0, 2147483647); + int messageId =3D IntegerDecoder.parse( value , = 0, Integer.MAX_VALUE); =20 - if ( ( messageId < 0 ) || ( messageId > 2147483647= ) ) + if ( ( messageId < 0 ) || ( messageId > Integer.MA= X_VALUE ) ) { throw new DecoderException( "The message ID must be between (0 .. 2 14= 7 483 647)" ); @@ -201,304 +185,25 @@ } } ); =20 - //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - // LdapResult=20 - //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - // LDAPResult --> SEQUENCE {=20 - // resultCode ENUMERATED { ... (Tag) - // We have a LDAPResult Enumerated, the tag must be 0x0A - // Nothing to do - super.transitions[StatesEnum.LDAP_RESULT_CODE_TAG][0x0A] =3D new G= rammarTransition( "LdapResult resultCode Tag", - StatesEnum.LDAP_RESULT_CODE_LENGTH, null); - - // LDAPResult --> SEQUENCE {=20 - // resultCode ENUMERATED { ... (Length) - // The length must be 1 (as the result code is between 0 and 90) - super.transitions[StatesEnum.LDAP_RESULT_CODE_LENGTH][0x0A] =3D ne= w GrammarTransition( "LdapResult resultCode Length", - StatesEnum.LDAP_RESULT_CODE_VALUE, new GrammarAction( "Lda= pResult resultCode Length" ) - { - public void action( IAsn1Container container ) throws = DecoderException - { - // We have to check that the length is 1 - TLV tlv =3D ((LdapMessageContainer)container).getC= urrentTLV(); - =20 - if ( tlv.getLength().getLength() !=3D 1 ) - { - throw new DecoderException("The LdapResult result= Code must be 1 byte length, got " + tlv.getLength().getLength()); - } - =20 - checkLength(((LdapMessageContainer)container).getLdap= Message(), tlv); - - return; - } - } ); - =20 - // LDAPResult --> SEQUENCE {=20 - // resultCode ENUMERATED { ... (Length) - // The value must be in {[0-8], [10-21], [32-35], 36, [48-54], [64= -69], 71, 80} - super.transitions[StatesEnum.LDAP_RESULT_CODE_VALUE][0x0A] =3D new= GrammarTransition( "LdapMessage Value", StatesEnum.LDAP_RESULT_MATCHED_DN_= TAG, null); - - //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - // protocolOp : Bind Request=20 - //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - // If the Tag is 0x60, then it's a BindRequest. Nothing to do whil= e the length is not verified. + //****************************************************************= **************************** + // If the Tag is 0x60, then it's a BindRequest. Nothing to do whil= e the length is not checked. + // If the Tag is 0x61, then it's a BindResponse.=20 + //****************************************************************= **************************** + =20 + //----------------------------------------------------------------= ---------------------------- + // BindRequest Message. + //----------------------------------------------------------------= ---------------------------- // LdapMessage ::=3D ... BindRequest ... // BindRequest ::=3D [APPLICATION 0] SEQUENCE { ... (Tag) - super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x60] =3D new Gramma= rTransition( "BindRequest Tag", StatesEnum.PROTOCOL_OP_LENGTH, null ); - - // We have to allocate a BindRequestPOJO - // LdapMessage ::=3D ... BindRequest ... - // BindRequest ::=3D [APPLICATION 0] SEQUENCE { ... (Length) - super.transitions[StatesEnum.PROTOCOL_OP_LENGTH][0x60] =3D new Gra= mmarTransition( "BindRequest Length", StatesEnum.PROTOCOL_OP_VALUE,=20 - new GrammarAction( "Init BindRequest" ) - { - public void action( IAsn1Container container ) throws = DecoderException - { - - LdapMessageContainer ldapMessageContainer =3D (LdapMe= ssageContainer)container; - LdapMessagePOJO ldapMessage =3D ldapMessageContainer.= getLdapMessage(); - - checkLength(((LdapMessageContainer)container).getLdap= Message(), ((LdapMessageContainer)container).getCurrentTLV()); - =09 - try=20 - { - // Now, we can allocate the BindRequest POJO - LdapPOJO bindRequest =3D (LdapPOJO)ldapMessageContai= ner.getPoolManager().allocate(PoolEnum.BIND_REQUEST_POJO_POOL); - =09 - // As this is a new Constructed object, we have to i= nit its length - TLV tlv =3D ldapMessageContainer.getCurre= ntTLV(); - int expectedLength =3D tlv.getLength().getLength(= ); - ((BindRequestPOJO)bindRequest).setExpectedLength(exp= ectedLength); - ((BindRequestPOJO)bindRequest).setCurrentLength(0); - - // And we associate it to the ldapMessage POJO - ldapMessage.setProtocolOP(bindRequest); - =09 - } catch (PoolException pe)=20 - { - throw new DecoderException( - "Cannot allocate a BindRequest Pojo : = " + pe.getMessage() ); - } - } - }); - - // LdapMessage ::=3D ... BindRequest ... - // BindRequest ::=3D [APPLICATION 0] SEQUENCE { ... (Value) - // Nothing to do, the Value is empty, this is a constructed TLV - super.transitions[StatesEnum.PROTOCOL_OP_VALUE][0x60] =3D new Gram= marTransition( "BindRequest Value", StatesEnum.BIND_REQUEST_VERSION_TAG, nu= ll); - - // BindRequest ::=3D ... version INTEGER (1 .. 127 ), ... (Tag) - // Nothing to do. - super.transitions[StatesEnum.BIND_REQUEST_VERSION_TAG][0x02] =3D n= ew GrammarTransition( "Bind version Tag", StatesEnum.BIND_REQUEST_VERSION_L= ENGTH, null); - =20 - // BindRequest ::=3D ... version INTEGER (1 .. 127 ), ... (Length) - // Checks the length - super.transitions[StatesEnum.BIND_REQUEST_VERSION_LENGTH][0x02] = =3D new GrammarTransition( "Bind version Length", StatesEnum.BIND_REQUEST_V= ERSION_VALUE, - new GrammarAction( "Store version" ) - { - public void action( IAsn1Container container ) throws = DecoderException - { - - checkLength(((LdapMessageContainer)container).getLdap= Message().getProtocolOp(), ((LdapMessageContainer)container).getCurrentTLV(= )); - return; - } - } ); - - // BindRequest ::=3D ... version INTEGER (1 .. 127 ), ... (value) - // Checks that the Version is in [1, 127] - super.transitions[StatesEnum.BIND_REQUEST_VERSION_VALUE][0x02] =3D= new GrammarTransition( "Bind version Length", StatesEnum.BIND_REQUEST_NAME= _TAG, - new GrammarAction( "Store version" ) - { - public void action( IAsn1Container container ) throws = DecoderException - { - - LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) - container; - BindRequestPOJO bindRequestMessage =3D - (BindRequestPOJO)ldapMessageContainer.getLdapMess= age().getProtocolOp(); - - // The current TLV should be a integer between 1 a= nd 127 - // We get it and store it in Version - TLV tlv =3D ldapMessageContainer.getCurrentT= LV(); - - Value value =3D tlv.getValue(); - - int version =3D IntegerDecoder.parse( value, 1, = 127 ); - - bindRequestMessage.setVersion( version ); - - return; - } - } ); - - // BindRequest ::=3D ... name LDAPDN, ... (Tag) - // Nothing to do. The tag is supposed to be 0x04 - super.transitions[StatesEnum.BIND_REQUEST_NAME_TAG][0x04] =3D new = GrammarTransition( "bind name tag", StatesEnum.BIND_REQUEST_NAME_LENGTH, nu= ll); - =20 - // BindRequest ::=3D ... name LDAPDN, ... (Length) - // We just check the length. - super.transitions[StatesEnum.BIND_REQUEST_NAME_LENGTH][0x04] =3D n= ew GrammarTransition( "bind name length", StatesEnum.BIND_REQUEST_NAME_VALU= E, - new GrammarAction( "Check Bind Name Length" ) - { - public void action( IAsn1Container container ) throws = DecoderException - { - checkLength(((LdapMessageContainer)container).getLdap= Message().getProtocolOp(), ((LdapMessageContainer)container).getCurrentTLV(= )); - return; - } - } ); - - // BindRequest ::=3D ... name LDAPDN, ... (Value) - // We just check the length. - super.transitions[StatesEnum.BIND_REQUEST_NAME_VALUE][0x04] =3D ne= w GrammarTransition( "bind name value", StatesEnum.BIND_REQUEST_AUTHENTICAT= ION_CHOICE_TAG, - new GrammarAction( "Store Bind Name value" ) - { - public void action( IAsn1Container container ) throws = DecoderException - { - - LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer )container; - =20 - // Get the Value and store it in the BindRequest=20 - TLV tlv =3D ldapMessageContainer.getCurrentTLV(= ); - =20 - MutableString name =3D null; - =20 - try - { - name =3D ( MutableString ) ldapMessageContainer.getP= oolManager().allocateString(tlv.getValue().getData().length); - }=20 - catch (PoolException pe) - { - throw new DecoderException( - "Cannot allocate a MutableString for Name : = " + pe.getMessage() ); - } - =20 - name.setData(tlv.getValue().getData()); - =20 - - BindRequestPOJO bindRequestMessage =3D (Bin= dRequestPOJO)ldapMessageContainer.getLdapMessage().getProtocolOp(); - - bindRequestMessage.setName(name); - return; - } - } ); - - // BindRequest ::=3D ... authentication AuthenticationChoice } - // AuthenticationChoice ::=3D CHOICE { - // The tag might be either 0x80 (SimpleAuthentication) or 0x83 (Sa= slAuthentication) - // Here, it's 0x80, so a SimpleAuthentication.=20 - // Nothing to do. - super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TA= G][( 0x80 & 0x00FF )] =3D new GrammarTransition( "Bind Simple Authenticatio= n Tag", StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH, null); - =20 - // AuthenticationChoice ::=3D CHOICE { - // simple [0] OCTET STRING, (Length) - super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LE= NGTH][( 0x80 & 0x00FF )] =3D new GrammarTransition( "Bind Simple Authentica= tion Length", StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE,=20 - new GrammarAction( "Check simple authentication length" )=20 - { - public void action( IAsn1Container container ) throws = DecoderException - { - checkLength(((LdapMessageContainer)container).getLdap= Message().getProtocolOp(), ((LdapMessageContainer)container).getCurrentTLV(= )); - =20 - return; - } - } ); - - // AuthenticationChoice ::=3D CHOICE { - // simple [0] OCTET STRING, (Value) - super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VA= LUE][( 0x80 & 0x00FF )] =3D new GrammarTransition( "Bind Simple Authenticat= ion Value", -1, //StatesEnum.CONTROLS_TAG,=20 - new GrammarAction( "Store Bind Simple Authentication value= " ) - { - public void action( IAsn1Container container ) throws = DecoderException - { - - LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer )container; - =20 - // Get the Value and store it in the BindRequest=20 - TLV tlv =3D ldapMessageContainer.getCurrentTLV(= ); - =20 - MutableString simple =3D null; - =20 - try - { - simple =3D ( MutableString ) ldapMessageContainer.ge= tPoolManager().allocateString(tlv.getValue().getData().length); - }=20 - catch (PoolException pe) - { - throw new DecoderException( - "Cannot allocate a MutableString for simple = : " + pe.getMessage() ); - } - =20 - simple.setData(tlv.getValue().getData()); - - BindRequestPOJO bindRequestMessage =3D (Bin= dRequestPOJO)ldapMessageContainer.getLdapMessage().getProtocolOp(); - - try=20 - { - SimpleAuthenticationPOJO authentication =3D ( Sim= pleAuthenticationPOJO ) - ldapMessageContainer.getPoolManager().allocate( - PoolEnum.SIMPLE_AUTH_POJO_POOL ); - =20 - authentication.setSimple(simple); -=09 - bindRequestMessage.setAuthentication(authenticati= on); - return; - }=20 - catch (PoolException pe)=20 - { - throw new DecoderException( - "Cannot allocate a SimpleAuthenticatio= n Pojo : " + pe.getMessage() ); - } - } - } ); + // Nothing to do while the length is not checked. + super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x60] =3D new Gramma= rTransition( StatesEnum.PROTOCOL_OP_TAG, StatesEnum.BIND_REQUEST_GRAMMAR_SW= ITCH, null ); =20 - //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - // protocolOp : Bind Response=20 - //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - // If the Tag is 0x61, then it's a BindResponse. Nothing to do whi= le the length is not verified. + //----------------------------------------------------------------= ---------------------------- + // BindResponse Message. + //----------------------------------------------------------------= ---------------------------- // LdapMessage ::=3D ... BindResponse ... // BindResponse ::=3D [APPLICATION 1] SEQUENCE { ... (Tag) - super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x61] =3D new Gramma= rTransition( "BindResponse Tag", StatesEnum.PROTOCOL_OP_LENGTH, null ); - - // We have to allocate a BindResponsePOJO - // LdapMessage ::=3D ... BindResponse ... - // BindResponse ::=3D [APPLICATION 1] SEQUENCE { ... (Length) - super.transitions[StatesEnum.PROTOCOL_OP_LENGTH][0x61] =3D new Gra= mmarTransition( "BindResponse Length", StatesEnum.PROTOCOL_OP_VALUE,=20 - new GrammarAction( "Init BindReponse" ) - { - public void action( IAsn1Container container ) throws = DecoderException - { - - LdapMessageContainer ldapMessageContainer =3D (LdapMe= ssageContainer)container; - LdapMessagePOJO ldapMessage =3D ldapMessageContainer.= getLdapMessage(); - - checkLength(((LdapMessageContainer)container).getLdap= Message(), ((LdapMessageContainer)container).getCurrentTLV()); - =09 - try=20 - { - // Now, we can allocate the BindResponse POJO - LdapPOJO bindResponse=3D (LdapPOJO)ldapMessageContai= ner.getPoolManager().allocate(PoolEnum.BIND_RESPONSE_POJO_POOL); - =09 - // As this is a new Constructed object, we have to i= nit its length - TLV tlv =3D ldapMessageContainer.getCurre= ntTLV(); - int expectedLength =3D tlv.getLength().getLength(= ); - ((BindResponsePOJO)bindResponse).setExpectedLength(e= xpectedLength); - ((BindResponsePOJO)bindResponse).setCurrentLength(0); - - // And we associate it to the ldapMessage POJO - ldapMessage.setProtocolOP(bindResponse); - =09 - } catch (PoolException pe)=20 - { - throw new DecoderException( - "Cannot allocate a BindResponse Pojo := " + pe.getMessage() ); - } - } - }); - - // LdapMessage ::=3D ... BindResponse ... - // BindResponse ::=3D [APPLICATION 1] SEQUENCE { ... (Value) - // Ok, we have a LdapResult to parse. As it can be used in many di= fferent - // rules, we have to decode it using another grammar (LdapResultGr= ammar). - super.transitions[StatesEnum.PROTOCOL_OP_VALUE][0x61] =3D new Gram= marTransition( "BindResponse Value", StatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,= null); - + // We have to switch to the BindResponse grammar + super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x61] =3D new Gramma= rTransition( StatesEnum.PROTOCOL_OP_TAG, StatesEnum.BIND_RESPONSE_GRAMMAR_S= WITCH, null); } }