Search in sources :

Example 31 with Role

use of org.apache.activemq.artemis.core.security.Role in project activemq-artemis by apache.

the class SecurityTest method testJAASSecurityManagerAuthorizationSameAddressDifferentQueues.

@Test
public void testJAASSecurityManagerAuthorizationSameAddressDifferentQueues() throws Exception {
    final SimpleString ADDRESS = new SimpleString("address");
    final SimpleString QUEUE_A = new SimpleString("a");
    final SimpleString QUEUE_B = new SimpleString("b");
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
    Set<Role> aRoles = new HashSet<>();
    aRoles.add(new Role(QUEUE_A.toString(), false, true, false, false, false, false, false, false, false, false));
    server.getConfiguration().putSecurityRoles(ADDRESS.concat(".").concat(QUEUE_A).toString(), aRoles);
    Set<Role> bRoles = new HashSet<>();
    bRoles.add(new Role(QUEUE_B.toString(), false, true, false, false, false, false, false, false, false, false));
    server.getConfiguration().putSecurityRoles(ADDRESS.concat(".").concat(QUEUE_B).toString(), bRoles);
    server.start();
    server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    server.createQueue(ADDRESS, RoutingType.ANYCAST, QUEUE_A, null, true, false);
    server.createQueue(ADDRESS, RoutingType.ANYCAST, QUEUE_B, null, true, false);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession aSession = addClientSession(cf.createSession("a", "a", false, true, true, false, 0));
    ClientSession bSession = addClientSession(cf.createSession("b", "b", false, true, true, false, 0));
    // client A CONSUME from queue A
    try {
        ClientConsumer consumer = aSession.createConsumer(QUEUE_A);
    } catch (ActiveMQException e) {
        e.printStackTrace();
        Assert.fail("should not throw exception here");
    }
    // client B CONSUME from queue A
    try {
        ClientConsumer consumer = bSession.createConsumer(QUEUE_A);
        Assert.fail("should throw exception here");
    } catch (ActiveMQException e) {
        assertTrue(e instanceof ActiveMQSecurityException);
    }
    // client B CONSUME from queue B
    try {
        ClientConsumer consumer = bSession.createConsumer(QUEUE_B);
    } catch (ActiveMQException e) {
        e.printStackTrace();
        Assert.fail("should not throw exception here");
    }
    // client A CONSUME from queue B
    try {
        ClientConsumer consumer = aSession.createConsumer(QUEUE_B);
        Assert.fail("should throw exception here");
    } catch (ActiveMQException e) {
        assertTrue(e instanceof ActiveMQSecurityException);
    }
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) HashSet(java.util.HashSet) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 32 with Role

use of org.apache.activemq.artemis.core.security.Role in project activemq-artemis by apache.

the class SecurityTest method testNonBlockSendManagementWithoutRole.

@Test
public void testNonBlockSendManagementWithoutRole() throws Exception {
    ActiveMQServer server = createServer();
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    Role role = new Role("arole", false, false, true, false, false, false, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    securityRepository.addMatch(configuration.getManagementAddress().toString(), roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    session.createQueue(configuration.getManagementAddress().toString(), SecurityTest.queueA, true);
    ClientProducer cp = session.createProducer(configuration.getManagementAddress());
    cp.send(session.createMessage(false));
    session.close();
    Queue binding = (Queue) server.getPostOffice().getBinding(new SimpleString(SecurityTest.queueA)).getBindable();
    Assert.assertEquals(0, getMessageCount(binding));
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Set(java.util.Set) HashSet(java.util.HashSet) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 33 with Role

use of org.apache.activemq.artemis.core.security.Role in project activemq-artemis by apache.

the class SecurityTest method testJAASSecurityManagerAuthorizationPositiveGuest.

@Test
public void testJAASSecurityManagerAuthorizationPositiveGuest() throws Exception {
    final SimpleString ADDRESS = new SimpleString("address");
    final SimpleString DURABLE_QUEUE = new SimpleString("durableQueue");
    final SimpleString NON_DURABLE_QUEUE = new SimpleString("nonDurableQueue");
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("GuestLogin");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
    Set<Role> roles = new HashSet<>();
    roles.add(new Role("bar", true, true, true, true, true, true, true, false, true, true));
    server.getConfiguration().putSecurityRoles("#", roles);
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = addClientSession(cf.createSession("junk", "junk", false, true, true, false, 0));
    // CREATE_DURABLE_QUEUE
    try {
        session.createQueue(ADDRESS, DURABLE_QUEUE, true);
    } catch (ActiveMQException e) {
        e.printStackTrace();
        Assert.fail("should not throw exception here");
    }
    // DELETE_DURABLE_QUEUE
    try {
        session.deleteQueue(DURABLE_QUEUE);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // CREATE_NON_DURABLE_QUEUE
    try {
        session.createQueue(ADDRESS, NON_DURABLE_QUEUE, false);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // DELETE_NON_DURABLE_QUEUE
    try {
        session.deleteQueue(NON_DURABLE_QUEUE);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    session.createQueue(ADDRESS, DURABLE_QUEUE, true);
    // PRODUCE
    try {
        ClientProducer producer = session.createProducer(ADDRESS);
        producer.send(session.createMessage(true));
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // CONSUME
    try {
        session.createConsumer(DURABLE_QUEUE);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // MANAGE
    try {
        ClientProducer producer = session.createProducer(server.getConfiguration().getManagementAddress());
        producer.send(session.createMessage(true));
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with Role

use of org.apache.activemq.artemis.core.security.Role in project activemq-artemis by apache.

the class SecurityTest method testJAASSecurityManagerAuthorizationPositive.

@Test
public void testJAASSecurityManagerAuthorizationPositive() throws Exception {
    final SimpleString ADDRESS = new SimpleString("address");
    final SimpleString DURABLE_QUEUE = new SimpleString("durableQueue");
    final SimpleString NON_DURABLE_QUEUE = new SimpleString("nonDurableQueue");
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
    Set<Role> roles = new HashSet<>();
    roles.add(new Role("programmers", true, true, true, true, true, true, true, true, true, true));
    server.getConfiguration().putSecurityRoles("#", roles);
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = addClientSession(cf.createSession("first", "secret", false, true, true, false, 0));
    // CREATE_DURABLE_QUEUE
    try {
        session.createQueue(ADDRESS, DURABLE_QUEUE, true);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // DELETE_DURABLE_QUEUE
    try {
        session.deleteQueue(DURABLE_QUEUE);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // CREATE_NON_DURABLE_QUEUE
    try {
        session.createQueue(ADDRESS, NON_DURABLE_QUEUE, false);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // DELETE_NON_DURABLE_QUEUE
    try {
        session.deleteQueue(NON_DURABLE_QUEUE);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    session.createQueue(ADDRESS, DURABLE_QUEUE, true);
    // PRODUCE
    try {
        ClientProducer producer = session.createProducer(ADDRESS);
        producer.send(session.createMessage(true));
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // CONSUME
    try {
        session.createConsumer(DURABLE_QUEUE);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // MANAGE
    try {
        ClientProducer producer = session.createProducer(server.getConfiguration().getManagementAddress());
        producer.send(session.createMessage(true));
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
    // BROWSE
    try {
        session.createConsumer(DURABLE_QUEUE, true);
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception here");
    }
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with Role

use of org.apache.activemq.artemis.core.security.Role in project activemq-artemis by apache.

the class SecurityTest method testCreateTempQueueWithRole.

@Test
public void testCreateTempQueueWithRole() throws Exception {
    ActiveMQServer server = createServer();
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    Role role = new Role("arole", false, false, false, false, true, false, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    securityRepository.addMatch(SecurityTest.addressA, roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    session.createQueue(SecurityTest.addressA, SecurityTest.queueA, false);
    session.close();
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Set(java.util.Set) HashSet(java.util.HashSet) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

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