commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r424139 - /jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java
Date Fri, 21 Jul 2006 00:09:23 GMT
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


Mime
View raw message