use of org.osgi.service.permissionadmin.PermissionInfo 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.PermissionInfo in project aries by apache.
the class PermissionAdminMBeanTest method toEncodedPerm.
private String[] toEncodedPerm(PermissionInfo[] permissions) {
assertNotNull(permissions);
String[] encoded = new String[permissions.length];
for (int i = 0; i < permissions.length; i++) {
PermissionInfo info = permissions[i];
encoded[i] = info.getEncoded();
}
return encoded;
}
use of org.osgi.service.permissionadmin.PermissionInfo in project aries by apache.
the class PermissionAdminTest method testSetPermissions.
@Test
public void testSetPermissions() throws IOException {
PermissionInfo info1 = new PermissionInfo("Admin", "test", "set");
PermissionInfo info2 = new PermissionInfo("Admin", "test2", "set");
PermissionInfo[] permInfos = new PermissionInfo[] { info1, info2 };
String[] encodedPermissions = new String[2];
int i = 0;
for (PermissionInfo info : permInfos) {
encodedPermissions[i++] = info.getEncoded();
}
mbean.setPermissions("test", encodedPermissions);
Mockito.verify(permAdmin).setPermissions("test", permInfos);
}
use of org.osgi.service.permissionadmin.PermissionInfo in project aries by apache.
the class PermissionAdminTest method testGetPermissions.
@Test
public void testGetPermissions() throws IOException {
PermissionInfo info = new PermissionInfo("Admin", "test", "get");
PermissionInfo[] permInfos = new PermissionInfo[] { info, info };
Mockito.when(permAdmin.getPermissions(Mockito.anyString())).thenReturn(permInfos);
String[] permissions = mbean.getPermissions("test");
Assert.assertNotNull(permissions);
Assert.assertEquals(2, permissions.length);
Assert.assertArrayEquals("Checks encoded permissions", new String[] { info.getEncoded(), info.getEncoded() }, permissions);
Mockito.reset(permAdmin);
Mockito.when(permAdmin.getPermissions(Mockito.anyString())).thenReturn(null);
String[] permissions2 = mbean.getPermissions("test");
Assert.assertNull(permissions2);
}
use of org.osgi.service.permissionadmin.PermissionInfo in project aries by apache.
the class PermissionAdmin method getPermissions.
/**
* @see org.osgi.jmx.service.permissionadmin.PermissionAdminMBean#getPermissions(java.lang.String)
*/
public String[] getPermissions(String location) throws IOException {
if (location == null) {
throw new IOException("Location cannot be null");
}
PermissionInfo[] permissions = permAdmin.getPermissions(location);
if (permissions != null) {
String[] encoded = new String[permissions.length];
for (int i = 0; i < permissions.length; i++) {
PermissionInfo info = permissions[i];
encoded[i] = info.getEncoded();
}
return encoded;
}
return null;
}
Aggregations