Search in sources :

Example 1 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class FloodServerTest method setUp.

// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
// Constructors --------------------------------------------------
// TestCase overrides -------------------------------------------
// Public --------------------------------------------------------
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Configuration config = createDefaultNettyConfig();
    server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    serverManager = new JMSServerManagerImpl(server);
    initialContext = new InVMNamingContext();
    serverManager.setRegistry(new JndiBindingRegistry(initialContext));
    serverManager.start();
    serverManager.activated();
    serverManager.createTopic(false, topicName, topicName);
    registerConnectionFactory();
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Before(org.junit.Before)

Example 2 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class OpenWireTestBase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = this.createServer(realStore, true);
    Configuration serverConfig = server.getConfiguration();
    serverConfig.getAddressesSettings().put("#", new AddressSettings().setAutoCreateQueues(false).setAutoCreateAddresses(false).setDeadLetterAddress(new SimpleString("ActiveMQ.DLQ")).setAutoCreateAddresses(true));
    serverConfig.setSecurityEnabled(enableSecurity);
    extraServerConfig(serverConfig);
    if (enableSecurity) {
        ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
        securityManager.getConfiguration().addRole("openwireSender", "sender");
        securityManager.getConfiguration().addUser("openwireSender", "SeNdEr");
        // sender cannot receive
        Role senderRole = new Role("sender", true, false, false, false, true, true, false, false, true, true);
        securityManager.getConfiguration().addRole("openwireReceiver", "receiver");
        securityManager.getConfiguration().addUser("openwireReceiver", "ReCeIvEr");
        // receiver cannot send
        Role receiverRole = new Role("receiver", false, true, false, false, true, true, false, true, false, false);
        securityManager.getConfiguration().addRole("openwireGuest", "guest");
        securityManager.getConfiguration().addUser("openwireGuest", "GuEsT");
        // guest cannot do anything
        Role guestRole = new Role("guest", false, false, false, false, false, false, false, false, false, false);
        securityManager.getConfiguration().addRole("openwireDestinationManager", "manager");
        securityManager.getConfiguration().addUser("openwireDestinationManager", "DeStInAtIoN");
        Role destRole = new Role("manager", false, false, false, false, true, true, false, false, false, false);
        Set<Role> roles = new HashSet<>();
        roles.add(senderRole);
        roles.add(receiverRole);
        roles.add(guestRole);
        roles.add(destRole);
        server.getConfiguration().putSecurityRoles("#", roles);
    }
    mbeanServer = MBeanServerFactory.createMBeanServer();
    server.setMBeanServer(mbeanServer);
    addServer(server);
    jmsServer = new JMSServerManagerImpl(server);
    namingContext = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(namingContext));
    jmsServer.start();
    registerConnectionFactory();
    System.out.println("debug: server started");
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) HashSet(java.util.HashSet) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Before(org.junit.Before)

Example 3 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class ManagementActivationTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    backupJmsServer = new JMSServerManagerImpl(backupServer.getServer());
    context = new InVMNamingContext();
    backupJmsServer.setRegistry(new JndiBindingRegistry(context));
    backupJmsServer.start();
}
Also used : JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Before(org.junit.Before)

Example 4 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class StompWithClientIdValidationTest method createServer.

@Override
protected JMSServerManager createServer() throws Exception {
    Configuration config = createBasicConfig().setSecurityEnabled(isSecurityEnabled()).setPersistenceEnabled(isPersistenceEnabled()).addAcceptorConfiguration("stomp", "tcp://localhost:61613?enabledProtocols=STOMP").addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration()) {

        @Override
        public String validateUser(String user, String password, RemotingConnection remotingConnection) {
            String validatedUser = super.validateUser(user, password, remotingConnection);
            if (validatedUser == null) {
                return null;
            }
            if ("STOMP".equals(remotingConnection.getProtocolName())) {
                final String clientId = remotingConnection.getClientID();
                /*
                * perform some kind of clientId validation, e.g. check presence or format
                */
                if (clientId == null || clientId.length() == 0) {
                    System.err.println("ClientID not set!");
                    return null;
                }
            }
            return validatedUser;
        }
    };
    securityManager.getConfiguration().addUser(defUser, defPass);
    ActiveMQServer activeMqServer = addServer(ActiveMQServers.newActiveMQServer(config, ManagementFactory.getPlatformMBeanServer(), securityManager));
    JMSConfiguration jmsConfig = new JMSConfigurationImpl();
    server = new JMSServerManagerImpl(activeMqServer, jmsConfig);
    server.setRegistry(new JndiBindingRegistry(new InVMNamingContext()));
    return server;
}
Also used : JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)

Example 5 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class StompTestBase method createServer.

/**
 * @return
 * @throws Exception
 */
protected JMSServerManager createServer() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.PROTOCOLS_PROP_NAME, StompProtocolManagerFactory.STOMP_PROTOCOL_NAME + "," + MQTTProtocolManagerFactory.MQTT_PROTOCOL_NAME);
    params.put(TransportConstants.PORT_PROP_NAME, TransportConstants.DEFAULT_STOMP_PORT);
    params.put(TransportConstants.STOMP_CONSUMERS_CREDIT, "-1");
    if (isEnableStompMessageId()) {
        params.put(TransportConstants.STOMP_ENABLE_MESSAGE_ID, true);
    }
    if (getStompMinLargeMessageSize() != null) {
        params.put(TransportConstants.STOMP_MIN_LARGE_MESSAGE_SIZE, 2048);
    }
    TransportConfiguration stompTransport = new TransportConfiguration(NettyAcceptorFactory.class.getName(), params);
    Configuration config = createBasicConfig().setSecurityEnabled(isSecurityEnabled()).setPersistenceEnabled(isPersistenceEnabled()).addAcceptorConfiguration(stompTransport).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName())).setConnectionTtlCheckInterval(500);
    if (getIncomingInterceptors() != null) {
        config.setIncomingInterceptorClassNames(getIncomingInterceptors());
    }
    if (getOutgoingInterceptors() != null) {
        config.setOutgoingInterceptorClassNames(getOutgoingInterceptors());
    }
    config.setPersistenceEnabled(true);
    ActiveMQServer activeMQServer = addServer(ActiveMQServers.newActiveMQServer(config, defUser, defPass));
    if (isSecurityEnabled()) {
        ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) activeMQServer.getSecurityManager();
        final String role = "testRole";
        securityManager.getConfiguration().addRole(defUser, role);
        config.getSecurityRoles().put("#", new HashSet<Role>() {

            {
                add(new Role(role, true, true, true, true, true, true, true, true, true, true));
            }
        });
    }
    JMSConfiguration jmsConfig = new JMSConfigurationImpl();
    jmsConfig.getQueueConfigurations().add(new JMSQueueConfigurationImpl().setName(getQueueName()).setBindings(getQueueName()));
    jmsConfig.getTopicConfigurations().add(new TopicConfigurationImpl().setName(getTopicName()).setBindings(getTopicName()));
    server = new JMSServerManagerImpl(activeMQServer, jmsConfig);
    server.setRegistry(new JndiBindingRegistry(new InVMNamingContext()));
    return server;
}
Also used : JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) HashMap(java.util.HashMap) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) NettyAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl) JMSQueueConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory) TopicConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)

Aggregations

JndiBindingRegistry (org.apache.activemq.artemis.core.registry.JndiBindingRegistry)18 InVMNamingContext (org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)18 JMSServerManagerImpl (org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl)17 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)14 Configuration (org.apache.activemq.artemis.core.config.Configuration)12 Before (org.junit.Before)9 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7 JMSConfigurationImpl (org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl)6 ConnectionFactoryConfiguration (org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration)4 JMSConfiguration (org.apache.activemq.artemis.jms.server.config.JMSConfiguration)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 JMSQueueConfigurationImpl (org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl)3 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Connection (javax.jms.Connection)2 MessageProducer (javax.jms.MessageProducer)2