incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r571207 - in /incubator/ftpserver/trunk/core/src: java/org/apache/ftpserver/ssl/DefaultSsl.java java/org/apache/ftpserver/util/ClassUtils.java test/org/apache/ftpserver/util/ClassUtilsTest.java
Date Thu, 30 Aug 2007 15:27:02 GMT
Author: ngn
Date: Thu Aug 30 08:27:01 2007
New Revision: 571207

URL: http://svn.apache.org/viewvc?rev=571207&view=rev
Log:
Fixed a bug where the ExtendedX509KeyManager would not be detected and MINA based SSL break

Modified:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java?rev=571207&r1=571206&r2=571207&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java Thu Aug
30 08:27:01 2007
@@ -33,6 +33,7 @@
 import javax.net.ssl.X509KeyManager;
 
 import org.apache.ftpserver.FtpServerConfigurationException;
+import org.apache.ftpserver.util.ClassUtils;
 import org.apache.ftpserver.util.IoUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -236,10 +237,10 @@
         ctx = SSLContext.getInstance(protocol);
         
         KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
-        
+
         // wrap key managers to allow us to control their behavior (FTPSERVER-93)
         for (int i = 0; i < keyManagers.length; i++) {
-          if(implementsInterface(keyManagers[i].getClass(), "javax.net.ssl.X509ExtendedKeyManager"))
{
+          if(ClassUtils.extendsClass(keyManagers[i].getClass(), "javax.net.ssl.X509ExtendedKeyManager"))
{
         	  keyManagers[i] = new ExtendedAliasKeyManager(keyManagers[i], keyAlias);
           } else if(keyManagers[i] instanceof X509KeyManager) {
         	  keyManagers[i] = new AliasKeyManager(keyManagers[i], keyAlias);
@@ -259,18 +260,6 @@
         return ctx;
     }
     
-    private boolean implementsInterface(Class clazz, String interfaceName) {
-    	Class[] interfaces = clazz.getInterfaces();
-    	
-    	for (int i = 0; i < interfaces.length; i++) {
-			if(interfaces[i].getName().equals(interfaceName)) {
-				return true;
-			}
-		}
-    	
-    	return false;
-    }
-
     public ClientAuth getClientAuth() {
         return clientAuthReqd;
     }

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java?rev=571207&r1=571206&r2=571207&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java Thu
Aug 30 08:27:01 2007
@@ -376,16 +376,25 @@
         return castValue;
     }
     
-    
-    public static boolean implementsInterface(Class clazz, String interfaceName) {
-    	Class[] interfaces = clazz.getInterfaces();
-    	
-    	for (int i = 0; i < interfaces.length; i++) {
-			if(interfaces[i].getName().equals(interfaceName)) {
-				return true;
-			}
-		}
+    /**
+     * Checks if a class is a subclass of a class with the specified name.
+     * Used as an instanceOf without having to load the class, useful when
+     * trying to check for classes that might not be available in the runtime
+     * JRE.
+     * @param clazz The class to check
+     * @param className The class name to look for in the super classes
+     * @return true if the class extends a class by the specified name.
+     */
+    public static boolean extendsClass(final Class clazz, String className) {
+    	Class superClass = clazz.getSuperclass();
     	
+    	while(superClass != null) {
+    		if(superClass.getName().equals(className)) {
+    			return true;
+    		}
+    		superClass = superClass.getSuperclass();
+    		
+    	}
     	return false;
     }
 }

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java?rev=571207&r1=571206&r2=571207&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java
Thu Aug 30 08:27:01 2007
@@ -25,21 +25,16 @@
 import java.util.Map;
 import java.util.Properties;
 
-import javax.net.ssl.X509KeyManager;
-
 import junit.framework.TestCase;
 
 import org.apache.ftpserver.config.PropertiesConfiguration;
 import org.apache.ftpserver.ftplet.Configuration;
-import org.apache.ftpserver.ssl.AliasKeyManager;
 
 public class ClassUtilsTest extends TestCase {
 
 	public void testImplementsInterface() {
-		X509KeyManager km = new AliasKeyManager(null, null);
-		
-		assertTrue(ClassUtils.implementsInterface(km.getClass(), "javax.net.ssl.X509KeyManager"));
-		assertFalse(ClassUtils.implementsInterface(km.getClass(), "foo"));
+		assertTrue(ClassUtils.extendsClass(MySubBean.class, MyBean.class.getName()));
+		assertFalse(ClassUtils.extendsClass(MySubBean.class, "foo"));
 	}
 	
     public void testNormalizePropertyName() {



Mime
View raw message