Search in sources :

Example 66 with ActiveMQJAASSecurityManager

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

the class SecurityTest method testCreateDurableQueueWithoutRole.

@Test
public void testCreateDurableQueueWithoutRole() 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, false, 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);
    try {
        session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
        Assert.fail("should throw exception");
    } catch (ActiveMQSecurityException se) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    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) 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) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 67 with ActiveMQJAASSecurityManager

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

the class SecurityTest method testCreateConsumerWithRole.

@Test
public void testCreateConsumerWithRole() throws Exception {
    ActiveMQServer server = createServer();
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().addRole("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    Role role = new Role("arole", false, true, false, false, false, false, false, false, false, false);
    Role sendRole = new Role("guest", true, false, true, false, false, false, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(sendRole);
    roles.add(role);
    securityRepository.addMatch(SecurityTest.addressA, roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession senSession = cf.createSession(false, true, true);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
    ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
    cp.send(session.createMessage(false));
    session.createConsumer(SecurityTest.queueA);
    session.close();
    senSession.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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 68 with ActiveMQJAASSecurityManager

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

the class SecurityTest method testSendMessageUpdateRoleCached.

@Test
public void testSendMessageUpdateRoleCached() throws Exception {
    Configuration configuration = createDefaultInVMConfig().setSecurityEnabled(true).setSecurityInvalidationInterval(10000);
    ActiveMQServer server = createServer(false, configuration);
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().addRole("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    Role role = new Role("arole", false, false, false, false, false, false, false, false, false, false);
    Role sendRole = new Role("guest", true, false, true, false, false, false, false, false, false, false);
    Role receiveRole = new Role("receiver", false, true, false, false, false, false, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(sendRole);
    roles.add(role);
    roles.add(receiveRole);
    securityRepository.addMatch(SecurityTest.addressA, roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession senSession = cf.createSession(false, true, true);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
    ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
    cp.send(session.createMessage(false));
    try {
        session.createConsumer(SecurityTest.queueA);
    } catch (ActiveMQSecurityException se) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    securityManager.getConfiguration().addRole("auser", "receiver");
    session.createConsumer(SecurityTest.queueA);
    // Removing the Role... the check should be cached, so the next createConsumer shouldn't fail
    securityManager.getConfiguration().removeRole("auser", "receiver");
    session.createConsumer(SecurityTest.queueA);
    session.close();
    senSession.close();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 69 with ActiveMQJAASSecurityManager

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

the class SecurityTest method testJAASSecurityManagerAuthenticationWithValidateUser.

@Test
public void testJAASSecurityManagerAuthenticationWithValidateUser() throws Exception {
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
    server.getConfiguration().setPopulateValidatedUser(true);
    server.start();
    Role role = new Role("programmers", true, true, true, true, true, true, true, true, true, true);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch("#", roles);
    ClientSessionFactory cf = createSessionFactory(locator);
    try {
        ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0);
        server.createQueue(SimpleString.toSimpleString("address"), RoutingType.ANYCAST, SimpleString.toSimpleString("queue"), null, true, false);
        ClientProducer producer = session.createProducer("address");
        producer.send(session.createMessage(true));
        session.commit();
        producer.close();
        ClientConsumer consumer = session.createConsumer("queue");
        session.start();
        ClientMessage message = consumer.receive(1000);
        assertNotNull(message);
        assertEquals("first", message.getValidatedUserID());
        session.close();
    } catch (ActiveMQException e) {
        e.printStackTrace();
        Assert.fail("should not throw exception");
    }
}
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) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 70 with ActiveMQJAASSecurityManager

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

the class SecurityTest method testSendMessageUpdateSender.

@Test
public void testSendMessageUpdateSender() throws Exception {
    Configuration configuration = createDefaultInVMConfig().setSecurityEnabled(true).setSecurityInvalidationInterval(-1);
    ActiveMQServer server = createServer(false, configuration);
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().addRole("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    Role role = new Role("arole", false, false, false, false, false, false, false, false, false, false);
    System.out.println("guest:" + role);
    Role sendRole = new Role("guest", true, false, true, false, false, false, false, false, false, false);
    System.out.println("guest:" + sendRole);
    Role receiveRole = new Role("receiver", false, true, false, false, false, false, false, false, false, false);
    System.out.println("guest:" + receiveRole);
    Set<Role> roles = new HashSet<>();
    roles.add(sendRole);
    roles.add(role);
    roles.add(receiveRole);
    securityRepository.addMatch(SecurityTest.addressA, roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession senSession = cf.createSession(false, true, true);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
    ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
    cp.send(session.createMessage(false));
    try {
        session.createConsumer(SecurityTest.queueA);
    } catch (ActiveMQSecurityException se) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    securityManager.getConfiguration().addRole("auser", "receiver");
    session.createConsumer(SecurityTest.queueA);
    // Removing the Role... the check should be cached... but we used
    // setSecurityInvalidationInterval(0), so the
    // next createConsumer should fail
    securityManager.getConfiguration().removeRole("auser", "guest");
    ClientSession sendingSession = cf.createSession("auser", "pass", false, false, false, false, 0);
    ClientProducer prod = sendingSession.createProducer(SecurityTest.addressA);
    prod.send(CreateMessage.createTextMessage(sendingSession, "Test", true));
    prod.send(CreateMessage.createTextMessage(sendingSession, "Test", true));
    try {
        sendingSession.commit();
        Assert.fail("Expected exception");
    } catch (ActiveMQException e) {
    // I would expect the commit to fail, since there were failures registered
    }
    sendingSession.close();
    Xid xid = newXID();
    sendingSession = cf.createSession("auser", "pass", true, false, false, false, 0);
    sendingSession.start(xid, XAResource.TMNOFLAGS);
    prod = sendingSession.createProducer(SecurityTest.addressA);
    prod.send(CreateMessage.createTextMessage(sendingSession, "Test", true));
    prod.send(CreateMessage.createTextMessage(sendingSession, "Test", true));
    sendingSession.end(xid, XAResource.TMSUCCESS);
    try {
        sendingSession.prepare(xid);
        Assert.fail("Exception was expected");
    } catch (Exception e) {
        e.printStackTrace();
    }
    // A prepare shouldn't mark any recoverable resources
    Xid[] xids = sendingSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(0, xids.length);
    session.close();
    senSession.close();
    sendingSession.close();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Xid(javax.transaction.xa.Xid) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)91 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)50 Role (org.apache.activemq.artemis.core.security.Role)49 Test (org.junit.Test)48 HashSet (java.util.HashSet)47 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)42 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)40 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)30 Set (java.util.Set)27 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)23 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)21 SecurityConfiguration (org.apache.activemq.artemis.core.config.impl.SecurityConfiguration)21 InVMLoginModule (org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule)19 Configuration (org.apache.activemq.artemis.core.config.Configuration)18 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)16 HashMap (java.util.HashMap)14 Before (org.junit.Before)13 ActiveMQSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager)10 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)9