myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1003669 - /myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ClassUtils.java
Date Fri, 01 Oct 2010 22:08:16 GMT
Author: lu4242
Date: Fri Oct  1 22:08:16 2010
New Revision: 1003669

URL: http://svn.apache.org/viewvc?rev=1003669&view=rev
Log:
add getContextClassLoader to sync with shared

Modified:
    myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ClassUtils.java

Modified: myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ClassUtils.java?rev=1003669&r1=1003668&r2=1003669&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ClassUtils.java
(original)
+++ myfaces/commons/trunk/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ClassUtils.java
Fri Oct  1 22:08:16 2010
@@ -27,6 +27,9 @@ import javax.el.ExpressionFactory;
 import java.io.InputStream;
 import java.io.IOException;
 import java.lang.reflect.Array;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.*;
 
 
@@ -131,7 +134,7 @@ public final class ClassUtils
             // Try WebApp ClassLoader first
             return Class.forName(type,
                                  false, // do not initialize for faster startup
-                                 Thread.currentThread().getContextClassLoader());
+                                 getContextClassLoader());
         }
         catch (ClassNotFoundException ignore)
         {
@@ -223,7 +226,7 @@ public final class ClassUtils
 
     public static InputStream getResourceAsStream(String resource)
     {
-        InputStream stream = Thread.currentThread().getContextClassLoader()
+        InputStream stream = getContextClassLoader()
                                 .getResourceAsStream(resource);
         if (stream == null)
         {
@@ -343,11 +346,43 @@ public final class ClassUtils
      */
     protected static ClassLoader getCurrentLoader(Object defaultObject)
     {
-        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        ClassLoader loader = getContextClassLoader();
         if(loader == null)
         {
             loader = defaultObject.getClass().getClassLoader();
         }
         return loader;
     }
+    
+    /**
+     * Gets the ClassLoader associated with the current thread.  Includes a check for priviledges

+     * against java2 security to ensure no security related exceptions are encountered. 
+     *
+     * @since 1.0.1
+     * @return ClassLoader
+     */
+    public static ClassLoader getContextClassLoader()
+    {
+        if (System.getSecurityManager() != null) 
+        {
+            try {
+                ClassLoader cl = AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+                        {
+                            public ClassLoader run() throws PrivilegedActionException
+                            {
+                                return Thread.currentThread().getContextClassLoader();
+                            }
+                        });
+                return cl;
+            }
+            catch (PrivilegedActionException pae)
+            {
+                throw new FacesException(pae);
+            }
+        }
+        else
+        {
+            return Thread.currentThread().getContextClassLoader();
+        }
+    }
 }



Mime
View raw message