directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159164 - directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec
Date Sun, 27 Mar 2005 18:40:20 GMT
Author: elecharny
Date: Sun Mar 27 10:40:20 2005
New Revision: 159164

URL: http://svn.apache.org/viewcvs?view=rev&rev=159164
Log:
A first working version of the new ASN.1 LDAP decoder.

Added:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainer.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainerFactory.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainer.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainer.java?view=auto&rev=159164
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainer.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainer.java
Sun Mar 27 10:40:20 2005
@@ -0,0 +1,191 @@
+/*
+ *   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 implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec;
+
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.asn1.util.pools.LocalPoolManager;
+import org.apache.asn1.util.pools.PoolObject;
+
+
+/**
+ * The LdapMessage container stores all the messages decoded by the
+ * Asn1Decoder. When dealing whith an incoding PDU, we will obtain
+ * a LdapMessagePOJO in the ILdapContainer.
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapMessageContainer extends PoolObject implements IAsn1Container //extends
AbstractLdapContainer
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The current state of the decoding */
+    protected int state;
+
+    /** The current transition */
+    protected int transition;
+
+    /** The current TLV */
+    protected TLV tlv;
+
+    /** The pool that is associated with this container */
+    protected LocalPoolManager poolManager;
+
+    /** The grammar that is used to decode the ldapMessage */
+    protected IGrammar grammar;
+
+    /** The ldap message */
+    private LdapMessagePOJO ldapMessage;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new LdapMessageContainer object.
+     */
+    public LdapMessageContainer()
+    {
+        super( );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Release the LdapMessage POJO
+     */
+    public void free()
+    {
+        state      = 0;
+        transition = 0;
+        ldapMessage.free();
+
+        super.free();
+    }
+
+    /**
+     * @return Returns the ldapMessage.
+     */
+    public LdapMessagePOJO getLdapMessage()
+    {
+
+        return ldapMessage;
+    }
+
+    /**
+     * Set a ldapMessage POJO into the container. It will be completed
+     * by the ldapDecoder .
+     *
+     * @param ldapMessage The ldapMessage to set.
+     */
+    public void setLdapMessage( LdapMessagePOJO ldapMessage )
+    {
+        this.ldapMessage = ldapMessage;
+    }
+
+    /**
+     * Associate a pool Manager to the container
+     *
+     * @param poolManager The pool manager
+     */
+    public void setPoolManager( LocalPoolManager poolManager )
+    {
+        this.poolManager = poolManager;
+    }
+
+    /**
+     * @return The poolManager associated with this container
+     */
+    public LocalPoolManager getPoolManager()
+    {
+        return poolManager;
+    }
+
+    /**
+     * @return Returns the grammar used to decode a LdapMessage.
+     */
+    public IGrammar getGrammar()
+    {
+        return grammar;
+    }
+
+    /**
+     * Set the IGrammar to use
+     *
+     * @param grammar The grammar to set.
+     */
+    public void setGrammar( IGrammar grammar )
+    {
+        this.grammar = grammar;
+    }
+
+    /**
+     * Set the current TLV
+     *
+     * @param tlv The current TLV
+     */
+    public void setCurrentTLV( TLV tlv )
+    {
+        this.tlv = tlv;
+    }
+
+    /**
+     * @return Returns the current TLV being decoded
+     */
+    public TLV getCurrentTLV()
+    {
+
+        return this.tlv;
+    }
+
+    /**
+     * @return Returns the current grammar state
+     */
+    public int getState()
+    {
+        return state;
+    }
+
+    /**
+     * Set the new current state
+     *
+     * @param state The new state
+     */
+    public void setState( int state )
+    {
+        this.state = state;
+    }
+
+    /**
+     * @return Returns the transition from the previous state to the new 
+     * state
+     */
+    public int getTransition()
+    {
+        return transition;
+    }
+
+    /**
+     * Update the transition from a state to another
+     *
+     * @param transition The transition to set
+     */
+    public void setTransition( int transition )
+    {
+        this.transition = transition;
+    }
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainerFactory.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainerFactory.java?view=auto&rev=159164
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainerFactory.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageContainerFactory.java
Sun Mar 27 10:40:20 2005
@@ -0,0 +1,42 @@
+/*
+ *   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 implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec;
+
+import org.apache.asn1.util.ObjectFactory;
+import org.apache.asn1.util.pools.PoolObject;
+
+
+/**
+ * Create a LdapMessageContainer object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapMessageContainerFactory implements ObjectFactory
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * The method that creates the object
+     *
+     * @return The created object
+     */
+    public PoolObject makeObject()
+    {
+
+        return new LdapMessageContainer();
+    }
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java?view=auto&rev=159164
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java
Sun Mar 27 10:40:20 2005
@@ -0,0 +1,379 @@
+/*
+ *   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 implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec;
+
+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.primitives.IntegerDecoder;
+import org.apache.asn1.ldap.codec.primitives.LdapDNDecoder;
+import org.apache.asn1.ldap.pojo.AbstractPOJO;
+import org.apache.asn1.ldap.pojo.BindRequestPOJO;
+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.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.
+ * 
+ * If an action is to be added or modified, this is where the work is to be done !
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapMessageGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( LdapMessageGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. LdapMessage is a singleton */
+    private static IGrammar instance = new LdapMessageGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+    /**
+     * DOCUMENT ME!
+     *
+     * @return DOCUMENT ME!
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+
+    private void checkLength(LdapPOJO ldapPOJO, TLV tlv) throws DecoderException
+	{
+	    // Create a new expected Length
+	    int expectedLength = tlv.getLength().getLength();
+	    
+	    int tlvLength = tlv.getSize();
+	
+	    // An exception will be thrown if the current length exceed the expected length
+		((AbstractPOJO)ldapPOJO).addLength(expectedLength + tlvLength);
+	}
+
+    /**
+     * Creates a new LdapMessageGrammar object.
+     */
+    private LdapMessageGrammar()
+    {
+
+        // We have 17 differents states, so 16 transitions between states.
+        super.transitions = new GrammarTransition[StatesEnum.LAST_STATE][256];
+
+        // LDAPMessage --> SEQUENCE { ... (Tag)
+        // We have a LDAPMessage, and the tag must be 0x30
+        super.transitions[StatesEnum.LDAP_MESSAGE_TAG][0x30] = new GrammarTransition( "LdapMessage
Tag",
+                StatesEnum.LDAP_MESSAGE_LENGTH, new GrammarAction( "LdapMessage Tag" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                    	try {
+	                    	LdapMessageContainer ldapMessageContainer = (LdapMessageContainer)container;
+	
+	                        // First, create a empty LdapMessage POJO
+	                    	LdapMessagePOJO ldapMessage = ( LdapMessagePOJO )
+	                            ldapMessageContainer.getPoolManager().allocate(
+	                                PoolEnum.LDAP_MESSAGE_POJO_POOL );
+	
+	                        // Then stores it into the container
+	                        ldapMessageContainer.setLdapMessage(ldapMessage);
+	                        
+	                        return;
+	                    }
+	                    catch ( PoolException pe )
+	                    {
+	                        throw new DecoderException(
+	                            "Cannot allocate a LdapMessage Pojo : " + pe.getMessage() );
+	                    }
+                    }
+                } );
+
+        // LDAPMessage --> SEQUENCE { ... (Length)
+        // Ok, get the LdapMessage length
+        super.transitions[StatesEnum.LDAP_MESSAGE_LENGTH][0x30] = new GrammarTransition(
"LdapMessage Length",
+                StatesEnum.LDAP_MESSAGE_VALUE, new GrammarAction( "LdapMessage Length" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                    	// We have to store the expected Length of the PDU
+                    	LdapMessageContainer ldapMessageContainer = (LdapMessageContainer)container;
+                    	LdapMessagePOJO ldapMessage = ldapMessageContainer.getLdapMessage();
+
+                    	ldapMessage.setExpectedLength(ldapMessageContainer.getCurrentTLV().getLength().getLength());
+                    	ldapMessage.setCurrentLength(0);
+
+                    	return;
+                    }
+                } );
+        
+        // LDAPMessage --> SEQUENCE { ... (Value)
+        // Nothing to do, it's a constructed TLV
+        super.transitions[StatesEnum.LDAP_MESSAGE_VALUE][0x30] = new GrammarTransition( "LdapMessage
Value", StatesEnum.LDAP_MESSAGE_ID_TAG, null);
+
+        // LDAPMessage --> ... MessageId ...(Tag)
+        // The tag must be 0x02. Nothing special to do.
+        super.transitions[StatesEnum.LDAP_MESSAGE_ID_TAG][0x02] = new GrammarTransition(
"MessageId Tag", StatesEnum.LDAP_MESSAGE_ID_LENGTH, null);
+
+        // LDAPMessage --> ... MessageId ...(Length)
+        // Checks the length
+        super.transitions[StatesEnum.LDAP_MESSAGE_ID_LENGTH][0x02] = new GrammarTransition(
"MessageId Length", StatesEnum.LDAP_MESSAGE_ID_VALUE, 
+                new GrammarAction( "Check MessageId Length " )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                    	checkLength(((LdapMessageContainer)container).getLdapMessage(), ((LdapMessageContainer)container).getCurrentTLV());
+
+                        return;
+                    }
+                } );
+        
+        // LDAPMessage --> ... MessageId ...(Value)
+        // Checks that MessageId is in [0 .. 2147483647] and store the value in the LdapMessage
POJO
+        super.transitions[StatesEnum.LDAP_MESSAGE_ID_VALUE][0x02] = new GrammarTransition(
"MessageId Value", StatesEnum.PROTOCOL_OP_TAG,
+                new GrammarAction( "Store MessageId" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                    	LdapMessageContainer ldapMessageContainer = (LdapMessageContainer)container;
+                    	LdapMessagePOJO ldapMessage = ldapMessageContainer.getLdapMessage();
+
+                        // The current TLV should be a integer
+                        // We get it and store it in MessageId
+                        TLV   tlv       = ldapMessageContainer.getCurrentTLV();
+
+                        Value value     = tlv.getValue();
+
+                        int   messageId = IntegerDecoder.parse( value , 0, 2147483647);
+
+                        if ( ( messageId < 0 ) || ( messageId > 2147483647 ) )
+                        {
+                            throw new DecoderException(
+                                "The message ID must be between (0 .. 2 147 483 647)" );
+                        }
+                        else
+                        {
+                        	ldapMessage.setMessageId( messageId );
+                        	
+                            return;
+                        }
+                    }
+                } );
+
+        // If the Tag is 0x60, then it's a BindRequest. Nothing to do while the length is
not verified.
+        // LdapMessage ::= ... BindRequest ...
+        // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Tag)
+        super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x60] = new GrammarTransition( "BindRequest
Tag", StatesEnum.PROTOCOL_OP_LENGTH, null );
+
+        // We have to allocate a BindRequestPOJO
+        // LdapMessage ::= ... BindRequest ...
+        // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Length)
+        super.transitions[StatesEnum.PROTOCOL_OP_LENGTH][0x60] = new GrammarTransition( "BindRequest
Length", StatesEnum.PROTOCOL_OP_VALUE, 
+                new GrammarAction( "Init BindRequest" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                    	LdapMessageContainer ldapMessageContainer = (LdapMessageContainer)container;
+                    	LdapMessagePOJO ldapMessage = ldapMessageContainer.getLdapMessage();
+
+                    	checkLength(((LdapMessageContainer)container).getLdapMessage(), ((LdapMessageContainer)container).getCurrentTLV());
+                    	
+                    	try 
+						{
+	                    	// Now, we can allocate the BindRequest POJO
+	                    	LdapPOJO bindRequest = (LdapPOJO)ldapMessageContainer.getPoolManager().allocate(PoolEnum.BIND_REQUEST_POJO_POOL);
+	                    	
+	                    	// As this is a new Constructed object, we have to init its length
+	                        TLV   tlv       = ldapMessageContainer.getCurrentTLV();
+	                        int expectedLength = tlv.getLength().getLength();
+	                    	((BindRequestPOJO)bindRequest).setExpectedLength(expectedLength);
+	                    	((BindRequestPOJO)bindRequest).setCurrentLength(0);
+
+							// 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 ::= ... BindRequest ...
+        // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Value)
+        // Nothing to do, the Value is empty, this is a constructed TLV
+        super.transitions[StatesEnum.PROTOCOL_OP_VALUE][0x60] = new GrammarTransition( "BindRequest
Value", StatesEnum.BIND_VERSION_TAG, null);
+
+        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (Tag)
+        // Nothing to do.
+        super.transitions[StatesEnum.BIND_VERSION_TAG][0x02] = new GrammarTransition( "Bind
version Tag", StatesEnum.BIND_VERSION_LENGTH, null);
+        
+        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (Length)
+        // Checks the length
+        super.transitions[StatesEnum.BIND_VERSION_LENGTH][0x02] = new GrammarTransition(
"Bind version Length", StatesEnum.BIND_VERSION_VALUE,
+                new GrammarAction( "Store version" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                    	checkLength(((LdapMessageContainer)container).getLdapMessage().getProtocolOp(),
((LdapMessageContainer)container).getCurrentTLV());
+                        return;
+                    }
+                } );
+
+        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (value)
+        // Checks that the Version is in [1, 127]
+        super.transitions[StatesEnum.BIND_VERSION_VALUE][0x02] = new GrammarTransition( "Bind
version Length", StatesEnum.BIND_NAME_TAG,
+                new GrammarAction( "Store version" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        BindRequestPOJO      bindRequestMessage   =
+                        	(BindRequestPOJO)ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        // The current TLV should be a integer between 1 and 127
+                        // We get it and store it in Version
+                        TLV   tlv     = ldapMessageContainer.getCurrentTLV();
+
+                        Value value   = tlv.getValue();
+
+                        int   version = IntegerDecoder.parse( value, 1, 127 );
+
+                        bindRequestMessage.setVersion( version );
+
+                        return;
+                    }
+                } );
+
+        // BindRequest ::= ... name LDAPDN, ... (Tag)
+        // Nothing to do. The tag is supposed to be 0x04
+        super.transitions[StatesEnum.BIND_NAME_TAG][0x04] = new GrammarTransition( "bind
name tag", StatesEnum.BIND_NAME_LENGTH, null);
+        
+        // BindRequest ::= ... name LDAPDN, ... (Length)
+        // We just check the length.
+        super.transitions[StatesEnum.BIND_NAME_LENGTH][0x04] = new GrammarTransition( "bind
name length", StatesEnum.BIND_NAME_VALUE,
+                new GrammarAction( "Check Bind Name Length" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                    	checkLength(((LdapMessageContainer)container).getLdapMessage().getProtocolOp(),
((LdapMessageContainer)container).getCurrentTLV());
+                        return;
+                    }
+                } );
+
+        // BindRequest ::= ... name LDAPDN, ... (Value)
+        // We just check the length.
+        super.transitions[StatesEnum.BIND_NAME_VALUE][0x04] = new GrammarTransition( "bind
name value", StatesEnum.BIND_AUTHENTICATION_CHOICE_TAG,
+                new GrammarAction( "Store Bind Name value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)container;
+                        
+	                    // Get the Value and store it in the BindRequest 
+	                    TLV   tlv     = ldapMessageContainer.getCurrentTLV();
+	                    
+	                    // TODO : allocate the string from a pool.
+	                    String value = LdapDNDecoder.parse(tlv.getValue());
+                        //String value = new String(tlv.getValue().getData());
+
+                        BindRequestPOJO      bindRequestMessage   = (BindRequestPOJO)ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        bindRequestMessage.setName(value);
+                        return;
+                    }
+                } );
+
+        // BindRequest ::= ... authentication AuthenticationChoice }
+        // AuthenticationChoice ::= CHOICE {
+        // The tag might be either 0x80 (SimpleAuthentication) or 0x83 (SaslAuthentication)
+        // Here, it's 0x80, so a SimpleAuthentication. 
+        // Nothing to do.
+        super.transitions[StatesEnum.BIND_AUTHENTICATION_CHOICE_TAG][( 0x80 & 0x00FF
)] = new GrammarTransition( "Bind Simple Authentication Tag", StatesEnum.BIND_AUTHENTICATION_SIMPLE_LENGTH,
null);
+        
+        // AuthenticationChoice ::= CHOICE {
+        //		simple         [0] OCTET STRING, (Length)
+        super.transitions[StatesEnum.BIND_AUTHENTICATION_SIMPLE_LENGTH][( 0x80 & 0x00FF
)] = new GrammarTransition( "Bind Simple Authentication Length", StatesEnum.BIND_AUTHENTICATION_SIMPLE_VALUE,

+        		new GrammarAction( "Check simple authentication length" ) 
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                    	checkLength(((LdapMessageContainer)container).getLdapMessage().getProtocolOp(),
((LdapMessageContainer)container).getCurrentTLV());
+                        
+                        return;
+                    }
+                } );
+
+        // AuthenticationChoice ::= CHOICE {
+        //		simple         [0] OCTET STRING, (Value)
+        super.transitions[StatesEnum.BIND_AUTHENTICATION_SIMPLE_VALUE][( 0x80 & 0x00FF
)] = new GrammarTransition( "Bind Simple Authentication Value", -1, //StatesEnum.CONTROLS_TAG,

+                new GrammarAction( "Store Bind Simple Authentication value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)container;
+                        
+	                    // Get the Value and store it in the BindRequest 
+	                    TLV   tlv     = ldapMessageContainer.getCurrentTLV();
+	                    
+	                    // TODO : allocate the string from a pool.
+                        String simple = new String(tlv.getValue().getData());
+
+                        BindRequestPOJO      bindRequestMessage   = (BindRequestPOJO)ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        try 
+						{
+	                        SimpleAuthenticationPOJO authentication = ( SimpleAuthenticationPOJO
)
+								ldapMessageContainer.getPoolManager().allocate(
+										PoolEnum.SIMPLE_AUTH_POJO_POOL );
+	                        
+	                        authentication.setSimple(simple);
+	
+	                        bindRequestMessage.setAuthentication(authentication);
+	                        return;
+						} 
+                        catch (PoolException pe) 
+						{
+                    		throw new DecoderException(
+                                    "Cannot allocate a SimpleAuthentication Pojo : " + pe.getMessage()
);
+						}
+                    }
+                } );
+    }
+}



Mime
View raw message