geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r810653 - in /geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence: Persistence.java spi/PersistenceProviderResolverHolder.java
Date Wed, 02 Sep 2009 18:28:37 GMT
Author: dwoods
Date: Wed Sep  2 18:28:37 2009
New Revision: 810653

URL: http://svn.apache.org/viewvc?rev=810653&view=rev
Log:
GERONIMO-4410 Add PrivilegedAction handler for accessing classloaders

Modified:
    geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/Persistence.java
    geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java

Modified: geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/Persistence.java
URL: http://svn.apache.org/viewvc/geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/Persistence.java?rev=810653&r1=810652&r2=810653&view=diff
==============================================================================
--- geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/Persistence.java
(original)
+++ geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/Persistence.java
Wed Sep  2 18:28:37 2009
@@ -24,6 +24,8 @@
 //
 package javax.persistence;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -178,9 +180,12 @@
             throws PersistenceException {
 
         Class<?> providerClass;
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+        // get our class loader
+        ClassLoader cl = PrivClassLoader.get(null);
         if (cl == null)
-            cl = Persistence.class.getClassLoader();
+            cl = PrivClassLoader.get(Persistence.class);
+
         try {
             providerClass = Class.forName(providerName, true, cl);
         } catch (Exception e) {
@@ -284,5 +289,28 @@
                 return true;
             }
     }
-    
+
+    private static class PrivClassLoader implements PrivilegedAction<ClassLoader> {
+        private final Class<?> c;
+
+        public static ClassLoader get(Class<?> c) {
+            final PrivClassLoader action = new PrivClassLoader(c);
+            if (System.getSecurityManager() != null)
+                return AccessController.doPrivileged(action);
+            else
+                return action.run();
+        }
+
+        private PrivClassLoader(Class<?> c) {
+            this.c = c;
+        }
+
+        public ClassLoader run() {
+            if (c != null)
+                return c.getClassLoader();
+            else
+                return Thread.currentThread().getContextClassLoader();
+        }
+    }
 }
+

Modified: geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java?rev=810653&r1=810652&r2=810653&view=diff
==============================================================================
--- geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
(original)
+++ geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA8/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
Wed Sep  2 18:28:37 2009
@@ -30,6 +30,8 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
@@ -81,9 +83,9 @@
             List<PersistenceProvider> providers;
             
             // get our class loader
-            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            ClassLoader cl = PrivClassLoader.get(null);
             if (cl == null)
-                cl = DefaultPersistenceProviderResolver.class.getClassLoader();
+                cl = PrivClassLoader.get(DefaultPersistenceProviderResolver.class);
 
             // use any previously cached providers
             synchronized (providerCache) {
@@ -158,6 +160,29 @@
                 providerCache.clear();
             }
         }
-    }
 
+        private static class PrivClassLoader implements PrivilegedAction<ClassLoader>
{
+            private final Class<?> c;
+
+            public static ClassLoader get(Class<?> c) {
+                final PrivClassLoader action = new PrivClassLoader(c);
+                if (System.getSecurityManager() != null)
+                    return AccessController.doPrivileged(action);
+                else
+                    return action.run();
+            }
+
+            private PrivClassLoader(Class<?> c) {
+                this.c = c;
+            }
+
+            public ClassLoader run() {
+                if (c != null)
+                    return c.getClassLoader();
+                else
+                    return Thread.currentThread().getContextClassLoader();
+            }
+        }
+    }
 }
+



Mime
View raw message