Search in sources :

Example 81 with ActiveMQJAASSecurityManager

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

the class EmbeddedRestActiveMQJMSTest method startEmbedded.

@BeforeClass
public static void startEmbedded() throws Exception {
    server = new EmbeddedRestActiveMQJMS(null);
    assertNotNull(server.embeddedActiveMQ);
    server.getManager().setConfigResourcePath("activemq-rest.xml");
    SecurityConfiguration securityConfiguration = createDefaultSecurityConfiguration();
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
    server.getEmbeddedJMS().setSecurityManager(securityManager);
    server.start();
    List<String> connectors = createInVmConnector();
    server.getEmbeddedJMS().getJMSServerManager().createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF, connectors, "ConnectionFactory");
    ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/queues/exampleQueue"));
    ClientResponse<?> response = request.head();
    response.releaseConnection();
    assertEquals(200, response.getStatus());
    Link sender = response.getLinkHeader().getLinkByTitle("create");
    System.out.println("create: " + sender);
    Link consumers = response.getLinkHeader().getLinkByTitle("pull-consumers");
    System.out.println("pull: " + consumers);
    response = Util.setAutoAck(consumers, true);
    consumeNext = response.getLinkHeader().getLinkByTitle("consume-next");
    System.out.println("consume-next: " + consumeNext);
}
Also used : ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) BeforeClass(org.junit.BeforeClass)

Example 82 with ActiveMQJAASSecurityManager

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

the class EmbeddedTest method startEmbedded.

@BeforeClass
public static void startEmbedded() throws Exception {
    server = new EmbeddedRestActiveMQJMS(null);
    server.getManager().setConfigResourcePath("activemq-rest.xml");
    SecurityConfiguration securityConfiguration = new SecurityConfiguration();
    securityConfiguration.addUser("guest", "guest");
    securityConfiguration.addRole("guest", "guest");
    securityConfiguration.setDefaultUser("guest");
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
    server.getEmbeddedJMS().setSecurityManager(securityManager);
    server.start();
    List<String> connectors = new ArrayList<>();
    connectors.add("in-vm");
    server.getEmbeddedJMS().getJMSServerManager().createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF, connectors, "ConnectionFactory");
}
Also used : ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ArrayList(java.util.ArrayList) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) EmbeddedRestActiveMQJMS(org.apache.activemq.artemis.rest.integration.EmbeddedRestActiveMQJMS) BeforeClass(org.junit.BeforeClass)

Example 83 with ActiveMQJAASSecurityManager

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

the class LocalTestServer method start.

@Override
public synchronized void start(final HashMap<String, Object> configuration, final boolean clearJournal) throws Exception {
    if (isStarted()) {
        return;
    }
    if (clearJournal) {
        // Delete the Journal environment
        File dir = new File("target/data");
        boolean deleted = LocalTestServer.deleteDirectory(dir);
        JmsTestLogger.LOGGER.info("Deleted dir: " + dir.getAbsolutePath() + " deleted: " + deleted);
    }
    javax.management.MBeanServer beanServer = java.lang.management.ManagementFactory.getPlatformMBeanServer();
    FileConfiguration fileConfiguration = new FileConfiguration();
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    securityManager.getConfiguration().addRole("guest", "guest");
    ActiveMQServerImpl activeMQServer = new ActiveMQServerImpl(fileConfiguration, beanServer, securityManager);
    jmsServerManager = new JMSServerManagerImpl(activeMQServer);
    System.setProperty(Constants.SERVER_INDEX_PROPERTY_NAME, "" + getServerID());
    jmsServerManager.setRegistry(new JndiBindingRegistry(getInitialContext()));
    FileDeploymentManager deploymentManager = new FileDeploymentManager();
    deploymentManager.addDeployable(fileConfiguration).readConfiguration();
    jmsServerManager.start();
    started = true;
}
Also used : FileConfiguration(org.apache.activemq.artemis.core.config.impl.FileConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) FileDeploymentManager(org.apache.activemq.artemis.core.config.FileDeploymentManager) File(java.io.File)

Example 84 with ActiveMQJAASSecurityManager

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

the class EmbeddedActiveMQ method initStart.

protected void initStart() throws Exception {
    if (configuration == null) {
        if (configResourcePath == null)
            configResourcePath = "broker.xml";
        FileDeploymentManager deploymentManager = new FileDeploymentManager(configResourcePath);
        FileConfiguration config = new FileConfiguration();
        deploymentManager.addDeployable(config);
        deploymentManager.readConfiguration();
        configuration = config;
    }
    if (securityManager == null) {
        securityManager = new ActiveMQJAASSecurityManager();
    }
    if (mbeanServer == null) {
        activeMQServer = new ActiveMQServerImpl(configuration, securityManager);
    } else {
        activeMQServer = new ActiveMQServerImpl(configuration, mbeanServer, securityManager);
    }
}
Also used : FileConfiguration(org.apache.activemq.artemis.core.config.impl.FileConfiguration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) FileDeploymentManager(org.apache.activemq.artemis.core.config.FileDeploymentManager) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)

Example 85 with ActiveMQJAASSecurityManager

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

the class ServerLargeMessageTest method testSendServerMessageWithValidatedUser.

@Test
public void testSendServerMessageWithValidatedUser() throws Exception {
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
    server.getConfiguration().setPopulateValidatedUser(true);
    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);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    try {
        ClientSession session = sf.createSession("first", "secret", false, true, true, false, 0);
        ClientMessage clientMessage = session.createMessage(false);
        clientMessage.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE));
        session.createQueue("A", RoutingType.ANYCAST, "A");
        ClientProducer prod = session.createProducer("A");
        prod.send(clientMessage);
        session.commit();
        session.start();
        ClientConsumer cons = session.createConsumer("A");
        ClientMessage msg = cons.receive(5000);
        assertEquals("first", msg.getValidatedUserID());
    } finally {
        sf.close();
        locator.close();
        server.stop();
    }
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) HashSet(java.util.HashSet) Test(org.junit.Test) SecurityTest(org.apache.activemq.artemis.tests.integration.security.SecurityTest)

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