FELIX-1535 check permission against current access control context
instead of the service using bundle

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@808595 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
index 2929284..d5d4517 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
@@ -20,7 +20,6 @@
 
 
 import java.io.IOException;
-
 import org.osgi.framework.Bundle;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
@@ -147,30 +146,38 @@
 
 
     /**
-     * Checks whether the bundle to which this instance has been given has the
-     * <code>CONFIGURE</code> permission and returns <code>true</code> in this
-     * case.
+     * Returns <code>true</code> if the current access control context (call
+     * stack) has the CONFIGURE permission.
      */
     boolean hasPermission()
     {
-        return bundle.hasPermission( new ConfigurationPermission( "*", ConfigurationPermission.CONFIGURE ) );
+        try
+        {
+            checkPermission();
+            return true;
+        }
+        catch ( SecurityException se )
+        {
+            return false;
+        }
     }
 
 
     /**
-     * Checks whether the bundle to which this instance has been given has the
-     * <code>CONFIGURE</code> permission and throws a <code>SecurityException</code>
-     * if this is not the case.
+     * Checks whether the current access control context (call stack) has the
+     * <code>CONFIGURE</code> permission and throws a
+     * <code>SecurityException</code> if this is not the case.
      *
-     * @throws SecurityException if the bundle to which this instance belongs
-     *      does not have the <code>CONFIGURE</code> permission.
+     * @throws SecurityException if the access control context does not have the
+     *             <code>CONFIGURE</code> permission.
      */
     void checkPermission()
     {
-        if ( !this.hasPermission() )
+        // the caller's permission must be checked
+        final SecurityManager sm = System.getSecurityManager();
+        if ( sm != null )
         {
-            throw new SecurityException( "Bundle " + bundle.getSymbolicName()
-                + " not permitted for Configuration Tasks" );
+            sm.checkPermission( new ConfigurationPermission( "*", ConfigurationPermission.CONFIGURE ) );
         }
     }