use of org.apache.activemq.artemis.api.core.management.RoleInfo in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testSecuritySettings.
@Test
public void testSecuritySettings() throws Exception {
ActiveMQServerControl serverControl = createManagementControl();
String addressMatch = "test.#";
String exactAddress = "test.whatever";
assertEquals(1, serverControl.getRoles(addressMatch).length);
serverControl.addSecuritySettings(addressMatch, "foo", "foo, bar", "foo", "bar", "foo, bar", "", "", "bar", "foo", "foo");
// Restart the server. Those settings should be persisted
restartServer();
serverControl = createManagementControl();
String rolesAsJSON = serverControl.getRolesAsJSON(exactAddress);
RoleInfo[] roleInfos = RoleInfo.from(rolesAsJSON);
assertEquals(2, roleInfos.length);
RoleInfo fooRole = null;
RoleInfo barRole = null;
if (roleInfos[0].getName().equals("foo")) {
fooRole = roleInfos[0];
barRole = roleInfos[1];
} else {
fooRole = roleInfos[1];
barRole = roleInfos[0];
}
assertTrue(fooRole.isSend());
assertTrue(fooRole.isConsume());
assertTrue(fooRole.isCreateDurableQueue());
assertFalse(fooRole.isDeleteDurableQueue());
assertTrue(fooRole.isCreateNonDurableQueue());
assertFalse(fooRole.isDeleteNonDurableQueue());
assertFalse(fooRole.isManage());
assertFalse(fooRole.isBrowse());
assertTrue(fooRole.isCreateAddress());
assertFalse(barRole.isSend());
assertTrue(barRole.isConsume());
assertFalse(barRole.isCreateDurableQueue());
assertTrue(barRole.isDeleteDurableQueue());
assertTrue(barRole.isCreateNonDurableQueue());
assertFalse(barRole.isDeleteNonDurableQueue());
assertFalse(barRole.isManage());
assertTrue(barRole.isBrowse());
assertFalse(barRole.isCreateAddress());
serverControl.removeSecuritySettings(addressMatch);
assertEquals(1, serverControl.getRoles(exactAddress).length);
}
use of org.apache.activemq.artemis.api.core.management.RoleInfo in project activemq-artemis by apache.
the class AddressControlTest method testGetRolesAsJSON.
@Test
public void testGetRolesAsJSON() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
Role role = new Role(RandomUtil.randomString(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean(), RandomUtil.randomBoolean());
session.createQueue(address, queue, true);
AddressControl addressControl = createManagementControl(address);
String jsonString = addressControl.getRolesAsJSON();
Assert.assertNotNull(jsonString);
RoleInfo[] roles = RoleInfo.from(jsonString);
Assert.assertEquals(0, roles.length);
Set<Role> newRoles = new HashSet<>();
newRoles.add(role);
server.getSecurityRepository().addMatch(address.toString(), newRoles);
jsonString = addressControl.getRolesAsJSON();
Assert.assertNotNull(jsonString);
roles = RoleInfo.from(jsonString);
Assert.assertEquals(1, roles.length);
RoleInfo r = roles[0];
Assert.assertEquals(role.getName(), roles[0].getName());
Assert.assertEquals(role.isSend(), r.isSend());
Assert.assertEquals(role.isConsume(), r.isConsume());
Assert.assertEquals(role.isCreateDurableQueue(), r.isCreateDurableQueue());
Assert.assertEquals(role.isDeleteDurableQueue(), r.isDeleteDurableQueue());
Assert.assertEquals(role.isCreateNonDurableQueue(), r.isCreateNonDurableQueue());
Assert.assertEquals(role.isDeleteNonDurableQueue(), r.isDeleteNonDurableQueue());
Assert.assertEquals(role.isManage(), r.isManage());
session.deleteQueue(queue);
}
Aggregations