directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r654362 - /directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
Date Thu, 08 May 2008 01:01:06 GMT
Author: akarasulu
Date: Wed May  7 18:01:06 2008
New Revision: 654362

URL: http://svn.apache.org/viewvc?rev=654362&view=rev
Log:
adding transformation code to implement a bind client

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java?rev=654362&r1=654361&r2=654362&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
Wed May  7 18:01:06 2008
@@ -25,6 +25,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javax.naming.InvalidNameException;
 import javax.naming.NamingEnumeration;
 import javax.naming.directory.Attribute;
 
@@ -112,6 +113,7 @@
 import org.apache.directory.shared.ldap.message.extended.GracefulShutdownRequest;
 import org.apache.directory.shared.ldap.message.spi.Provider;
 import org.apache.directory.shared.ldap.message.spi.TransformerSpi;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -240,6 +242,72 @@
 
 
     /**
+     * Transform a BindResponse message from a TwixMessage to a 
+     * SnickersMessage.  This is used by clients which are receiving a 
+     * BindResponse PDU and must decode it to return the Snickers 
+     * representation.
+     * 
+     * @param twixMessage The message to transform
+     * @param messageId The message Id
+     * @return a Snickers BindResponseImpl
+     */
+    private Message transformBindResponse( LdapMessage twixMessage, int messageId )
+    {
+        BindResponseImpl snickersMessage = new BindResponseImpl( messageId );
+        BindResponse bindResponse = twixMessage.getBindResponse();
+
+        // Twix : byte[] serverSaslcreds -> Snickers : byte[] serverSaslCreds
+        snickersMessage.setServerSaslCreds( bindResponse.getServerSaslCreds() );
+        transformControlsTwixToSnickers( twixMessage, snickersMessage );
+        transformLdapResultTwixToSnickers( bindResponse.getLdapResult(), snickersMessage.getLdapResult()
);
+        
+        return snickersMessage;
+    }
+
+    
+    /**
+     * Transforms parameters of a Twix LdapResult into a Snickers LdapResult.
+     *
+     * @param twixResult the Twix LdapResult representation
+     * @param snickersResult the Snickers LdapResult representation
+     */
+    private void transformLdapResultTwixToSnickers( LdapResult twixResult, 
+        org.apache.directory.shared.ldap.message.LdapResult snickersResult )
+    {
+        snickersResult.setErrorMessage( twixResult.getErrorMessage() );
+        
+        try
+        {
+            snickersResult.setMatchedDn( new LdapDN( twixResult.getMatchedDN() ) );
+        }
+        catch ( InvalidNameException e )
+        {
+            log.error( "Could not parse matchedDN while transforming twix value to snickers:
{}", 
+                twixResult.getMatchedDN() );
+            snickersResult.setMatchedDn( new LdapDN() );
+        }
+        
+        snickersResult.setResultCode( twixResult.getResultCode() );
+
+        if ( twixResult.getReferrals() == null )
+        {
+            
+        }
+        else
+        {
+            ReferralImpl referral = new ReferralImpl();
+            
+            for ( LdapURL url : twixResult.getReferrals() )
+            {
+                referral.addLdapUrl( url.toString() );
+            }
+            
+            snickersResult.setReferral( referral );
+        }
+    }
+    
+
+    /**
      * Transform a CompareRequest message from a TwixMessage to a
      * SnickersMessage
      * 
@@ -698,6 +766,9 @@
                 break;
 
             case ( LdapConstants.BIND_RESPONSE  ):
+                snickersMessage = transformBindResponse( twixMessage, messageId );
+                break;
+
             case ( LdapConstants.SEARCH_RESULT_ENTRY  ):
             case ( LdapConstants.SEARCH_RESULT_DONE  ):
             case ( LdapConstants.SEARCH_RESULT_REFERENCE  ):
@@ -806,7 +877,7 @@
     /**
      * Transform a Ldapresult part of a Snickers Response to a Twix LdapResult
      * 
-     * @param snickersLdapResult The Snickers LdapResult to transform
+     * @param snickersLdapResult the Snickers LdapResult to transform
      * @return A Twix LdapResult
      */
     private LdapResult transformLdapResult( LdapResultImpl snickersLdapResult )
@@ -903,6 +974,41 @@
 
 
     /**
+     * Transform a Snickers BindRequest to a Twix BindRequest
+     * 
+     * @param twixMessage The Twix BindRequest to produce
+     * @param snickersMessage The incoming Snickers BindRequest
+     */
+    private void transformBindRequest( LdapMessage twixMessage, Message snickersMessage )
+    {
+        BindRequestImpl snickersBindRequest = ( BindRequestImpl ) snickersMessage;
+
+        BindRequest bindRequest = new BindRequest();
+        
+        if ( snickersBindRequest.isSimple() )
+        {
+            SimpleAuthentication simple = new SimpleAuthentication();
+            simple.setSimple( snickersBindRequest.getCredentials() );
+            bindRequest.setAuthentication( simple );
+        }
+        else
+        {
+            SaslCredentials sasl = new SaslCredentials();
+            sasl.setCredentials( snickersBindRequest.getCredentials() );
+            sasl.setMechanism( snickersBindRequest.getSaslMechanism() );
+            bindRequest.setAuthentication( sasl );
+        }
+        
+        bindRequest.setMessageId( snickersBindRequest.getMessageId() );
+        bindRequest.setName( snickersBindRequest.getName() );
+        bindRequest.setVersion( snickersBindRequest.isVersion3() ? 3 : 2 );
+        
+        // Set the operation into the LdapMessage
+        twixMessage.setProtocolOP( bindRequest );
+    }
+
+
+    /**
      * Transform a Snickers CompareResponse to a Twix CompareResponse
      * 
      * @param twixMessage The Twix CompareResponse to produce
@@ -1142,6 +1248,10 @@
                 transformBindResponse( twixMessage, msg );
                 break;
                 
+            case BIND_REQUEST :
+                transformBindRequest( twixMessage, msg );
+                break;
+                
             case ADD_RESPONSE :
                 transformAddResponse( twixMessage, msg );
                 break;
@@ -1182,6 +1292,30 @@
         return twixMessage;
     }
 
+
+    /**
+     * TODO finish this implementation.  Takes Twix Controls, transforming 
+     * them to Snickers Controls and populates the Snickers message with them.
+     *
+     * @param twixMessage the Twix message
+     * @param msg the Snickers message
+     */
+    private void transformControlsTwixToSnickers( LdapMessage twixMessage, Message msg )
+    {
+        if ( twixMessage.getControls() == null )
+        {
+            return;
+        }
+        
+        Iterator<Control> list = twixMessage.getControls().iterator();
+        
+        while ( list.hasNext() )
+        {
+            log.debug( "Not decoding response control: {}", list.next() );
+        }
+    }
+    
+    
     /**
      * Transforms the controls
      * @param twixMessage The Twix SearchResultReference to produce



Mime
View raw message