You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2006/07/21 02:09:23 UTC

svn commit: r424139 - /jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java

Author: skitching
Date: Thu Jul 20 17:09:23 2006
New Revision: 424139

URL: http://svn.apache.org/viewvc?rev=424139&view=rev
Log:
Fix for LOGGING-107. JCL failed when run under a security policy that prevented calling ClassLoader.getParent.
We now catch SecurityException in this case, and also use an AccessController so JCL can be granted permissions
without needing the caller to have those permissions too.

Modified:
    jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java

Modified: jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java?rev=424139&r1=424138&r2=424139&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java (original)
+++ jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java Thu Jul 20 17:09:23 2006
@@ -689,6 +689,28 @@
     }
 
     /**
+     * Fetch the parent classloader of a specified classloader.
+     * <p>
+     * If a SecurityException occurs, null is returned.
+     * <p>
+     * Note that this method is non-static merely so logDiagnostic is available.
+     */
+    private ClassLoader getParentClassLoader(final ClassLoader cl) {
+        try {
+            return (ClassLoader)AccessController.doPrivileged(
+                    new PrivilegedAction() {
+                        public Object run() {
+                            return cl.getParent();
+                        }
+                    });
+        } catch(SecurityException ex) {
+            logDiagnostic("[SECURITY] Unable to obtain parent classloader");
+            return null;
+        }
+        
+    }
+
+    /**
      * Utility method to check whether a particular logging library is
      * present and available for use. Note that this does <i>not</i>
      * affect the future behaviour of this class.
@@ -1161,7 +1183,8 @@
             }
             
             // try the parent classloader
-            currentCL = currentCL.getParent();
+            // currentCL = currentCL.getParent();
+            currentCL = getParentClassLoader(currentCL);
         }
 
         if ((logAdapter != null) && affectState) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org