Commits

Anonymous committed cfbcf63

Update osuser to use a common classloading point. This should fix a lot
of classloading errors in different application servers (read: JBoss).

This fixes USER-62 in particular.

Comments (0)

Files changed (4)

src/java/com/opensymphony/user/UserManager.java

 import com.opensymphony.user.provider.UserProvider;
 import com.opensymphony.user.util.ConfigLoader;
 
+import com.opensymphony.util.ClassLoaderUtil;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
     }
 
     public UserManager(String filename) {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
         accessor = new Accessor();
 
         // load config
         // crazy (read: JBoss) and won't work with the "/"
         ConfigLoader configLoader = new ConfigLoader();
         String loc = "/" + filename;
-        InputStream in = classLoader.getResourceAsStream(loc);
+        InputStream in = ClassLoaderUtil.getResourceAsStream(loc, this.getClass());
 
         if (in == null) {
             loc = filename;
-            in = classLoader.getResourceAsStream(loc);
+            in = ClassLoaderUtil.getResourceAsStream(loc, this.getClass());
         }
 
         if (in == null) {
             loc = "/META-INF/" + filename;
-            in = classLoader.getResourceAsStream(loc);
+            in = ClassLoaderUtil.getResourceAsStream(loc, this.getClass());
         }
 
         if (in == null) {
             loc = "META-INF/" + filename;
-            in = classLoader.getResourceAsStream(loc);
+            in = ClassLoaderUtil.getResourceAsStream(loc, this.getClass());
         }
 
         if (in == null) {
             loc = "/META-INF/osuser-default.xml";
-            in = classLoader.getResourceAsStream(loc);
+            in = ClassLoaderUtil.getResourceAsStream(loc, this.getClass());
         }
 
         if (in == null) {
             loc = "META-INF/osuser-default.xml";
-            in = classLoader.getResourceAsStream(loc);
+            in = ClassLoaderUtil.getResourceAsStream(loc, this.getClass());
         }
 
         if (logger.isDebugEnabled()) {

src/java/com/opensymphony/user/authenticator/SmartAuthenticator.java

 import com.opensymphony.user.authenticator.orion.OrionAuthenticator;
 import com.opensymphony.user.authenticator.weblogic.WeblogicAuthenticator;
 
+import com.opensymphony.util.ClassLoaderUtil;
+
 import javax.servlet.http.HttpServletRequest;
 
 
 
     private Authenticator loadJBossAuthenticator() {
         try {
-            Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.AuthenticationManager");
+            ClassLoaderUtil.loadClass("org.jboss.security.AuthenticationManager", this.getClass());
 
             Authenticator jbossAuth = new JBossAuthenticator();
             jbossAuth.init(properties);
 
     private Authenticator loadOrionAuthenticator() {
         try {
-            Thread.currentThread().getContextClassLoader().loadClass("com.evermind.security.RoleManager");
+            ClassLoaderUtil.loadClass("com.evermind.security.RoleManager", this.getClass());
 
             Authenticator orionAuth = new OrionAuthenticator();
             orionAuth.init(properties);
 
     private Authenticator loadWeblogicAuthenticator() {
         try {
-            Thread.currentThread().getContextClassLoader().loadClass("weblogic.servlet.security.ServletAuthentication");
+            ClassLoaderUtil.loadClass("weblogic.servlet.security.ServletAuthentication", this.getClass());
 
             Authenticator wlsAuth = new WeblogicAuthenticator();
             wlsAuth.init(properties);

src/java/com/opensymphony/user/provider/file/FileEntitiesCache.java

  */
 package com.opensymphony.user.provider.file;
 
+import com.opensymphony.util.ClassLoaderUtil;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
         if (storeFileType.equalsIgnoreCase("file")) {
             return new FileInputStream(storeFile);
         } else if (storeFileType.equalsIgnoreCase("resource")) {
-            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-
-            return classLoader.getResourceAsStream(storeFile);
+            return ClassLoaderUtil.getResourceAsStream(storeFile, this.getClass());
         } else {
             log.fatal("property storeFileType must be one of (file,resource)");
 

src/java/com/opensymphony/user/util/ConfigLoader.java

 import com.opensymphony.user.authenticator.Authenticator;
 import com.opensymphony.user.provider.UserProvider;
 
+import com.opensymphony.util.ClassLoaderUtil;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
  * providers, reads their properties and initializes them.
  *
  * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  *
  * @see com.opensymphony.user.UserManager
  * @see com.opensymphony.user.provider.UserProvider
         if (userManager != null) {
             try {
                 Authenticator authenticator;
-
-                try {
-                    authenticator = (Authenticator) Class.forName(currentClass).newInstance();
-                } catch (ClassNotFoundException ee) {
-                    // try using thread's classloader
-                    authenticator = (Authenticator) Class.forName(currentClass, true, Thread.currentThread().getContextClassLoader()).newInstance();
-                } catch (NoClassDefFoundError ee) {
-                    // try using thread's classloader
-                    authenticator = (Authenticator) Class.forName(currentClass, true, Thread.currentThread().getContextClassLoader()).newInstance();
-                }
+                authenticator = (Authenticator) ClassLoaderUtil.loadClass(currentClass, this.getClass()).newInstance();
 
                 if (authenticator.init(currentProperties)) {
                     userManager.setAuthenticator(authenticator);
         if (userManager != null) {
             try {
                 UserProvider provider;
-
-                try {
-                    provider = (UserProvider) Class.forName(currentClass).newInstance();
-                } catch (ClassNotFoundException ee) {
-                    // try using thread's classloader
-                    provider = (UserProvider) Class.forName(currentClass, true, Thread.currentThread().getContextClassLoader()).newInstance();
-                } catch (NoClassDefFoundError ee) {
-                    // try using thread's classloader
-                    provider = (UserProvider) Class.forName(currentClass, true, Thread.currentThread().getContextClassLoader()).newInstance();
-                }
+                provider = (UserProvider) ClassLoaderUtil.loadClass(currentClass, this.getClass()).newInstance();
 
                 if (provider.init(currentProperties)) {
                     userManager.addProvider(provider);