Search in sources :

Example 16 with SecurityConfiguration

use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration in project activemq-artemis by apache.

the class CriticalCrashTest method createServer.

ActiveMQServer createServer(String folder) throws Exception {
    final AtomicBoolean blocked = new AtomicBoolean(false);
    Configuration conf = createConfig(folder);
    ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
    conf.setPersistenceEnabled(true);
    ActiveMQServer server = new ActiveMQServerImpl(conf, securityManager) {

        @Override
        protected StorageManager createStorageManager() {
            JournalStorageManager storageManager = new JournalStorageManager(conf, getCriticalAnalyzer(), executorFactory, scheduledPool, ioExecutorFactory, shutdownOnCriticalIO) {

                @Override
                public void readLock() {
                    super.readLock();
                    if (blocked.get()) {
                        while (true) {
                            try {
                                System.out.println("Blocking forever");
                                Thread.sleep(1000);
                            } catch (Throwable ignored) {
                            }
                        }
                    }
                }

                @Override
                public void storeMessage(Message message) throws Exception {
                    super.storeMessage(message);
                    blocked.set(true);
                }
            };
            this.getCriticalAnalyzer().add(storageManager);
            return storageManager;
        }
    };
    return server;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) Message(org.apache.activemq.artemis.api.core.Message) 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) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)

Example 17 with SecurityConfiguration

use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration in project activemq-artemis by apache.

the class FileBrokerTest method testConfigFileReload.

@Test
public void testConfigFileReload() throws Exception {
    ServerDTO serverDTO = new ServerDTO();
    serverDTO.configuration = "broker-reload.xml";
    FileBroker broker = null;
    String path = null;
    try {
        SecurityConfiguration securityConfiguration = new SecurityConfiguration();
        securityConfiguration.addUser("myUser", "myPass");
        securityConfiguration.addRole("myUser", "guest");
        ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
        broker = new FileBroker(serverDTO, securityManager);
        broker.start();
        ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core");
        Assert.assertNotNull(activeMQServer);
        Assert.assertTrue(activeMQServer.isStarted());
        Assert.assertTrue(broker.isStarted());
        File file = new File(activeMQServer.getConfiguration().getConfigurationUrl().toURI());
        path = file.getPath();
        Assert.assertNotNull(activeMQServer.getConfiguration().getConfigurationUrl());
        Thread.sleep(activeMQServer.getConfiguration().getConfigurationFileRefreshPeriod() * 2);
        ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616");
        ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession("myUser", "myPass", false, true, false, false, 0);
        ClientProducer producer = session.createProducer("DLQ");
        producer.send(session.createMessage(true));
        replacePatternInFile(path, "guest", "X");
        Thread.sleep(activeMQServer.getConfiguration().getConfigurationFileRefreshPeriod() * 2);
        try {
            producer.send(session.createMessage(true));
            fail("Should throw a security exception");
        } catch (Exception e) {
        }
        locator.close();
    } finally {
        assert broker != null;
        broker.stop();
        if (path != null) {
            replacePatternInFile(path, "X", "guest");
        }
    }
}
Also used : FileBroker(org.apache.activemq.artemis.integration.FileBroker) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) IOException(java.io.IOException) ServerDTO(org.apache.activemq.artemis.dto.ServerDTO) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) File(java.io.File) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 18 with SecurityConfiguration

use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration 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 19 with SecurityConfiguration

use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration 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 20 with SecurityConfiguration

use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration 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)

Aggregations

SecurityConfiguration (org.apache.activemq.artemis.core.config.impl.SecurityConfiguration)22 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)21 InVMLoginModule (org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule)19 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)8 ActiveMQSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager)8 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)7 Configuration (org.apache.activemq.artemis.core.config.Configuration)6 JMSServerManagerImpl (org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl)4 Message (org.apache.activemq.artemis.api.core.Message)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 FileDeploymentManager (org.apache.activemq.artemis.core.config.FileDeploymentManager)3 FileConfiguration (org.apache.activemq.artemis.core.config.impl.FileConfiguration)3 JndiBindingRegistry (org.apache.activemq.artemis.core.registry.JndiBindingRegistry)3 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 Before (org.junit.Before)3 File (java.io.File)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2