Search in sources :

Example 1 with PermissionAdmin

use of org.osgi.service.permissionadmin.PermissionAdmin in project aries by apache.

the class PermissionAdminMBeanTest method testMBeanInterface.

@Test
public void testMBeanInterface() throws IOException {
    PermissionAdminMBean mBean = getMBean(PermissionAdminMBean.OBJECTNAME, PermissionAdminMBean.class);
    PermissionAdmin permAdminService = context().getService(PermissionAdmin.class);
    assertNotNull(permAdminService);
    String[] serviceLocation = permAdminService.getLocations();
    String[] mBeanLocations = mBean.listLocations();
    assertArrayEquals(serviceLocation, mBeanLocations);
    PermissionInfo defPerm = new PermissionInfo("AllPermission", "*", "*");
    permAdminService.setDefaultPermissions(new PermissionInfo[] { defPerm });
    PermissionInfo[] permissions = permAdminService.getDefaultPermissions();
    assertNotNull(permissions);
    String[] encoded = toEncodedPerm(permissions);
    String[] mBeanDefPermissions = mBean.listDefaultPermissions();
    assertArrayEquals(encoded, mBeanDefPermissions);
    Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
    assertNotNull(a);
    String location = a.getLocation();
    PermissionInfo bundleaPerm = new PermissionInfo("ServicePermission", "ServiceA", "GET");
    mBean.setPermissions(location, new String[] { bundleaPerm.getEncoded() });
    String[] serviceBundleaPerm = toEncodedPerm(permAdminService.getPermissions(location));
    String[] mBeanBundleaPerm = mBean.getPermissions(location);
    assertNotNull(mBeanBundleaPerm);
    assertArrayEquals(serviceBundleaPerm, mBeanBundleaPerm);
    PermissionInfo defaultPerm = new PermissionInfo("AllPermission", "*", "GET");
    mBean.setDefaultPermissions(new String[] { defaultPerm.getEncoded() });
    String[] serviceDefaultPerm = toEncodedPerm(permAdminService.getDefaultPermissions());
    String[] mBeanDefaultPerm = mBean.listDefaultPermissions();
    assertNotNull(mBeanDefaultPerm);
    assertArrayEquals(serviceDefaultPerm, mBeanDefaultPerm);
}
Also used : PermissionInfo(org.osgi.service.permissionadmin.PermissionInfo) Bundle(org.osgi.framework.Bundle) PermissionAdminMBean(org.osgi.jmx.service.permissionadmin.PermissionAdminMBean) PermissionAdmin(org.osgi.service.permissionadmin.PermissionAdmin) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 2 with PermissionAdmin

use of org.osgi.service.permissionadmin.PermissionAdmin in project bnd by bndtools.

the class SimplePermissionPolicy method setPermissions.

/**
	 * Sets the permissions of a bundle from a resource, if exists.
	 */
public void setPermissions(Bundle bundle) {
    PermissionAdmin permissionAdmin = getPermissionAdmin();
    if (permissionAdmin == null) /* no permission admin service */
    {
        return;
    }
    PermissionInfo[] info = getPermissions(bundle);
    if (info == null) {
        launcher.trace("Using default permissions for %s", bundle.getLocation());
        info = defaultPermissions;
    } else
        launcher.trace("For permissions inside bundle %s", bundle.getLocation());
    if (info != null && info.length > 0) {
        bundles.add(bundle);
        permissionAdmin.setPermissions(bundle.getLocation(), info);
    } else
        launcher.trace("No permissions for %s", bundle.getLocation());
}
Also used : PermissionInfo(org.osgi.service.permissionadmin.PermissionInfo) PermissionAdmin(org.osgi.service.permissionadmin.PermissionAdmin)

Aggregations

PermissionAdmin (org.osgi.service.permissionadmin.PermissionAdmin)2 PermissionInfo (org.osgi.service.permissionadmin.PermissionInfo)2 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 PermissionAdminMBean (org.osgi.jmx.service.permissionadmin.PermissionAdminMBean)1