directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r768052 - in /directory/studio/trunk: connection-core/src/main/java/org/apache/directory/studio/connection/core/ test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/
Date Thu, 23 Apr 2009 21:04:57 GMT
Author: seelmann
Date: Thu Apr 23 21:04:57 2009
New Revision: 768052

URL: http://svn.apache.org/viewvc?rev=768052&view=rev
Log:
Fix for DIRSTUDIO-485 (Provide default IAuthHandler and IReferralHandler to be used in connections
core without connections ui)

Modified:
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
    directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java?rev=768052&r1=768051&r2=768052&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
(original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
Thu Apr 23 21:04:57 2009
@@ -25,6 +25,9 @@
 import java.util.List;
 import java.util.PropertyResourceBundle;
 
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.event.CoreEventRunner;
 import org.apache.directory.studio.connection.core.event.EventRunner;
 import org.apache.directory.studio.connection.core.io.jndi.LdifModificationLogger;
@@ -190,6 +193,32 @@
      */
     public IAuthHandler getAuthHandler()
     {
+        if(authHandler == null)
+        {
+            // if no authentication handler was set a default authentication handler is used
+            // that only works if the bind password is stored within the connection parameters.
+            authHandler = new IAuthHandler()
+            {
+                public ICredentials getCredentials( ConnectionParameter connectionParameter
)
+                {
+                    if ( connectionParameter.getBindPrincipal() == null || "".equals( connectionParameter.getBindPrincipal()
) ) //$NON-NLS-1$
+                    {
+                        return new Credentials( "", "", connectionParameter ); //$NON-NLS-1$
//$NON-NLS-2$
+                    }
+                    else if ( connectionParameter.getBindPassword() != null && !"".equals(
connectionParameter.getBindPassword() ) ) //$NON-NLS-1$
+                    {
+                        return new Credentials( connectionParameter.getBindPrincipal(), connectionParameter.getBindPassword(),
+                            connectionParameter );
+                    }
+                    else
+                    {
+                        // no credentials provided in connection parameters
+                        // returning null cancel the authentication
+                        return null;
+                    }
+                }
+            };
+        }
         return authHandler;
     }
 
@@ -214,6 +243,19 @@
      */
     public IReferralHandler getReferralHandler()
     {
+        if(referralHandler == null)
+        {
+            // if no referral handler was set a default referral handler is used
+            // that just cancels referral chasing
+            referralHandler = new IReferralHandler()
+            {
+                public Connection getReferralConnection( LdapURL referralURL )
+                {
+                    // null cancels referral chasing
+                    return null;
+                }  
+            };
+        }
         return referralHandler;
     }
 

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java?rev=768052&r1=768051&r2=768052&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
(original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
Thu Apr 23 21:04:57 2009
@@ -41,7 +41,7 @@
      * to select a proper connection.
      * 
      * @param referralURL the referral URL
-     * @return the target connection
+     * @return the target connection, null to cancel referral chasing
      */
     public Connection getReferralConnection( LdapURL referralURL );
 

Modified: directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java?rev=768052&r1=768051&r2=768052&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java
(original)
+++ directory/studio/trunk/test-integration-core/src/main/java/org/apache/directory/studio/test/integration/core/JNDIConnectionWrapperTest.java
Thu Apr 23 21:04:57 2009
@@ -33,17 +33,13 @@
 
 import org.apache.directory.server.unit.AbstractServerTest;
 import org.apache.directory.studio.connection.core.Connection;
-import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.ConnectionParameter;
-import org.apache.directory.studio.connection.core.Credentials;
-import org.apache.directory.studio.connection.core.IAuthHandler;
-import org.apache.directory.studio.connection.core.ICredentials;
-import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
 import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
 import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
 import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
 import org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper;
+import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 
 
@@ -138,8 +134,6 @@
             EncryptionMethod.NONE, AuthenticationMethod.SIMPLE, "uid=admin,ou=system", "secret",
null, true, null );
         Connection connection = new Connection( connectionParameter );
         JNDIConnectionWrapper connectionWrapper = connection.getJNDIConnectionWrapper();
-        IAuthHandler authHandler = getAuthHandler();
-        ConnectionCorePlugin.getDefault().setAuthHandler( authHandler );
 
         assertFalse( connectionWrapper.isConnected() );
 
@@ -168,7 +162,7 @@
         // simple auth without principal and credential
         monitor = getProgressMonitor();
         connectionParameter = new ConnectionParameter( null, "localhost", ldapService.getPort(),
-            EncryptionMethod.NONE, AuthenticationMethod.SIMPLE, null, null, null, true, null
);
+            EncryptionMethod.NONE, AuthenticationMethod.SIMPLE, "uid=admin", "invalid", null,
true, null );
         connection = new Connection( connectionParameter );
         connectionWrapper = connection.getJNDIConnectionWrapper();
         connectionWrapper.connect( monitor );
@@ -234,18 +228,4 @@
         return monitor;
     }
 
-
-    private IAuthHandler getAuthHandler()
-    {
-        IAuthHandler authHandler = new IAuthHandler()
-        {
-            public ICredentials getCredentials( ConnectionParameter connectionParameter )
-            {
-                return new Credentials( connectionParameter.getBindPrincipal(), connectionParameter.getBindPassword(),
-                    connectionParameter );
-            }
-        };
-        return authHandler;
-    }
-
 }



Mime
View raw message