SecureAction was not caching the correct context; make sure we exclude
others from the call stack by using a privileged block. (FELIX-1285)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@789915 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java b/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
index 08e4810..7f87913 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
@@ -56,7 +56,23 @@
 
     public SecureAction()
     {
-        m_acc = AccessController.getContext();
+        if (System.getSecurityManager() != null)
+        {
+            try
+            {
+                Actions actions = (Actions) m_actions.get();
+                actions.set(Actions.INITIALIZE_CONTEXT, null);
+                m_acc = (AccessControlContext) AccessController.doPrivileged(actions);
+            }
+            catch (PrivilegedActionException ex)
+            {
+                throw (RuntimeException) ex.getException();
+            }
+        }
+        else
+        {
+            m_acc = AccessController.getContext();
+        }
     }
 
     public String getSystemProperty(String name, String def)
@@ -947,6 +963,8 @@
 
     private static class Actions implements PrivilegedExceptionAction
     {
+        public static final int INITIALIZE_CONTEXT = 0;
+
         public static final int ADD_EXTENSION_URL = 1;
         public static final int CREATE_MODULECLASSLOADER_ACTION = 2;
         public static final int CREATE_TMPFILE_ACTION = 3;
@@ -1054,7 +1072,11 @@
 
             unset();
 
-            if (action == GET_PROPERTY_ACTION)
+            if (action == INITIALIZE_CONTEXT)
+            {
+                return AccessController.getContext();
+            }
+            else if (action == GET_PROPERTY_ACTION)
             {
                 return System.getProperty((String) arg1, (String) arg2);
             }