directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10091 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap
Date Mon, 19 Apr 2004 03:36:11 GMT
Author: akarasulu
Date: Sun Apr 18 20:36:10 2004
New Revision: 10091

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindErrorMessageRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindMatchedDNRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResultCodeRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BufferUtils.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralUrlRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindResponseRuleTest.java
  (contents, props changed)
Log:
Commit changes ...

o experimented with a couple of configurations because of how awkward bind 
  responses are but got it working
o have some code that can be used for a generalized LDAPResult other than in 
  the bind PDU
o added test case that demonstrates how the digester and some of these rules
  work together to decode a bind response



Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindErrorMessageRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindErrorMessageRule.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,45 @@
+/*
+ *   Copyright 2004 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.snickers.ldap;
+
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
+import org.apache.ldap.common.message.BindResponse;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindErrorMessageRule extends PrimitiveOctetStringRule
+{
+    /* (non-Javadoc)
+    * @see org.apache.snickers.ber.Rule#finish()
+    */
+    public void finish()
+    {
+        super.finish() ;
+
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        String errorMsg = new String( BufferUtils.getArray( buf ) ) ;
+        BindResponse resp = ( BindResponse ) getDigester().peek() ;
+        resp.getLdapResult().setErrorMessage( errorMsg ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindMatchedDNRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindMatchedDNRule.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,45 @@
+/*
+ *   Copyright 2004 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.snickers.ldap;
+
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
+import org.apache.ldap.common.message.BindResponse;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindMatchedDNRule extends PrimitiveOctetStringRule
+{
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        String dn = new String( BufferUtils.getArray( buf ) ) ;
+        BindResponse resp = ( BindResponse ) getDigester().peek() ;
+        resp.getLdapResult().setMatchedDn( dn ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,70 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import java.nio.ByteBuffer ;
+
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.AbstractRule ;
+
+import org.apache.ldap.common.message.BindResponse ;
+import org.apache.ldap.common.message.BindResponseImpl ;
+import org.apache.ldap.common.message.LdapResultImpl;
+
+
+/**
+ * A rule that creates, pushes and pops a BindRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindResponseRule extends AbstractRule
+{
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass ) ;
+        BindResponse resp = new BindResponseImpl( getDigester().popInt() ) ;
+        LdapResultImpl result = new LdapResultImpl( resp ) ;
+        resp.setLdapResult( result ) ;
+        getDigester().push( resp ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        BindResponse resp = null ;
+
+        if ( getDigester().peek() instanceof BindResponse )
+        {
+            resp = ( BindResponse ) getDigester().pop() ;
+        }
+        else
+        {
+            ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+            resp = ( BindResponse ) getDigester().pop() ;
+            resp.setServerSaslCreds( BufferUtils.getArray( buf ) ) ;
+        }
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResultCodeRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResultCodeRule.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,46 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import org.apache.ldap.common.message.BindResponse ;
+import org.apache.ldap.common.message.ResultCodeEnum;
+
+import org.apache.snickers.ber.digester.rules.PrimitiveEnumDecodeRule ;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindResultCodeRule extends PrimitiveEnumDecodeRule
+{
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+
+        int val = getDigester().popInt() ;
+        ResultCodeEnum resultCode = ResultCodeEnum.getResultCodeEnum( val ) ;
+        BindResponse resp = ( BindResponse ) getDigester().peek() ;
+        resp.getLdapResult().setResultCode( resultCode ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BufferUtils.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BufferUtils.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,66 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import org.apache.commons.lang.ArrayUtils ;
+
+import java.nio.ByteBuffer ;
+
+
+/**
+ * ByteBuffer manipulation utilities.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BufferUtils
+{
+    /**
+     * One way or another gets an array from a buffer.  If the backing store
+     * is an accessible array and the buffer's limit and capacity are the same
+     * then the backing store of the buffer is returned.  Otherwise there is
+     * no choice but to copy the ByteBuffer.  Hence the returned byte[] may be
+     * shared with the ByteBuffer so changes to one will effect the other.
+     * Don't use this method if the ByteBuffer will be reused.
+     *
+     * @param buf the ByteBuffer to get an array for
+     * @return the byte[] representing the contents of the ByteBuffer
+     */
+    public static byte[] getArray( ByteBuffer buf )
+    {
+        byte[] array = ArrayUtils.EMPTY_BYTE_ARRAY ;
+
+        if ( buf == null || buf.remaining() == 0 )
+        {
+            return array ;
+        }
+
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            array = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            array = new byte[buf.remaining()] ;
+            buf.get( array ) ;
+        }
+
+        return array ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,82 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import org.apache.ldap.common.message.LdapResult ;
+import org.apache.ldap.common.message.ReferralImpl ;
+import org.apache.ldap.common.message.BindResponse;
+import org.apache.ldap.common.message.ResultResponse;
+
+import org.apache.snickers.ber.TagEnum ;
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.AbstractRule ;
+
+
+/**
+ * A BERDigester Rule that creates and pushes a Referral onto the object Stack
+ * to be populated by ReferralUrlRule invokations.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ReferralRule extends AbstractRule
+{
+    /** the tag for a Referral within an LDAPResult */
+    private static final TagEnum TAG = new TagEnum( "Referral",
+            0x83000000, 3 ) {} ;
+
+
+    /**
+     * Creates and sets the Referral for an LdapResult to use.  It does so
+     * by first accessing the underlying LdapResult which is expected to be
+     * the top object on the objectStack.  A peek is performed to get this
+     * LdapResult.  It is then used to create the Referral object which is
+     * pushed onto the stack.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass ) ;
+
+        if ( id != TAG.getTagId() )
+        {
+            throw new IllegalArgumentException(
+                    "Expecting " + TAG.getName()
+                    + " with an id of " + TAG.getTagId()
+                    + " but instead got a tag id of " + id ) ;
+        }
+
+        ResultResponse resp = ( BindResponse ) getDigester().getRoot() ;
+        LdapResult result = ( LdapResult ) resp.getLdapResult() ;
+        ReferralImpl ref = new ReferralImpl( result ) ;
+        result.setReferral( ref ) ;
+        getDigester().push( ref ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+        getDigester().pop() ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralUrlRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralUrlRule.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,64 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import java.nio.ByteBuffer ;
+
+import org.apache.ldap.common.message.Referral ;
+
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+
+
+/**
+ * Rule that collects an OCTET_STRING and adds it to the Referral object at
+ * the top of the stack.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ReferralUrlRule extends PrimitiveOctetStringRule
+{
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+
+        // get the LDAP URL collected as an OCTET STRING
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+
+        // peek at the Referral underneath who we add the LDAPURL to
+        Referral ref = ( Referral ) getDigester().peek() ;
+
+        byte[] url = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            url = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            url = new byte[buf.remaining()] ;
+            buf.get( url ) ;
+        }
+
+        ref.addLdapUrl( new String( url ) ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultRule.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,65 @@
+/*
+ *   Copyright 2004 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.snickers.ldap;
+
+import org.apache.snickers.ber.digester.AbstractRule;
+import org.apache.snickers.ber.TypeClass;
+import org.apache.ldap.common.message.*;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * A rule used to create and populate an LdapResult object.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ResultRule extends AbstractRule
+{
+    private LdapResult result = null ;
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass ) ;
+        ResultResponse resp = ( ResultResponse ) getDigester().peek() ;
+        result = new LdapResultImpl( resp ) ;
+        getDigester().push( result ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        result.setErrorMessage( new String( BufferUtils.getArray( buf ) ) ) ;
+        buf = ( ByteBuffer ) getDigester().pop() ;
+        result.setMatchedDn( new String( BufferUtils.getArray( buf ) ) ) ;
+        int resultCode = getDigester().popInt() ;
+        result.setResultCode( ResultCodeEnum.getResultCodeEnum( resultCode ) ) ;
+        getDigester().pop() ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindResponseRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindResponseRuleTest.java
Sun Apr 18 20:36:10 2004
@@ -0,0 +1,162 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import junit.framework.TestCase ;
+
+import org.apache.snickers.ber.digester.BERDigester ;
+
+import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
+import org.apache.snickers.ber.digester.rules.PrimitiveEnumDecodeRule ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+import org.apache.snickers.ber.*;
+
+import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.berlib.snacc.ldap_v3.LDAPResultEnum;
+import org.apache.commons.codec.stateful.CallbackHistory;
+import org.apache.commons.lang.ArrayUtils;
+
+import java.nio.ByteBuffer ;
+
+
+/**
+ * Tests the population of an LdapResult using a ResultRule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindResponseRuleTest extends TestCase
+{
+    BERDigester digester ;
+    CallbackHistory history ;
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp() ;
+        digester = new BERDigester() ;
+        history = new CallbackHistory() ;
+        digester.setCallback( history ) ;
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        digester = null ;
+        history = null ;
+    }
+
+
+    public void testBindResponseOutput() throws Exception
+    {
+        // build the PDU
+        BindResponseImpl resp = new BindResponseImpl( 540 ) ;
+        resp.setServerSaslCreds( "hello".getBytes() ) ;
+        LdapResultImpl result = new LdapResultImpl( resp ) ;
+        result.setResultCode( ResultCodeEnum.BUSY ) ;
+        result.setErrorMessage( "An Error Message!" ) ;
+        result.setMatchedDn( "uid=akarasulu,dc=example,dc=com" ) ;
+        ReferralImpl referral = new ReferralImpl( result ) ;
+        referral.addLdapUrl( "hello" ) ;
+        referral.addLdapUrl( "world" ) ;
+        result.setReferral( referral ) ;
+        resp.setLdapResult( result ) ;
+        MessageEncoder encoder = new MessageEncoder() ;
+        byte[] pdu = encoder.encode( resp ) ;
+        ByteBuffer buf = ByteBuffer.wrap( pdu ) ;
+
+        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
+        CallbackHistory cb = new CallbackHistory() ;
+        decoder.setCallback( cb ) ;
+        decoder.decode( buf ) ;
+        DefaultMutableTupleNode node = ( DefaultMutableTupleNode ) cb.getMostRecent() ;
+        StringBuffer sb = new StringBuffer() ;
+        node.printDepthFirst( sb, 0 ) ;
+        System.out.println( sb.toString() ) ;
+    }
+
+
+    public void testBindResponse() throws Exception
+    {
+        int[] pattern = new int[2] ;
+
+        pattern[0] = 0x10000000 ;
+        pattern[1] = 0x02000000 ;
+        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
+
+        // for the BindResponse and the LdapResult
+        pattern[1] = 0x41000000 ;
+        digester.addRule( pattern, new BindResponseRule() ) ;
+
+        pattern = new int[3] ;
+        pattern[0] = 0x10000000 ;
+        pattern[1] = 0x41000000 ;
+
+        // for the resultCode
+        pattern[2] = 0x0a000000 ;
+        digester.addRule( pattern, new BindResultCodeRule() ) ;
+
+        // for matchedDN and errorMessage
+        pattern[2] = 0x04000000 ;
+        digester.addRule( pattern, new BindMatchedDNRule() ) ;
+        digester.addRule( pattern, new BindErrorMessageRule() ) ;
+
+        // for referral
+        pattern[2] = 0x83000000 ;
+        digester.addRule( pattern, new ReferralRule() ) ;
+
+        // for serverSaslCreds
+        pattern[2] = 0x87000000 ;
+        TagEnum tag = new TagEnum( "ServerSaslCreds", 0x87000000, 7 ) {} ;
+        digester.addRule( pattern, new PrimitiveOctetStringRule( tag ) ) ;
+
+        // for LDAPURLs of referral
+        pattern = new int[4] ;
+        pattern[0] = 0x10000000 ;
+        pattern[1] = 0x41000000 ;
+        pattern[2] = 0x83000000 ;
+        pattern[3] = 0x04000000 ;
+        digester.addRule( pattern, new ReferralUrlRule() ) ;
+
+        // build the PDU
+        BindResponseImpl resp = new BindResponseImpl( 540 ) ;
+        resp.setServerSaslCreds( "hello".getBytes() ) ;
+        LdapResultImpl result = new LdapResultImpl( resp ) ;
+        result.setResultCode( ResultCodeEnum.BUSY ) ;
+        result.setErrorMessage( "An Error Message!" ) ;
+        result.setMatchedDn( "uid=akarasulu,dc=example,dc=com" ) ;
+        ReferralImpl referral = new ReferralImpl( result ) ;
+        referral.addLdapUrl( "hello" ) ;
+        referral.addLdapUrl( "world" ) ;
+        result.setReferral( referral ) ;
+        resp.setLdapResult( result ) ;
+        MessageEncoder encoder = new MessageEncoder() ;
+        byte[] pdu = encoder.encode( resp ) ;
+        ByteBuffer buf = ByteBuffer.wrap( pdu ) ;
+        digester.decode( buf ) ;
+
+        BindResponse decoded = ( BindResponse ) history.getMostRecent() ;
+        assertNotNull( decoded ) ;
+        assertEquals( resp.getMessageId(), decoded.getMessageId() ) ;
+        assertNotNull( decoded.getServerSaslCreds() ) ;
+        assertEquals( new String( resp.getServerSaslCreds() ),
+                new String( decoded.getServerSaslCreds() ) ) ;
+
+    }
+}
\ No newline at end of file

Mime
View raw message