directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1804952 - /directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/
Date Mon, 14 Aug 2017 08:16:16 GMT
Author: elecharny
Date: Mon Aug 14 08:16:15 2017
New Revision: 1804952

URL: http://svn.apache.org/viewvc?rev=1804952&view=rev
Log:
o Added a bind ( SaslRequest ) method in the interface
o Added an AbstractSaslRequest which is now inherited from the Sasl classes

Added:
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractSaslRequest.java
      - copied, changed from r1795244, directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
Modified:
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionWrapper.java
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslCramMd5Request.java
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslDigestMd5Request.java
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslGssApiRequest.java
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java
    directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java

Copied: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractSaslRequest.java
(from r1795244, directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java)
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractSaslRequest.java?p2=directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractSaslRequest.java&p1=directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java&r1=1795244&r2=1804952&rev=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/AbstractSaslRequest.java
Mon Aug 14 08:16:15 2017
@@ -36,7 +36,7 @@ import org.apache.directory.api.util.Str
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public abstract class SaslRequest
+public abstract class AbstractSaslRequest implements SaslRequest
 {
     /** The mechanism used to decode user identity */
     protected String saslMechanism;
@@ -69,10 +69,9 @@ public abstract class SaslRequest
     /**
      * Creates a new instance of SaslRequest.
      *
-     * @param saslMechanism
-     *      the SASL mechanism
+     * @param saslMechanism the SASL mechanism
      */
-    protected SaslRequest( String saslMechanism )
+    protected AbstractSaslRequest( String saslMechanism )
     {
         this.saslMechanism = saslMechanism;
     }
@@ -101,10 +100,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Gets the authorization ID.
-     *
-     * @return the authorization ID
+     * {@inheritDoc}
      */
+    @Override
     public String getAuthorizationId()
     {
         return authorizationId;
@@ -112,10 +110,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Gets the controls.
-     *
-     * @return the controls
+     * {@inheritDoc}
      */
+    @Override
     public Control[] getControls()
     {
         return controls.toArray( new Control[0] );
@@ -123,10 +120,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Gets the crendentials
-     *
-     * @return the credentials
+     * {@inheritDoc}
      */
+    @Override
     public byte[] getCredentials()
     {
         if ( credentials != null )
@@ -141,10 +137,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Gets the quality of protection.
-     *
-     * @return the quality of protection
+     * {@inheritDoc}
      */
+    @Override
     public SaslQoP getQualityOfProtection()
     {
         return qualityOfProtection;
@@ -152,10 +147,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Gets realm name.
-     *
-     * @return the realm name
+     * {@inheritDoc}
      */
+    @Override
     public String getRealmName()
     {
         return realmName;
@@ -163,10 +157,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Gets the SASL mechanism.
-     *
-     * @return the SASL mechanism
+     * {@inheritDoc}
      */
+    @Override
     public String getSaslMechanism()
     {
         return saslMechanism;
@@ -174,10 +167,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Gets the security strength.
-     *
-     * @return the security strength
+     * {@inheritDoc}
      */
+    @Override
     public SaslSecurityStrength getSecurityStrength()
     {
         return securityStrength;
@@ -185,10 +177,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Gets the username.
-     *
-     * @return the username
+     * {@inheritDoc}
      */
+    @Override
     public String getUsername()
     {
         return username;
@@ -196,10 +187,9 @@ public abstract class SaslRequest
 
 
     /**
-     * Indicates if mutual authentication is required.
-     *
-     * @return the flag indicating if mutual authentication is required
+     * {@inheritDoc}
      */
+    @Override
     public boolean isMutualAuthentication()
     {
         return mutualAuthentication;

Modified: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=1804952&r1=1804951&r2=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
Mon Aug 14 08:16:15 2017
@@ -236,6 +236,16 @@ public interface LdapConnection extends
 
 
     /**
+     * SASL Bind to the server using a SASL request object.
+     *
+     * @param saslRequest The SASL request object containing all the needed parameters
+     * @return A {@link BindResponse} containing the result
+     * @throws LdapException if some error occurred
+     */
+    BindResponse bind( SaslRequest saslRequest ) throws LdapException;
+
+
+    /**
      * Do a search, on the base object, using the given filter and scope. The
      * SearchRequest parameters default to
      * <ul>

Modified: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionWrapper.java?rev=1804952&r1=1804951&r2=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionWrapper.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionWrapper.java
Mon Aug 14 08:16:15 2017
@@ -244,6 +244,16 @@ public class LdapConnectionWrapper imple
      * {@inheritDoc}
      */
     @Override
+    public BindResponse bind( SaslRequest saslRequest ) throws LdapException
+    {
+        return connection.bind( saslRequest );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes
)
         throws LdapException
     {

Modified: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1804952&r1=1804951&r2=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Mon Aug 14 08:16:15 2017
@@ -1464,6 +1464,64 @@ public class LdapNetworkConnection exten
 
 
     /**
+     * Bind to the server using a SaslRequest object.
+     *
+     * @param request The SaslRequest POJO containing all the needed parameters
+     * @return A LdapResponse containing the result
+     * @throws LdapException if some error occurred
+     */
+    public BindResponse bind( SaslRequest request ) throws LdapException
+    {
+        if ( request == null )
+        {
+            String msg = "Cannot process a null request";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        BindFuture bindFuture = bindAsync( request );
+
+
+        // Get the result from the future
+        try
+        {
+            // Read the response, waiting for it if not available immediately
+            // Get the response, blocking
+            BindResponse bindResponse = bindFuture.get( timeout, TimeUnit.MILLISECONDS );
+
+            if ( bindResponse == null )
+            {
+                // We didn't received anything : this is an error
+                LOG.error( "Bind failed : timeout occurred" );
+                throw new LdapException( TIME_OUT_ERROR );
+            }
+
+            if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
+            {
+                authenticated.set( true );
+
+                // Everything is fine, return the response
+                LOG.debug( "Bind successful : {}", bindResponse );
+            }
+            else
+            {
+                // We have had an error
+                LOG.debug( "Bind failed : {}", bindResponse );
+            }
+
+            return bindResponse;
+        }
+        catch ( Exception ie )
+        {
+            // Catch all other exceptions
+            LOG.error( NO_RESPONSE_ERROR, ie );
+
+            throw new LdapException( NO_RESPONSE_ERROR, ie );
+        }
+    }
+
+
+    /**
      * Bind to the server using a CramMd5Request object.
      *
      * @param request The CramMd5Request POJO containing all the needed parameters
@@ -4060,8 +4118,12 @@ public class LdapNetworkConnection exten
      * Process the SASL Bind. It's a dialog with the server, we will send a first BindRequest,
receive
      * a response and the, if this response is a challenge, continue by sending a new BindRequest
with
      * the requested informations.
+     *
+     * @param saslRequest The SASL request object containing all the needed parameters
+     * @return A {@link BindResponse} containing the result
+     * @throws LdapException if some error occurred
      */
-    private BindFuture bindSasl( SaslRequest saslRequest ) throws LdapException
+    public BindFuture bindSasl( SaslRequest saslRequest ) throws LdapException
     {
         // First switch to anonymous state
         authenticated.set( false );
@@ -4073,8 +4135,7 @@ public class LdapNetworkConnection exten
         checkSession();
 
         BindRequest bindRequest = createBindRequest( ( String ) null, null,
-            saslRequest.getSaslMechanism(), saslRequest
-                .getControls() );
+            saslRequest.getSaslMechanism(), saslRequest.getControls() );
 
         // Update the messageId
         int newId = messageId.incrementAndGet();

Modified: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslCramMd5Request.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslCramMd5Request.java?rev=1804952&r1=1804951&r2=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslCramMd5Request.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslCramMd5Request.java
Mon Aug 14 08:16:15 2017
@@ -29,7 +29,7 @@ import org.apache.directory.api.ldap.mod
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class SaslCramMd5Request extends SaslRequest
+public class SaslCramMd5Request extends AbstractSaslRequest
 {
     /**
      * Creates a new instance of SaslCramMd5Request.

Modified: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslDigestMd5Request.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslDigestMd5Request.java?rev=1804952&r1=1804951&r2=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslDigestMd5Request.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslDigestMd5Request.java
Mon Aug 14 08:16:15 2017
@@ -29,7 +29,7 @@ import org.apache.directory.api.ldap.mod
  *  
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class SaslDigestMd5Request extends SaslRequest
+public class SaslDigestMd5Request extends AbstractSaslRequest
 {
     /**
      * Creates a new instance of SaslDigestMd5Request.

Modified: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslGssApiRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslGssApiRequest.java?rev=1804952&r1=1804951&r2=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslGssApiRequest.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslGssApiRequest.java
Mon Aug 14 08:16:15 2017
@@ -31,7 +31,7 @@ import org.apache.directory.api.ldap.mod
  *  
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class SaslGssApiRequest extends SaslRequest
+public class SaslGssApiRequest extends AbstractSaslRequest
 {
     /** The KDC host*/
     protected String kdcHost;

Modified: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java?rev=1804952&r1=1804951&r2=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java
Mon Aug 14 08:16:15 2017
@@ -29,7 +29,7 @@ import org.apache.directory.api.ldap.mod
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class SaslPlainRequest extends SaslRequest
+public class SaslPlainRequest extends AbstractSaslRequest
 {
     /**
      * Creates a new instance of SaslPlainRequest.

Modified: directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java?rev=1804952&r1=1804951&r2=1804952&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
(original)
+++ directory/shared/branches/shared-value/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
Mon Aug 14 08:16:15 2017
@@ -17,127 +17,41 @@
  *   under the License.
  *
  */
-
 package org.apache.directory.ldap.client.api;
 
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
 import org.apache.directory.api.ldap.model.constants.SaslQoP;
 import org.apache.directory.api.ldap.model.constants.SaslSecurityStrength;
 import org.apache.directory.api.ldap.model.message.Control;
-import org.apache.directory.api.util.Strings;
-
 
 /**
  * Holds the data required to complete the SASL operation
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public abstract class SaslRequest
+public interface SaslRequest
 {
-    /** The mechanism used to decode user identity */
-    protected String saslMechanism;
-
-    /** The list of controls */
-    protected List<Control> controls = new ArrayList<>();
-
-    /** The username */
-    protected String username;
-
-    /** The credentials */
-    protected byte[] credentials;
-
-    /** The realm name on the server */
-    protected String realmName;
-
-    /** The authorization ID of the entity */
-    protected String authorizationId;
-
-    /** The quality of protection */
-    protected SaslQoP qualityOfProtection;
-
-    /** The security strength */
-    protected SaslSecurityStrength securityStrength;
-
-    /** Require mutual authentication */
-    protected boolean mutualAuthentication = false;
-
-
-    /**
-     * Creates a new instance of SaslRequest.
-     *
-     * @param saslMechanism
-     *      the SASL mechanism
-     */
-    protected SaslRequest( String saslMechanism )
-    {
-        this.saslMechanism = saslMechanism;
-    }
-
-
-    /**
-     * Adds the given controls.
-     *
-     * @param controls the controls
-     */
-    public void addAllControls( Control[] controls )
-    {
-        this.controls.addAll( Arrays.asList( controls ) );
-    }
-
-
-    /**
-     * Adds the given control.
-     *
-     * @param control the control
-     */
-    public void addControl( Control control )
-    {
-        this.controls.add( control );
-    }
-
-
     /**
      * Gets the authorization ID.
      *
      * @return the authorization ID
      */
-    public String getAuthorizationId()
-    {
-        return authorizationId;
-    }
-
+    String getAuthorizationId();
 
+    
     /**
      * Gets the controls.
      *
      * @return the controls
      */
-    public Control[] getControls()
-    {
-        return controls.toArray( new Control[0] );
-    }
-
+    Control[] getControls();
 
+    
     /**
      * Gets the crendentials
      *
      * @return the credentials
      */
-    public byte[] getCredentials()
-    {
-        if ( credentials != null )
-        {
-            return credentials;
-        }
-        else
-        {
-            return Strings.EMPTY_BYTES;
-        }
-    }
+    byte[] getCredentials();
 
 
     /**
@@ -145,21 +59,15 @@ public abstract class SaslRequest
      *
      * @return the quality of protection
      */
-    public SaslQoP getQualityOfProtection()
-    {
-        return qualityOfProtection;
-    }
-
-
+    SaslQoP getQualityOfProtection();
+    
+    
     /**
      * Gets realm name.
      *
      * @return the realm name
      */
-    public String getRealmName()
-    {
-        return realmName;
-    }
+    String getRealmName();
 
 
     /**
@@ -167,10 +75,7 @@ public abstract class SaslRequest
      *
      * @return the SASL mechanism
      */
-    public String getSaslMechanism()
-    {
-        return saslMechanism;
-    }
+    String getSaslMechanism();
 
 
     /**
@@ -178,21 +83,15 @@ public abstract class SaslRequest
      *
      * @return the security strength
      */
-    public SaslSecurityStrength getSecurityStrength()
-    {
-        return securityStrength;
-    }
-
+    SaslSecurityStrength getSecurityStrength();
 
+    
     /**
      * Gets the username.
      *
      * @return the username
      */
-    public String getUsername()
-    {
-        return username;
-    }
+    String getUsername();
 
 
     /**
@@ -200,107 +99,5 @@ public abstract class SaslRequest
      *
      * @return the flag indicating if mutual authentication is required
      */
-    public boolean isMutualAuthentication()
-    {
-        return mutualAuthentication;
-    }
-
-
-    /**
-     * Sets the Authorization ID
-     *
-     * @param authorizationId The authorization ID
-     */
-    public void setAuthorizationId( String authorizationId )
-    {
-        this.authorizationId = authorizationId;
-    }
-
-
-    /**
-     * Sets the credentials.
-     *
-     * @param credentials the credentials
-     */
-    public void setCredentials( byte[] credentials )
-    {
-        this.credentials = credentials;
-    }
-
-
-    /**
-     * Sets the credentials.
-     *
-     * @param credentials the credentials
-     */
-    public void setCredentials( String credentials )
-    {
-        this.credentials = Strings.getBytesUtf8( credentials );
-    }
-
-
-    /**
-     * Sets the flag indicating if mutual authentication is required.
-     *
-     * @param mutualAuthentication the flag indicating if mutual authentication is required
-     */
-    public void setMutualAuthentication( boolean mutualAuthentication )
-    {
-        this.mutualAuthentication = mutualAuthentication;
-    }
-
-
-    /**
-     * Sets the quality of protection.
-     *
-     * @param qualityOfProtection the quality of protection
-     */
-    public void setQualityOfProtection( SaslQoP qualityOfProtection )
-    {
-        this.qualityOfProtection = qualityOfProtection;
-    }
-
-
-    /**
-     * Sets the realm name.
-     * 
-     * @param realmName The realm name
-     */
-    protected void setRealmName( String realmName )
-    {
-        this.realmName = realmName;
-    }
-
-
-    /**
-     * Sets the SASL mechanism
-     *
-     * @param saslMechanism the SASL mechanism
-     */
-    protected void setSaslMechanism( String saslMechanism )
-    {
-        this.saslMechanism = saslMechanism;
-    }
-
-
-    /**
-     * Sets the security strength.
-     *
-     * @param securityStrength the security strength
-     */
-    public void setSecurityStrength( SaslSecurityStrength securityStrength )
-    {
-        this.securityStrength = securityStrength;
-    }
-
-
-    /**
-     * Sets the username.
-     *
-     * @param username the username
-     */
-    public void setUsername( String username )
-    {
-        this.username = username;
-    }
+    boolean isMutualAuthentication();
 }



Mime
View raw message