directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1513517 - in /directory/shared/trunk/ldap: client/api/src/main/java/org/apache/directory/ldap/client/api/ extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/
Date Tue, 13 Aug 2013 14:49:04 GMT
Author: elecharny
Date: Tue Aug 13 14:49:03 2013
New Revision: 1513517

URL: http://svn.apache.org/r1513517
Log:
Fixed the way we handle extendedResponse decoding

Modified:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyFactory.java

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1513517&r1=1513516&r2=1513517&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Tue Aug 13 14:49:03 2013
@@ -107,7 +107,6 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.message.Request;
 import org.apache.directory.api.ldap.model.message.Response;
 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
-import org.apache.directory.api.ldap.model.message.ResultResponse;
 import org.apache.directory.api.ldap.model.message.SearchRequest;
 import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
 import org.apache.directory.api.ldap.model.message.SearchResultDone;
@@ -3104,18 +3103,13 @@ public class LdapNetworkConnection exten
             }
 
             // Get back the response. It's still an opaque response
-            ResultResponse resultResponse = extendedRequest.getResultResponse();
-
-            // Decode the payload now
-            resultResponse.getMessageId();
-
             if ( Strings.isEmpty( response.getResponseName() ) )
             {
                 response.setResponseName( extendedRequest.getRequestName() );
             }
 
-            ExtendedResponseDecorator<?> decoratedResponse = ldapApiService
-                .decorate( ( ExtendedResponse ) resultResponse );
+            // Decode the payload now
+            ExtendedResponseDecorator<?> decoratedResponse = ldapApiService.decorate(
response );
 
             return decoratedResponse;
         }

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyFactory.java?rev=1513517&r1=1513516&r2=1513517&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyFactory.java
(original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyFactory.java
Tue Aug 13 14:49:03 2013
@@ -20,9 +20,14 @@
 package org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify;
 
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.nio.ByteBuffer;
+
 import org.apache.directory.api.asn1.DecoderException;
-import org.apache.directory.api.ldap.codec.api.ExtendedRequestDecorator;
+import org.apache.directory.api.asn1.ber.Asn1Decoder;
 import org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory;
+import org.apache.directory.api.ldap.codec.api.ExtendedRequestDecorator;
 import org.apache.directory.api.ldap.codec.api.ExtendedResponseDecorator;
 import org.apache.directory.api.ldap.codec.api.LdapApiService;
 import org.apache.directory.api.ldap.extras.extended.PwdModifyRequest;
@@ -31,6 +36,7 @@ import org.apache.directory.api.ldap.ext
 import org.apache.directory.api.ldap.extras.extended.PwdModifyResponseImpl;
 import org.apache.directory.api.ldap.model.message.ExtendedRequest;
 import org.apache.directory.api.ldap.model.message.ExtendedResponse;
+import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
 
 
 /**
@@ -108,13 +114,57 @@ public class PasswordModifyFactory imple
     /**
      * {@inheritDoc}
      */
-    public ExtendedResponseDecorator<PwdModifyResponse> decorate( ExtendedResponse
decoratedMessage )
+    public ExtendedResponseDecorator<PwdModifyResponse> decorate( ExtendedResponse
decoratedResponse )
     {
-        if ( decoratedMessage instanceof PasswordModifyResponseDecorator )
+        if ( decoratedResponse instanceof PasswordModifyResponseDecorator )
+        {
+            return ( PasswordModifyResponseDecorator ) decoratedResponse;
+        }
+
+        if ( decoratedResponse instanceof PwdModifyResponse )
         {
-            return ( PasswordModifyResponseDecorator ) decoratedMessage;
+            return new PasswordModifyResponseDecorator( codec, ( PwdModifyResponse ) decoratedResponse
);
+        }
+
+        // It's an opaque extended operation
+        ExtendedResponseDecorator<ExtendedResponse> response = ( ExtendedResponseDecorator<ExtendedResponse>
) decoratedResponse;
+
+        // Decode the response, as it's an opaque operation
+        Asn1Decoder decoder = new Asn1Decoder();
+
+        byte[] value = response.getResponseValue();
+        ByteBuffer buffer = ByteBuffer.wrap( value );
+
+        PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
+
+        try
+        {
+            decoder.decode( buffer, container );
+
+            PwdModifyResponse pwdModifyResponse = container.getPwdModifyResponse();
+
+            // Now, update the created response with what we got from the extendedResponse
+            pwdModifyResponse.getLdapResult().setResultCode( response.getLdapResult().getResultCode()
);
+            pwdModifyResponse.getLdapResult().setDiagnosticMessage( response.getLdapResult().getDiagnosticMessage()
);
+            pwdModifyResponse.getLdapResult().setMatchedDn( response.getLdapResult().getMatchedDn()
);
+            pwdModifyResponse.getLdapResult().setReferral( response.getLdapResult().getReferral()
);
+
+            return new PasswordModifyResponseDecorator( codec, pwdModifyResponse );
+        }
+        catch ( DecoderException de )
+        {
+            StringWriter sw = new StringWriter();
+            de.printStackTrace( new PrintWriter( sw ) );
+            String stackTrace = sw.toString();
+
+            // Error while decoding the value. 
+            PwdModifyResponse pwdModifyResponse = new PwdModifyResponseImpl(
+                decoratedResponse.getMessageId(),
+                ResultCodeEnum.OPERATIONS_ERROR,
+                stackTrace );
+
+            return new PasswordModifyResponseDecorator( codec, pwdModifyResponse );
         }
 
-        return new PasswordModifyResponseDecorator( codec, ( PwdModifyResponse ) decoratedMessage
);
     }
 }



Mime
View raw message