You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/07/31 04:33:28 UTC

svn commit: r799494 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: ModuleImpl.java util/SecureAction.java

Author: rickhall
Date: Fri Jul 31 02:33:27 2009
New Revision: 799494

URL: http://svn.apache.org/viewvc?rev=799494&view=rev
Log:
Get class loaders inside privileged block. (FELIX-1193)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java?rev=799494&r1=799493&r2=799494&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java Fri Jul 31 02:33:27 2009
@@ -1275,11 +1275,11 @@
             final ClassLoader parent;
             if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_APP))
             {
-                parent = ClassLoader.getSystemClassLoader();
+                parent = m_secureAction.getSystemClassLoader();
             }
             else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_EXT))
             {
-                parent = ClassLoader.getSystemClassLoader().getParent();
+                parent = m_secureAction.getSystemClassLoader().getParent();
             }
             else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK))
             {
@@ -1290,7 +1290,7 @@
             // class loader by default instead, which is not really spec.
             else if (m_bootClassLoader == null)
             {
-                parent = ClassLoader.getSystemClassLoader();
+                parent = m_secureAction.getSystemClassLoader();
             }
             else
             {

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java?rev=799494&r1=799493&r2=799494&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java Fri Jul 31 02:33:27 2009
@@ -96,6 +96,48 @@
         }
     }
 
+    public ClassLoader getParentClassLoader(ClassLoader loader)
+    {
+        if (System.getSecurityManager() != null)
+        {
+            try
+            {
+                Actions actions = (Actions) m_actions.get();
+                actions.set(Actions.GET_PARENT_CLASS_LOADER_ACTION, loader);
+                return (ClassLoader) AccessController.doPrivileged(actions, m_acc);
+            }
+            catch (PrivilegedActionException ex)
+            {
+                throw (RuntimeException) ex.getException();
+            }
+        }
+        else
+        {
+            return loader.getParent();
+        }
+    }
+
+    public ClassLoader getSystemClassLoader()
+    {
+        if (System.getSecurityManager() != null)
+        {
+            try
+            {
+                Actions actions = (Actions) m_actions.get();
+                actions.set(Actions.GET_SYSTEM_CLASS_LOADER_ACTION);
+                return (ClassLoader) AccessController.doPrivileged(actions, m_acc);
+            }
+            catch (PrivilegedActionException ex)
+            {
+                throw (RuntimeException) ex.getException();
+            }
+        }
+        else
+        {
+            return ClassLoader.getSystemClassLoader();
+        }
+    }
+
     public Class forName(String name) throws ClassNotFoundException
     {
         if (System.getSecurityManager() != null)
@@ -1007,22 +1049,24 @@
         public static final int GET_METHOD_ACTION = 19;
         public static final int GET_POLICY_ACTION = 20;
         public static final int GET_PROPERTY_ACTION = 21;
-        public static final int GET_URL_INPUT_ACTION = 22;
-        public static final int INVOKE_CONSTRUCTOR_ACTION = 23;
-        public static final int INVOKE_DIRECTMETHOD_ACTION = 24;
-        public static final int INVOKE_METHOD_ACTION = 25;
-        public static final int LIST_DIRECTORY_ACTION = 26;
-        public static final int MAKE_DIRECTORIES_ACTION = 27;
-        public static final int MAKE_DIRECTORY_ACTION = 28;
-        public static final int OPEN_JARX_ACTION = 29;
-        public static final int OPEN_JARX_VERIFY_ACTION = 30;
-        public static final int OPEN_URLCONNECTION_ACTION = 31;
-        public static final int RENAME_FILE_ACTION = 32;
-        public static final int SET_ACCESSIBLE_ACTION = 33;
-        public static final int START_ACTIVATOR_ACTION = 34;
-        public static final int STOP_ACTIVATOR_ACTION = 35;
-        public static final int SWAP_FIELD_ACTION = 36;
-        public static final int SYSTEM_EXIT_ACTION = 37;
+        public static final int GET_PARENT_CLASS_LOADER_ACTION = 22;
+        public static final int GET_SYSTEM_CLASS_LOADER_ACTION = 23;
+        public static final int GET_URL_INPUT_ACTION = 24;
+        public static final int INVOKE_CONSTRUCTOR_ACTION = 25;
+        public static final int INVOKE_DIRECTMETHOD_ACTION = 26;
+        public static final int INVOKE_METHOD_ACTION = 27;
+        public static final int LIST_DIRECTORY_ACTION = 28;
+        public static final int MAKE_DIRECTORIES_ACTION = 29;
+        public static final int MAKE_DIRECTORY_ACTION = 30;
+        public static final int OPEN_JARX_ACTION = 31;
+        public static final int OPEN_JARX_VERIFY_ACTION = 32;
+        public static final int OPEN_URLCONNECTION_ACTION = 33;
+        public static final int RENAME_FILE_ACTION = 34;
+        public static final int SET_ACCESSIBLE_ACTION = 35;
+        public static final int START_ACTIVATOR_ACTION = 36;
+        public static final int STOP_ACTIVATOR_ACTION = 37;
+        public static final int SWAP_FIELD_ACTION = 38;
+        public static final int SYSTEM_EXIT_ACTION = 39;
 
         private int m_action = -1;
         private Object m_arg1 = null;
@@ -1031,6 +1075,11 @@
         private Object m_arg4 = null;
         private Object m_arg5 = null;
 
+        public void set(int action)
+        {
+            m_action = action;
+        }
+
         public void set(int action, Object arg1)
         {
             m_action = action;
@@ -1102,6 +1151,14 @@
             {
                 return System.getProperty((String) arg1, (String) arg2);
             }
+            else if (action == GET_PARENT_CLASS_LOADER_ACTION)
+            {
+                return ((ClassLoader) arg1).getParent();
+            }
+            else if (action == GET_SYSTEM_CLASS_LOADER_ACTION)
+            {
+                return ClassLoader.getSystemClassLoader();
+            }
             else if (action == FOR_NAME_ACTION)
             {
                 return Class.forName((String) arg1);