use of org.apache.activemq.artemis.core.security.Role in project activemq-artemis by apache.
the class SecurityManagementWithConfiguredAdminUserTest method setupAndStartActiveMQServer.
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
protected ActiveMQServer setupAndStartActiveMQServer() throws Exception {
Configuration config = createDefaultInVMConfig().setSecurityEnabled(true);
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
server.start();
HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
securityManager.getConfiguration().addUser(validAdminUser, validAdminPassword);
securityManager.getConfiguration().addUser(invalidAdminUser, invalidAdminPassword);
securityManager.getConfiguration().addRole(validAdminUser, "admin");
securityManager.getConfiguration().addRole(validAdminUser, "guest");
securityManager.getConfiguration().addRole(invalidAdminUser, "guest");
Set<Role> adminRole = securityRepository.getMatch(ActiveMQDefaultConfiguration.getDefaultManagementAddress().toString());
adminRole.add(new Role("admin", true, true, true, true, true, true, true, true, true, true));
securityRepository.addMatch(ActiveMQDefaultConfiguration.getDefaultManagementAddress().toString(), adminRole);
Set<Role> guestRole = securityRepository.getMatch("*");
guestRole.add(new Role("guest", true, true, true, true, true, true, false, true, true, true));
securityRepository.addMatch("*", guestRole);
return server;
}
use of org.apache.activemq.artemis.core.security.Role 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);
}
use of org.apache.activemq.artemis.core.security.Role in project activemq-artemis by apache.
the class RepositoryTest method testWithoutWildcard.
@Test
public void testWithoutWildcard() {
securityRepository.addMatch("queues.1.*", new HashSet<Role>());
HashSet<Role> roles = new HashSet<>(2);
roles.add(new Role("test1", true, true, true, true, true, true, true, true, true, true));
roles.add(new Role("test2", true, true, true, true, true, true, true, true, true, true));
securityRepository.addMatch("queues.2.aq", roles);
HashSet<Role> hashSet = securityRepository.getMatch("queues.2.aq");
Assert.assertEquals(hashSet.size(), 2);
}
use of org.apache.activemq.artemis.core.security.Role in project activemq-artemis by apache.
the class SecurityOpenWireTest method testSendNoAuth.
@Test
public void testSendNoAuth() throws Exception {
Set<Role> roles = new HashSet<>();
roles.add(new Role("programmers", false, false, false, false, false, false, false, false, false, false));
server.getSecurityRepository().addMatch("denyQ", roles);
SimpleString denyQ = new SimpleString("denyQ");
server.createQueue(denyQ, RoutingType.ANYCAST, denyQ, null, true, false);
try (Connection connection = factory.createConnection("denyQ", "denyQ")) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("denyQ");
System.out.println("Queue:" + queue);
MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
try {
producer.send(session.createTextMessage());
fail();
} catch (JMSException e) {
// pass
}
}
}
use of org.apache.activemq.artemis.core.security.Role in project wildfly by wildfly.
the class SecurityRoleAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
if (context.isNormalServer()) {
final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
final ActiveMQServer server = getServer(context, operation);
final String match = address.getElement(address.size() - 2).getValue();
final String roleName = address.getLastElement().getValue();
if (server != null) {
final Role role = SecurityRoleDefinition.transform(context, roleName, model);
final Set<Role> roles = server.getSecurityRepository().getMatch(match);
roles.add(role);
server.getSecurityRepository().addMatch(match, roles);
}
}
}
Aggregations