Search in sources :

Example 1 with AdminPermission

use of org.osgi.framework.AdminPermission in project aries by apache.

the class ServiceRegistryContext method lookup.

public Object lookup(Name name) throws NamingException {
    Object result;
    OsgiName validName = convert(name);
    String pathFragment = validName.getSchemePath();
    String schemeName = validName.getScheme();
    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;
            } catch (AccessControlException accessControlException) {
                NamingException namingException = new NameNotFoundException(MESSAGES.getMessage("caller.not.priviledged"));
                namingException.setRootCause(accessControlException);
                throw namingException;
            }
        } 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));
        } else if (OsgiName.SERVICE_LIST_PATH.equals(pathFragment)) {
            result = new ServiceRegistryListContext(callerContext, env, validName);
        } else {
            result = null;
        }
    } else {
        result = new ServiceRegistryContext(callerContext, validName, env);
    }
    if (result == null) {
        throw new NameNotFoundException(name.toString());
    }
    return result;
}
Also used : AdminPermission(org.osgi.framework.AdminPermission) NameNotFoundException(javax.naming.NameNotFoundException) AccessControlException(java.security.AccessControlException) NamingException(javax.naming.NamingException)

Example 2 with AdminPermission

use of org.osgi.framework.AdminPermission in project logging-log4j2 by apache.

the class Activator method loadProvider.

private void loadProvider(final Bundle bundle) {
    if (bundle.getState() == Bundle.UNINSTALLED) {
        return;
    }
    try {
        checkPermission(new AdminPermission(bundle, AdminPermission.RESOURCE));
        checkPermission(new AdaptPermission(BundleWiring.class.getName(), bundle, AdaptPermission.ADAPT));
        loadProvider(bundle.adapt(BundleWiring.class));
    } catch (final SecurityException e) {
        LOGGER.debug("Cannot access bundle [{}] contents. Ignoring.", bundle.getSymbolicName(), e);
    } catch (final Exception e) {
        LOGGER.warn("Problem checking bundle {} for Log4j 2 provider.", bundle.getSymbolicName(), e);
    }
}
Also used : AdminPermission(org.osgi.framework.AdminPermission) BundleWiring(org.osgi.framework.wiring.BundleWiring) AdaptPermission(org.osgi.framework.AdaptPermission)

Aggregations

AdminPermission (org.osgi.framework.AdminPermission)2 AccessControlException (java.security.AccessControlException)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NamingException (javax.naming.NamingException)1 AdaptPermission (org.osgi.framework.AdaptPermission)1 BundleWiring (org.osgi.framework.wiring.BundleWiring)1