Вопрос

I am trying to use conditional permissions in my application, running in Karaf. The code is an excerpt from the book OSGi in Action (see the full policy example) and boils down to:

ConditionalPermissionAdmin permAdmin = getConditionalPermissionAdmin(context);
ConditionalPermissionUpdate update = permAdmin.newConditionalPermissionUpdate();
List infos = update.getConditionalPermissionInfos();
infos.clear();

infos.add(permAdmin.newConditionalPermissionInfo(
        "All permissions",
        new ConditionInfo[]{
            new ConditionInfo(
            BundleLocationCondition.class.getName(),
            new String[]{FrameworkUtil.getBundle(this.getClass()).getLocation()})
        },
        new PermissionInfo[]{
            new PermissionInfo(AllPermission.class.getName(), "*", "*")
        },
        ConditionalPermissionInfo.ALLOW));
update.commit();

However, no ConditionalPermissionAdmin service seems to be registered by Karaf, as I get a null ServiceReference when looking for it.

Is there a problem with the Karaf security layer? How do I activate it?

Это было полезно?

Решение

there's nothing wrong with Karaf, as you most likely are using Karaf out of the Box you most likely are also using the Felix Framework. For Felix you'll need to deploy the extra org/apache/felix/org.apache.felix.security/1.4.0/ org.apache.felix.framework.security-1.4.0.jar=1. (most likely a newer version is also needed ;-) ) Equinox comes with this already enabled. See more at my blog

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top