use of org.osgi.service.permissionadmin.PermissionInfo in project aries by apache.
the class PermissionAdminTest method testSetDefaultPermissions.
@Test
public void testSetDefaultPermissions() throws IOException {
PermissionInfo info1 = new PermissionInfo("Admin", "test", "get");
PermissionInfo info2 = new PermissionInfo("Admin", "test2", "get");
PermissionInfo[] permInfos = new PermissionInfo[] { info1, info2 };
String[] encodedPermissions = new String[2];
int i = 0;
for (PermissionInfo info : permInfos) {
encodedPermissions[i++] = info.getEncoded();
}
mbean.setDefaultPermissions(encodedPermissions);
Mockito.verify(permAdmin).setDefaultPermissions(permInfos);
}
use of org.osgi.service.permissionadmin.PermissionInfo in project aries by apache.
the class PermissionAdminTest method testListDefaultPermissions.
@Test
public void testListDefaultPermissions() throws IOException {
PermissionInfo info = new PermissionInfo("Admin", "test", "get");
PermissionInfo[] permInfos = new PermissionInfo[] { info, info };
Mockito.when(permAdmin.getDefaultPermissions()).thenReturn(permInfos);
String[] permissions = mbean.listDefaultPermissions();
Assert.assertNotNull(permissions);
Assert.assertEquals(2, permissions.length);
Assert.assertArrayEquals("Checks encoded default permissions", new String[] { info.getEncoded(), info.getEncoded() }, permissions);
Mockito.reset(permAdmin);
Mockito.when(permAdmin.getDefaultPermissions()).thenReturn(null);
String[] permissions2 = mbean.listDefaultPermissions();
Assert.assertNull(permissions2);
}
use of org.osgi.service.permissionadmin.PermissionInfo 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());
}
use of org.osgi.service.permissionadmin.PermissionInfo in project bnd by bndtools.
the class SimplePermissionPolicy method getPermissions.
/**
* Get the resource and parse it into PermissionInfo objects.
*/
public PermissionInfo[] getPermissions(Bundle bundle) {
URL url = bundle.getEntry("/OSGI-INF/permissions.perm");
if (url == null)
url = bundle.getEntry("/OSGI-INF/permissions.perm".toUpperCase());
PermissionInfo[] info = null;
if (url != null)
try {
InputStream in = url.openStream();
info = parse(in);
} catch (IOException e) {
System.err.println("Unable to read permission info for bundle " + bundle.getLocation() + " " + e);
}
return info;
}
Aggregations