Have wiring use protection domain from revision, rename security context
to protection domain. (FELIX-2950)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1126730 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 6609b42..3d7196b 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -1118,7 +1118,7 @@
 
         // Set protection domain after adding the revision to the bundle,
         // since this requires that the bundle has a revision.
-        ((BundleRevisionImpl) revision).setSecurityContext(
+        ((BundleRevisionImpl) revision).setProtectionDomain(
             new BundleProtectionDomain(getFramework(), this));
 
         SecurityProvider sp = getFramework().getSecurityProvider();
@@ -1128,7 +1128,7 @@
             {
                 sp.checkBundle(this);
             }
-            catch (Exception ex) 
+            catch (Exception ex)
             {
                 m_revisions.remove(m_revisions.size() - 1);
                 throw ex;
@@ -1201,7 +1201,7 @@
         for (int i = m_revisions.size() - 1; (i >= 0) && (pd == null); i--)
         {
             pd = (ProtectionDomain)
-                ((BundleRevisionImpl) m_revisions.get(i)).getSecurityContext();
+                ((BundleRevisionImpl) m_revisions.get(i)).getProtectionDomain();
         }
 
         return pd;
@@ -1248,7 +1248,7 @@
         }
     }
 
-    BundleContext _getBundleContext() 
+    BundleContext _getBundleContext()
     {
         return m_context;
     }
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
index f56e3de..fbd016b 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -154,6 +154,11 @@
         m_isExtension = mp.isExtension();
     }
 
+    static SecureAction getSecureAction()
+    {
+        return m_secureAction;
+    }
+
     int getDeclaredActivationPolicy()
     {
         return m_declaredActivationPolicy;
@@ -334,12 +339,12 @@
         }
     }
 
-    public synchronized void setSecurityContext(Object securityContext)
+    public synchronized void setProtectionDomain(ProtectionDomain pd)
     {
-        m_protectionDomain = (ProtectionDomain) securityContext;
+        m_protectionDomain = pd;
     }
 
-    public synchronized Object getSecurityContext()
+    public synchronized ProtectionDomain getProtectionDomain()
     {
         return m_protectionDomain;
     }
@@ -384,7 +389,7 @@
     {
         List<Content> contentList = new ArrayList();
         calculateContentPath(this, getContent(), contentList, true);
-        
+
         List<BundleRevision> fragments = null;
         List<Content> fragmentContents = null;
         if (m_wiring != null)
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
index dd263db..73722d1 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -84,8 +84,6 @@
 
     private BundleClassLoader m_classLoader;
     private boolean m_isActivationTriggered = false;
-    private ProtectionDomain m_protectionDomain = null;
-    private final static SecureAction m_secureAction = new SecureAction();
 
     // Bundle-specific class loader for boot delegation.
     private final ClassLoader m_bootClassLoader;
@@ -98,10 +96,11 @@
         ClassLoader cl = null;
         try
         {
-            Constructor ctor = m_secureAction.getDeclaredConstructor(
+            Constructor ctor = BundleRevisionImpl.getSecureAction().getDeclaredConstructor(
                 SecureClassLoader.class, new Class[] { ClassLoader.class });
-            m_secureAction.setAccesssible(ctor);
-            cl = (ClassLoader) m_secureAction.invoke(ctor, new Object[] { null });
+            BundleRevisionImpl.getSecureAction().setAccesssible(ctor);
+            cl = (ClassLoader) BundleRevisionImpl.getSecureAction().invoke(
+                ctor, new Object[] { null });
         }
         catch (Throwable ex)
         {
@@ -417,10 +416,10 @@
             // enabled; otherwise, create it directly.
             try
             {
-                Constructor ctor = (Constructor) m_secureAction.getConstructor(
-                    clazz, new Class[] { BundleWiringImpl.class, ClassLoader.class });
+                Constructor ctor = (Constructor) BundleRevisionImpl.getSecureAction()
+                    .getConstructor(clazz, new Class[] { BundleWiringImpl.class, ClassLoader.class });
                 m_classLoader = (BundleClassLoader)
-                    m_secureAction.invoke(ctor,
+                    BundleRevisionImpl.getSecureAction().invoke(ctor,
                     new Object[] { this, determineParentClassLoader() });
             }
             catch (Exception ex)
@@ -463,7 +462,7 @@
 
         try
         {
-            return m_secureAction.createURL(null,
+            return BundleRevisionImpl.getSecureAction().createURL(null,
                 FelixConstants.BUNDLE_URL_PROTOCOL + "://" +
                 m_revision.getId() + ":" + port + path, m_revision.getURLStreamHandler());
         }
@@ -639,22 +638,24 @@
         final ClassLoader parent;
         if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_APP))
         {
-            parent = m_secureAction.getSystemClassLoader();
+            parent = BundleRevisionImpl.getSecureAction().getSystemClassLoader();
         }
         else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_EXT))
         {
-            parent = m_secureAction.getParentClassLoader(m_secureAction.getSystemClassLoader());
+            parent = BundleRevisionImpl.getSecureAction().getParentClassLoader(
+                BundleRevisionImpl.getSecureAction().getSystemClassLoader());
         }
         else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK))
         {
-            parent = m_secureAction.getClassLoader(BundleRevisionImpl.class);
+            parent = BundleRevisionImpl.getSecureAction()
+                .getClassLoader(BundleRevisionImpl.class);
         }
         // On Android we cannot set the parent class loader to be null, so
         // we special case that situation here and set it to the system
         // class loader by default instead, which is not really spec.
         else if (m_bootClassLoader == null)
         {
-            parent = m_secureAction.getSystemClassLoader();
+            parent = BundleRevisionImpl.getSecureAction().getSystemClassLoader();
         }
         else
         {
@@ -732,12 +733,12 @@
 
             try
             {
-                dexFileClassLoadDex = dexFileClass.getMethod("loadDex", 
+                dexFileClassLoadDex = dexFileClass.getMethod("loadDex",
                     new Class[]{String.class, String.class, Integer.TYPE});
             }
             catch (Exception ex)
             {
-                // Nothing we need to do 
+                // Nothing we need to do
             }
             dexFileClassConstructor = dexFileClass.getConstructor(
                 new Class[] { java.io.File.class });
@@ -1105,8 +1106,10 @@
                 {
                     // Return the class or resource from the parent class loader.
                     return (isClass)
-                        ? (Object) m_secureAction.getClassLoader(this.getClass()).loadClass(name)
-                        : (Object) m_secureAction.getClassLoader(this.getClass()).getResource(name);
+                        ? (Object) BundleRevisionImpl.getSecureAction()
+                            .getClassLoader(this.getClass()).loadClass(name)
+                        : (Object) BundleRevisionImpl.getSecureAction()
+                            .getClassLoader(this.getClass()).getResource(name);
                 }
                 catch (NoClassDefFoundError ex)
                 {
@@ -1123,7 +1126,8 @@
     {
         // The target class is loaded by a bundle class loader,
         // then return true.
-        if (BundleClassLoader.class.isInstance(m_secureAction.getClassLoader(clazz)))
+        if (BundleClassLoader.class.isInstance(
+            BundleRevisionImpl.getSecureAction().getClassLoader(clazz)))
         {
             return true;
         }
@@ -1131,9 +1135,9 @@
         // If the target class was loaded from a class loader that
         // came from a bundle, then return true.
         ClassLoader last = null;
-        for (ClassLoader cl = m_secureAction.getClassLoader(clazz);
+        for (ClassLoader cl = BundleRevisionImpl.getSecureAction().getClassLoader(clazz);
             (cl != null) && (last != cl);
-            cl = m_secureAction.getClassLoader(cl.getClass()))
+            cl = BundleRevisionImpl.getSecureAction().getClassLoader(cl.getClass()))
         {
             last = cl;
             if (BundleClassLoader.class.isInstance(cl))
@@ -1341,7 +1345,7 @@
 
                         if (clazz == null)
                         {
-                            int activationPolicy = 
+                            int activationPolicy =
                                 ((BundleImpl) getBundle()).isDeclaredActivationPolicyUsed()
                                 ? ((BundleRevisionImpl) ((BundleImpl) getBundle())
                                     .getCurrentRevision()).getDeclaredActivationPolicy()
@@ -1413,10 +1417,10 @@
                                 // If we have a security context, then use it to
                                 // define the class with it for security purposes,
                                 // otherwise define the class without a protection domain.
-                                if (m_protectionDomain != null)
+                                if (m_revision.getProtectionDomain() != null)
                                 {
                                     clazz = defineClass(name, bytes, 0, bytes.length,
-                                        m_protectionDomain);
+                                        m_revision.getProtectionDomain());
                                 }
                                 else
                                 {
@@ -1499,8 +1503,8 @@
                 {
                     if (m_dexFileClassLoadDex != null)
                     {
-                        dexFile = m_dexFileClassLoadDex.invoke(null, 
-                            new Object[]{content.getFile().getAbsolutePath(), 
+                        dexFile = m_dexFileClassLoadDex.invoke(null,
+                            new Object[]{content.getFile().getAbsolutePath(),
                                 content.getFile().getAbsolutePath() + ".dex", new Integer(0)});
                     }
                     else
@@ -1807,7 +1811,8 @@
             boolean classpath = false;
             try
             {
-                m_secureAction.getClassLoader(BundleClassLoader.class).loadClass(name);
+                BundleRevisionImpl.getSecureAction()
+                    .getClassLoader(BundleClassLoader.class).loadClass(name);
                 classpath = true;
             }
             catch (NoClassDefFoundError err)
@@ -1860,7 +1865,8 @@
         // class loader.
         try
         {
-            m_secureAction.getClassLoader(BundleClassLoader.class).loadClass(name);
+            BundleRevisionImpl.getSecureAction()
+                .getClassLoader(BundleClassLoader.class).loadClass(name);
 
             StringBuffer sb = new StringBuffer("*** Package '");
             sb.append(pkgName);
diff --git a/framework/src/main/java/org/apache/felix/framework/ResolverStateImpl.java b/framework/src/main/java/org/apache/felix/framework/ResolverStateImpl.java
index 6d983c9..a663de5 100644
--- a/framework/src/main/java/org/apache/felix/framework/ResolverStateImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ResolverStateImpl.java
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -194,11 +194,11 @@
                 if (System.getSecurityManager() != null)
                 {
                     if (req.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) && (
-                        !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getSecurityContext()).impliesDirect(
+                        !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getProtectionDomain()).impliesDirect(
                             new PackagePermission((String) cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR),
                             PackagePermission.EXPORTONLY)) ||
                             !((reqRevision == null) ||
-                                ((BundleProtectionDomain) reqRevision.getSecurityContext()).impliesDirect(
+                                ((BundleProtectionDomain) reqRevision.getProtectionDomain()).impliesDirect(
                                     new PackagePermission((String) cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR),
                                     cap.getRevision().getBundle(),PackagePermission.IMPORT))
                             )))
@@ -209,21 +209,21 @@
                         }
                     }
                     else if (req.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE) && (
-                        !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getSecurityContext()).impliesDirect(
+                        !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getProtectionDomain()).impliesDirect(
                             new BundlePermission(cap.getRevision().getSymbolicName(), BundlePermission.PROVIDE)) ||
                             !((reqRevision == null) ||
-                                ((BundleProtectionDomain) reqRevision.getSecurityContext()).impliesDirect(
+                                ((BundleProtectionDomain) reqRevision.getProtectionDomain()).impliesDirect(
                                     new BundlePermission(reqRevision.getSymbolicName(), BundlePermission.REQUIRE))
                             )))
                     {
                         continue;
                     }
                     else if (req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE) &&
-                        (!((BundleProtectionDomain) reqRevision.getSecurityContext())
+                        (!((BundleProtectionDomain) reqRevision.getProtectionDomain())
                             .impliesDirect(new BundlePermission(
                                 reqRevision.getSymbolicName(),
                                 BundlePermission.FRAGMENT))
-                        || !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getSecurityContext())
+                        || !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getProtectionDomain())
                             .impliesDirect(new BundlePermission(
                                 cap.getRevision().getSymbolicName(),
                                 BundlePermission.HOST))))