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);
}
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());
}
Aggregations