directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r682763 - in /directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers: ./ bind/ bind/cramMD5/ bind/digestMD5/ bind/gssapi/ bind/plain/
Date Tue, 05 Aug 2008 15:45:47 GMT
Author: elecharny
Date: Tue Aug  5 08:45:46 2008
New Revision: 682763

URL: http://svn.apache.org/viewvc?rev=682763&view=rev
Log:
Added a init and cleanup method in the MechanismHandler, so that those methods are directly
related to the underlying mechanism.

Modified:
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/MechanismHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SaslConstants.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SimpleMechanismHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/cramMD5/CramMd5MechanismHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/digestMD5/DigestMd5MechanismHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/gssapi/GssapiMechanismHandler.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/plain/PlainMechanismHandler.java

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
Tue Aug  5 08:45:46 2008
@@ -107,32 +107,6 @@
             
             handle( ldapSession, message );
             return;
-
-            /*
-            if ( coreSession.getDirectoryService().isAllowAnonymousAccess() )
-            {
-            	// We are not authenticated, and the server allows anonymous access,
-            	// we have create a new Anonymous session. Just return.
-            	handle( ldapSession, message );
-            	return;
-            }
-            else if ( message instanceof ResultResponseRequest )
-            {
-            	// The server does not allow anonymous access, and the client
-            	// is not authenticated : get out if the request expect a
-            	// response.
-                ResultResponse response = ( ( ResultResponseRequest ) message ).getResultResponse();
-                response.getLdapResult().setErrorMessage( "Anonymous access disabled." );
-                response.getLdapResult().setResultCode( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS
);
-                ldapSession.getIoSession().write( response );
-                return;
-            }
-            else
-            {
-            	// Last case : the AbandonRequest. We just quit.
-                return;
-            }
-            */
         }
     }
 

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewBindHandler.java
Tue Aug  5 08:45:46 2008
@@ -249,16 +249,13 @@
                 // Build the response
                 result.setResultCode( ResultCodeEnum.SASL_BIND_IN_PROGRESS );
                 BindResponse resp = ( BindResponse ) bindRequest.getResultResponse();
-                
+
                 // Store the challenge
                 resp.setServerSaslCreds( tokenBytes );
                 
                 // Switch to AuthPending
                 ldapSession.setAuthPending();
                 
-                // Store the current mechanism, as the C/R is not finished
-                ldapSession.putSaslProperty( SaslConstants.SASL_MECH, bindRequest.getSaslMechanism()
);
-                
                 // And write back the response
                 ldapSession.getIoSession().write( resp );
                 LOG.debug( "Returning final authentication data to client to complete context."
);
@@ -285,7 +282,7 @@
      */
     private void sendAuthMethNotSupported( LdapSession ldapSession, BindRequest bindRequest
)
     {
-        // First, reinit the state to Anonymous, and clear the
+        // First, r-einit the state to Anonymous, and clear the
         // saslProperty map
         ldapSession.clearSaslProperties();
         ldapSession.setAnonymous();
@@ -352,12 +349,12 @@
         }
         
         // Clean the SaslProperties, we don't need them anymore
-        // except the saslCreds and saslServer which will be used 
-        // by the DIGEST-MD5 mech.
-        ldapSession.removeSaslProperty( SaslConstants.SASL_MECH );
-        ldapSession.removeSaslProperty( SaslConstants.SASL_HOST );
-        ldapSession.removeSaslProperty( SaslConstants.SASL_AUTHENT_USER );
-        ldapSession.removeSaslProperty( SaslConstants.SASL_USER_BASE_DN );
+        MechanismHandler handler = (MechanismHandler)ldapSession.getSaslProperty( SaslConstants.SASL_MECH_HANDLER
);
+        
+        if ( handler != null )
+        {
+            handler.cleanup( ldapSession );
+        }
 
         ldapSession.getIoSession().write( response );
         
@@ -367,8 +364,6 @@
     
     private void handleSaslAuthPending( LdapSession ldapSession, BindRequest bindRequest,
DirectoryService ds ) throws Exception
     {
-        CoreSession adminSession = ldapSession.getLdapServer().getDirectoryService().getAdminSession();
-        
         // First, check that we have the same mechanism
         String saslMechanism = bindRequest.getSaslMechanism();
         
@@ -527,13 +522,14 @@
                 ldapSession.putSaslProperty( SaslConstants.SASL_MECH, saslMechanism );
                 
 
-                // Store the host in the ldap session
-                String saslHost = getLdapServer().getSaslHost();
-                ldapSession.putSaslProperty( SaslConstants.SASL_HOST, saslHost );
-
                 // Get the handler for this mechanism
                 MechanismHandler mechanismHandler = handlers.get( saslMechanism );
                 
+                // Stor ethe mechanism handler in the salsProperties
+                ldapSession.putSaslProperty( SaslConstants.SASL_MECH_HANDLER, mechanismHandler
);
+                
+                mechanismHandler.init( ldapSession );
+
                 // Get the SaslServer instance which manage the C/R exchange
                 SaslServer ss = mechanismHandler.handleMechanism( ldapSession, bindRequest
);
                 

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/MechanismHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/MechanismHandler.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/MechanismHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/MechanismHandler.java
Tue Aug  5 08:45:46 2008
@@ -45,4 +45,20 @@
      * @throws Exception
      */
     public SaslServer handleMechanism( LdapSession session, BindRequest bindRequest ) throws
Exception;
+    
+    
+    /**
+     * Initialize the saslProperties with some mechanism's specific data
+     *
+     * @param ldapSession the Ldapsession instance
+     */
+    public void init( LdapSession ldapSession );
+    
+    
+    /**
+     * Clean the Sasl properties when the use has been authenticated
+     *
+     * @param ldapSession the Ldapsession instance
+     */
+    public void cleanup( LdapSession ldapSession );
 }

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SaslConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SaslConstants.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SaslConstants.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SaslConstants.java
Tue Aug  5 08:45:46 2008
@@ -82,6 +82,18 @@
     
     
     /**
+     * A key constant representing the SASL properties 
+     */
+    public static final String SASL_PROPS = "saslProps";
+    
+    
+    /**
+     * A key constant representing the SASL mechanism handler
+     */
+    public static final String SASL_MECH_HANDLER = "saslmechHandler";
+    
+    
+    /**
      * A key constant representing the SASL IoFilter 
      */
     public static final String SASL_FILTER = "SASL_FILTER";

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SimpleMechanismHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SimpleMechanismHandler.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SimpleMechanismHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/SimpleMechanismHandler.java
Tue Aug  5 08:45:46 2008
@@ -130,4 +130,22 @@
         
         return null;
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void init( LdapSession ldapSession )
+    {
+        // Do nothing
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void cleanup( LdapSession ldapSession )
+    {
+        ldapSession.clearSaslProperties();
+    }
 }

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/cramMD5/CramMd5MechanismHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/cramMD5/CramMd5MechanismHandler.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/cramMD5/CramMd5MechanismHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/cramMD5/CramMd5MechanismHandler.java
Tue Aug  5 08:45:46 2008
@@ -66,4 +66,27 @@
 
         return ss;
     }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void init( LdapSession ldapSession )
+    {
+        // Store the host in the ldap session
+        String saslHost = ldapSession.getLdapServer().getSaslHost();
+        ldapSession.putSaslProperty( SaslConstants.SASL_HOST, saslHost );
+    }
+    
+
+    /**
+     * Remove the SaslServer and Mechanism property.
+     * 
+     * @param ldapSession the Ldapsession instance
+     */
+    public void cleanup( LdapSession ldapSession )
+    {
+        ldapSession.clearSaslProperties();
+    }
+
 }

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/digestMD5/DigestMd5MechanismHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/digestMD5/DigestMd5MechanismHandler.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/digestMD5/DigestMd5MechanismHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/digestMD5/DigestMd5MechanismHandler.java
Tue Aug  5 08:45:46 2008
@@ -81,23 +81,53 @@
 
         if ( ss == null )
         {
-            String saslHost = ldapSession.getLdapServer().getSaslHost();
-            String userBaseDn = ldapSession.getLdapServer().getSearchBaseDn();
-            ldapSession.putSaslProperty( SaslConstants.SASL_HOST, saslHost );
-            ldapSession.putSaslProperty( SaslConstants.SASL_USER_BASE_DN, userBaseDn );
-
-            Map<String, String> saslProps = new HashMap<String, String>();
-            saslProps.put( Sasl.QOP, ldapSession.getLdapServer().getSaslQopString() );
-            saslProps.put( "com.sun.security.sasl.digest.realm", getActiveRealms( ldapSession.getLdapServer()
) );
-
             CoreSession adminSession = ldapSession.getLdapServer().getDirectoryService().getAdminSession();
 
             CallbackHandler callbackHandler = new DigestMd5CallbackHandler( ldapSession,
adminSession, bindRequest );
 
-            ss = Sasl.createSaslServer( SupportedSaslMechanisms.DIGEST_MD5, SaslConstants.LDAP_PROTOCOL,
saslHost, saslProps, callbackHandler );
+            ss = Sasl.createSaslServer( 
+                SupportedSaslMechanisms.DIGEST_MD5, 
+                SaslConstants.LDAP_PROTOCOL, 
+                (String)ldapSession.getSaslProperty( SaslConstants.SASL_HOST ),
+                (Map<String, String>)ldapSession.getSaslProperty( SaslConstants.SASL_PROPS
),
+                callbackHandler );
             ldapSession.putSaslProperty( SaslConstants.SASL_SERVER, ss );
         }
 
         return ss;
     }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void init( LdapSession ldapSession )
+    {
+        // Store the host in the ldap session
+        String saslHost = ldapSession.getLdapServer().getSaslHost();
+        String userBaseDn = ldapSession.getLdapServer().getSearchBaseDn();
+
+
+        ldapSession.putSaslProperty( SaslConstants.SASL_HOST, saslHost );
+        ldapSession.putSaslProperty( SaslConstants.SASL_USER_BASE_DN, userBaseDn );
+
+        Map<String, String> saslProps = new HashMap<String, String>();
+        saslProps.put( Sasl.QOP, ldapSession.getLdapServer().getSaslQopString() );
+        saslProps.put( "com.sun.security.sasl.digest.realm", getActiveRealms( ldapSession.getLdapServer()
) );
+        ldapSession.putSaslProperty( SaslConstants.SASL_PROPS, saslProps );
+    }
+    
+    
+    /**
+     * Remove the Host, UserBaseDn, props and Mechanism property.
+     * 
+     * @param ldapSession the Ldapsession instance
+     */
+    public void cleanup( LdapSession ldapSession )
+    {
+        ldapSession.removeSaslProperty( SaslConstants.SASL_HOST );
+        ldapSession.removeSaslProperty( SaslConstants.SASL_USER_BASE_DN );
+        ldapSession.removeSaslProperty( SaslConstants.SASL_MECH );
+        ldapSession.removeSaslProperty( SaslConstants.SASL_PROPS );
+    }
 }

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/gssapi/GssapiMechanismHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/gssapi/GssapiMechanismHandler.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/gssapi/GssapiMechanismHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/gssapi/GssapiMechanismHandler.java
Tue Aug  5 08:45:46 2008
@@ -45,13 +45,9 @@
 {
     public SaslServer handleMechanism( LdapSession ldapSession, BindRequest bindRequest )
throws Exception
     {
-        SaslServer ss;
+        SaslServer ss = (SaslServer)ldapSession.getSaslProperty( SaslConstants.SASL_SERVER
);
 
-        if ( ldapSession.getIoSession().containsAttribute( SaslConstants.SASL_SERVER ) )
-        {
-            ss = ( SaslServer ) ldapSession.getIoSession().getAttribute( SaslConstants.SASL_SERVER
);
-        }
-        else
+        if ( ss == null )
         {
             Subject subject = ( Subject ) ldapSession.getIoSession().getAttribute( "saslSubject"
);
 
@@ -74,4 +70,29 @@
 
         return ss;
     }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void init( LdapSession ldapSession )
+    {
+        // Store the host in the ldap session
+        String saslHost = ldapSession.getLdapServer().getSaslHost();
+        ldapSession.putSaslProperty( SaslConstants.SASL_HOST, saslHost );
+    }
+
+
+    /**
+     * Remove the Host, UserBaseDn, props and Mechanism property.
+     * 
+     * @param ldapSession the Ldapsession instance
+     */
+    public void cleanup( LdapSession ldapSession )
+    {
+        ldapSession.removeSaslProperty( SaslConstants.SASL_HOST );
+        ldapSession.removeSaslProperty( SaslConstants.SASL_USER_BASE_DN );
+        ldapSession.removeSaslProperty( SaslConstants.SASL_MECH );
+        ldapSession.removeSaslProperty( SaslConstants.SASL_PROPS );
+    }
 }

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/plain/PlainMechanismHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/plain/PlainMechanismHandler.java?rev=682763&r1=682762&r2=682763&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/plain/PlainMechanismHandler.java
(original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/bind/plain/PlainMechanismHandler.java
Tue Aug  5 08:45:46 2008
@@ -56,4 +56,24 @@
 
         return ss;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void init( LdapSession ldapSession )
+    {
+        // Do nothing
+    }
+
+    
+    /**
+     * Remove the SaslServer and Mechanism property.
+     * 
+     * @param ldapSession the Ldapsession instance
+     */
+    public void cleanup( LdapSession ldapSession )
+    {
+        ldapSession.clearSaslProperties();
+    }
 }
\ No newline at end of file



Mime
View raw message