Search in sources :

Example 81 with Role

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;
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Set(java.util.Set) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)

Example 82 with Role

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);
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) RoleInfo(org.apache.activemq.artemis.api.core.management.RoleInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RandomUtil.randomString(org.apache.activemq.artemis.tests.util.RandomUtil.randomString) JsonString(javax.json.JsonString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 83 with Role

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);
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 84 with Role

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
        }
    }
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) HashSet(java.util.HashSet) Session(javax.jms.Session) Test(org.junit.Test)

Example 85 with Role

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);
        }
    }
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PathAddress(org.jboss.as.controller.PathAddress)

Aggregations

Role (org.apache.activemq.artemis.core.security.Role)86 HashSet (java.util.HashSet)72 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)49 Test (org.junit.Test)46 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)35 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)33 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)33 Set (java.util.Set)30 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)26 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)24 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)20 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)15 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)14 Before (org.junit.Before)11 Configuration (org.apache.activemq.artemis.core.config.Configuration)9 HashMap (java.util.HashMap)7 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)7 Session (javax.jms.Session)5 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)5 Connection (javax.jms.Connection)4