diff --git a/guacamole/pom.xml b/guacamole/pom.xml
index 86f9ac29b..34be37da3 100644
--- a/guacamole/pom.xml
+++ b/guacamole/pom.xml
@@ -69,7 +69,6 @@
org.slf4j
slf4j-api
1.6.1
- provided
org.slf4j
@@ -83,7 +82,6 @@
net.sourceforge.guacamole
guacamole-common
0.4.0
- provided
@@ -91,7 +89,6 @@
net.sourceforge.guacamole
guacamole-common-auth
0.5.0
- provided
diff --git a/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader.java b/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader.java
new file mode 100644
index 000000000..b1a398a69
--- /dev/null
+++ b/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader.java
@@ -0,0 +1,125 @@
+
+package net.sourceforge.guacamole.net.basic;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
+import net.sourceforge.guacamole.GuacamoleException;
+import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
+import net.sourceforge.guacamole.properties.GuacamoleProperties;
+
+/*
+ * Guacamole - Clientless Remote Desktop
+ * Copyright (C) 2010 Michael Jumper
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+public class GuacamoleClassLoader extends ClassLoader {
+
+ private URLClassLoader classLoader = null;
+
+ private static GuacamoleException exception = null;
+ private static GuacamoleClassLoader instance = null;
+
+ static {
+
+ try {
+ // Attempt to create singleton classloader which loads classes from
+ // all .jar's in the lib directory defined in guacamole.properties
+ instance = new GuacamoleClassLoader(
+ GuacamoleProperties.getProperty(BasicGuacamoleProperties.LIB_DIRECTORY)
+ );
+ }
+
+ catch (GuacamoleException e) {
+ // On error, record exception
+ exception = e;
+ }
+
+ }
+
+ private GuacamoleClassLoader(File libDirectory) throws GuacamoleException {
+
+ // If no directory provided, just direct requests to parent classloader
+ if (libDirectory == null)
+ return;
+
+ // Validate directory is indeed a directory
+ if (!libDirectory.isDirectory())
+ throw new GuacamoleException(libDirectory + " is not a directory.");
+
+ // Get list of URLs for all .jar's in the lib directory
+ Collection jarURLs = new ArrayList();
+ for (File file : libDirectory.listFiles(new FilenameFilter() {
+
+ @Override
+ public boolean accept(File dir, String name) {
+
+ // If it ends with .jar, accept the file
+ return name.endsWith(".jar");
+
+ }
+
+ })) {
+
+ try {
+
+ // Add URL for the .jar to the jar URL list
+ jarURLs.add(file.toURI().toURL());
+
+ }
+ catch (MalformedURLException e) {
+ throw new GuacamoleException(e);
+ }
+
+ }
+
+ // Set delegate classloader to new URLClassLoader which loads from the
+ // .jars found above.
+
+ URL[] urls = new URL[jarURLs.size()];
+ classLoader = new URLClassLoader(
+ jarURLs.toArray(urls),
+ getClass().getClassLoader()
+ );
+
+ }
+
+ public static GuacamoleClassLoader getInstance() throws GuacamoleException {
+
+ // If instance could not be created, rethrow original exception
+ if (exception != null) throw exception;
+
+ return instance;
+
+ }
+
+ @Override
+ protected Class> findClass(String name) throws ClassNotFoundException {
+
+ // If no classloader, use super
+ if (classLoader == null)
+ return super.findClass(name);
+
+ // Otherwise, delegate
+ return classLoader.loadClass(name);
+
+ }
+
+}
diff --git a/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/properties/AuthenticationProviderProperty.java b/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/properties/AuthenticationProviderProperty.java
index 2b0ce0d08..90e982e32 100644
--- a/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/properties/AuthenticationProviderProperty.java
+++ b/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/properties/AuthenticationProviderProperty.java
@@ -21,6 +21,7 @@ package net.sourceforge.guacamole.net.basic.properties;
import java.lang.reflect.InvocationTargetException;
import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.auth.AuthenticationProvider;
+import net.sourceforge.guacamole.net.basic.GuacamoleClassLoader;
import net.sourceforge.guacamole.properties.GuacamoleProperty;
public abstract class AuthenticationProviderProperty implements GuacamoleProperty {
@@ -31,7 +32,9 @@ public abstract class AuthenticationProviderProperty implements GuacamolePropert
// Get auth provider instance
try {
- Object obj = Class.forName(authProviderClassName).getConstructor().newInstance();
+ Object obj = GuacamoleClassLoader.getInstance().loadClass(authProviderClassName)
+ .getConstructor().newInstance();
+
if (!(obj instanceof AuthenticationProvider))
throw new GuacamoleException("Specified authentication provider class is not a AuthenticationProvider.");
diff --git a/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties.java b/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties.java
index ecaacba6c..cb9430e96 100644
--- a/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties.java
+++ b/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties.java
@@ -39,4 +39,11 @@ public class BasicGuacamoleProperties {
};
+ public static final FileGuacamoleProperty LIB_DIRECTORY = new FileGuacamoleProperty() {
+
+ @Override
+ public String getName() { return "lib-directory"; }
+
+ };
+
}