Author: akarasulu
Date: Mon Aug 23 11:12:39 2004
New Revision: 36770
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/bind/BindRequestEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/bind/BindRequestEncoderTest.java
Log:
Commit changes ...
o completed BindRequest encoder
o completed test case for new encoder
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/bind/BindRequestEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/bind/BindRequestEncoder.java Mon Aug 23 11:12:39 2004
@@ -0,0 +1,100 @@
+/*
+ * 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.encoder.bind;
+
+
+import org.apache.ldap.common.message.BindRequest;
+
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ldap.encoder.EncoderUtils;
+import org.apache.snickers.ber.primitives.UniversalTag;
+
+import org.apache.commons.lang.NotImplementedException;
+
+
+/**
+ * A BindRequest stub to tuple tree encoder.
+ *
+ * @author Apache Directory
+ * Project $Rev$
+ */
+public class BindRequestEncoder
+{
+ /** thread safe instance of this encoder */
+ public static final BindRequestEncoder INSTANCE = new BindRequestEncoder();
+
+
+ /**
+ * Encodes a BindRequest stub into a tuple tree.
+ *
+ * @param request the BindRequest instance to be encoded
+ * @return the root of the tuple tree node for the BindRequest
+ */
+ public TupleNode encode( BindRequest request )
+ {
+ /// Create the top level BindRequest PDU node
+ DefaultMutableTupleNode top =
+ new DefaultMutableTupleNode( new Tuple() );
+ top.getTuple().setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+ top.getTuple().setLength( Length.INDEFINATE );
+
+ // Create and add the message id to response PDU
+ DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( request.getMessageId() );
+ top.addLast( child );
+ child.setParent( top );
+
+ // Create the bind response sequence of TLV tuple
+ DefaultMutableTupleNode bindreq =
+ new DefaultMutableTupleNode( new Tuple() );
+ bindreq.getTuple().setTag( LdapTag.BIND_REQUEST, false );
+ bindreq.getTuple().setLength( Length.INDEFINATE );
+
+ // add the version integer
+ child = ( DefaultMutableTupleNode ) EncoderUtils.encode(
+ request.getVersion3() ? 3 : 2 );
+ bindreq.addLast( child );
+ child.setParent( bindreq );
+
+ // add the name LDAPDN
+ child = ( DefaultMutableTupleNode ) EncoderUtils.encode(
+ request.getName() );
+ bindreq.addLast( child );
+ child.setParent( bindreq );
+
+ // add the security information
+ if ( request.isSimple() )
+ {
+ child = ( DefaultMutableTupleNode ) EncoderUtils.encode(
+ LdapTag.CONTEXT_SPECIFIC_TAG_0, request.getCredentials() );
+ bindreq.addLast( child );
+ child.setParent( bindreq );
+ }
+ else
+ {
+ throw new NotImplementedException( "SASL not yet implemented!" );
+ }
+
+ top.addLast( bindreq );
+ bindreq.setParent( top );
+ return top;
+ }
+}
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/bind/BindRequestEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/bind/BindRequestEncoderTest.java Mon Aug 23 11:12:39 2004
@@ -0,0 +1,48 @@
+/*
+ * 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.encoder.bind;
+
+import org.apache.snickers.ldap.encoder.AbstractEncoderTestCase;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.ldap.common.message.BindRequestImpl;
+
+/**
+ * Document me.
+ *
+ * @author Apache Directory
+ * Project $Rev$
+ */
+public class BindRequestEncoderTest extends AbstractEncoderTestCase
+{
+
+ public void testEncode()
+ {
+ BindRequestImpl req = new BindRequestImpl( 12 );
+ req.setCredentials( "password".getBytes() );
+ req.setName( "uid=akarasulu,dc=apache,dc=org" );
+ req.setSimple( true );
+ req.setVersion3( true );
+
+ // Encode stub into tuple tree then into the accumulator
+ TupleNode node = BindRequestEncoder.INSTANCE.encode( req );
+ encode( ( DefaultMutableTupleNode ) node );
+
+ // Test to see if original stub equals the round trip generated stub
+ assertTrue( req.equals( decode() ) );
+ }
+}