You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2018/02/21 10:26:08 UTC

svn commit: r1824953 - /aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java

Author: gnodet
Date: Wed Feb 21 10:26:08 2018
New Revision: 1824953

URL: http://svn.apache.org/viewvc?rev=1824953&view=rev
Log:
[ARIES-916] Lookup of System BundleContext via JNDI causes AccessControlException

Modified:
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java?rev=1824953&r1=1824952&r2=1824953&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java Wed Feb 21 10:26:08 2018
@@ -79,16 +79,19 @@ public class ServiceRegistryContext exte
 
         if (validName.hasInterface()) {
             if (OsgiName.FRAMEWORK_PATH.equals(pathFragment) && "bundleContext".equals(validName.getServiceName())) {
-                AdminPermission adminPermission =
-                        new AdminPermission(callerContext.getBundle(), AdminPermission.CONTEXT);
                 try {
-                    AccessController.checkPermission(adminPermission);
-                    return callerContext;
+                    SecurityManager sm = System.getSecurityManager();
+                    if (sm != null) {
+                        AdminPermission adminPermission =
+                                new AdminPermission(callerContext.getBundle(), AdminPermission.CONTEXT);
+                        sm.checkPermission(adminPermission);
+                    }
                 } catch (AccessControlException accessControlException) {
                     NamingException namingException = new NameNotFoundException("The Caller does not have permissions to get the BundleContext.");
                     namingException.setRootCause(accessControlException);
                     throw namingException;
                 }
+                return callerContext;
             } else if ((OsgiName.SERVICE_PATH.equals(pathFragment) && OsgiName.OSGI_SCHEME.equals(schemeName))
                     || (OsgiName.SERVICES_PATH.equals(pathFragment) && OsgiName.ARIES_SCHEME.equals(schemeName))) {
                 result = ServiceHelper.getService(callerContext, validName, null, true, env, OsgiName.OSGI_SCHEME.equals(schemeName));