Search in sources :

Example 86 with ActiveMQJAASSecurityManager

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

the class SecurityManagementWithConfiguredAdminUserTest method setupAndStartActiveMQServer.

// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
protected ActiveMQServer setupAndStartActiveMQServer() throws Exception {
    Configuration config = createDefaultInVMConfig().setSecurityEnabled(true);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser(validAdminUser, validAdminPassword);
    securityManager.getConfiguration().addUser(invalidAdminUser, invalidAdminPassword);
    securityManager.getConfiguration().addRole(validAdminUser, "admin");
    securityManager.getConfiguration().addRole(validAdminUser, "guest");
    securityManager.getConfiguration().addRole(invalidAdminUser, "guest");
    Set<Role> adminRole = securityRepository.getMatch(ActiveMQDefaultConfiguration.getDefaultManagementAddress().toString());
    adminRole.add(new Role("admin", true, true, true, true, true, true, true, true, true, true));
    securityRepository.addMatch(ActiveMQDefaultConfiguration.getDefaultManagementAddress().toString(), adminRole);
    Set<Role> guestRole = securityRepository.getMatch("*");
    guestRole.add(new Role("guest", true, true, true, true, true, true, false, true, true, true));
    securityRepository.addMatch("*", guestRole);
    return server;
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Set(java.util.Set) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)

Example 87 with ActiveMQJAASSecurityManager

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

the class ActiveMQTestBase method createInVMFailoverServer.

protected ActiveMQServer createInVMFailoverServer(final boolean realFiles, final Configuration configuration, final int pageSize, final int maxAddressSize, final Map<String, AddressSettings> settings, NodeManager nodeManager, final int id) {
    ActiveMQServer server;
    ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
    configuration.setPersistenceEnabled(realFiles);
    server = addServer(new InVMNodeManagerServer(configuration, ManagementFactory.getPlatformMBeanServer(), securityManager, nodeManager));
    try {
        server.setIdentity("Server " + id);
        for (Map.Entry<String, AddressSettings> setting : settings.entrySet()) {
            server.getAddressSettingsRepository().addMatch(setting.getKey(), setting.getValue());
        }
        AddressSettings defaultSetting = new AddressSettings();
        defaultSetting.setPageSizeBytes(pageSize);
        defaultSetting.setMaxSizeBytes(maxAddressSize);
        server.getAddressSettingsRepository().addMatch("#", defaultSetting);
        return server;
    } finally {
        addServer(server);
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) 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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) Map(java.util.Map) HashMap(java.util.HashMap)

Example 88 with ActiveMQJAASSecurityManager

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

the class SecurityOpenWireTest method extraServerConfig.

@Override
protected void extraServerConfig(Configuration serverConfig) {
    super.extraServerConfig(serverConfig);
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("denyQ", "denyQ");
    securityManager.getConfiguration().addRole("denyQ", "denyQ");
}
Also used : ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)

Example 89 with ActiveMQJAASSecurityManager

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

the class EmbeddedExample method main.

public static void main(final String[] args) throws Exception {
    // Step 1. Configure security.
    SecurityConfiguration securityConfig = new SecurityConfiguration();
    securityConfig.addUser("guest", "guest");
    securityConfig.addRole("guest", "guest");
    securityConfig.setDefaultUser("guest");
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfig);
    // Step 2. Create and start embedded broker.
    ActiveMQServer server = ActiveMQServers.newActiveMQServer("broker.xml", null, securityManager);
    server.start();
    System.out.println("Started Embedded Broker");
    InitialContext initialContext = null;
    // Step 3. Create an initial context to perform the JNDI lookup.
    initialContext = new InitialContext();
    // Step 4. Look-up the JMS queue
    Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
    // Step 5. Look-up the JMS connection factory
    ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
    // Step 6. Send and receive a message using JMS API
    try (Connection connection = cf.createConnection()) {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        TextMessage message = session.createTextMessage("Hello sent at " + new Date());
        System.out.println("Sending message: " + message.getText());
        producer.send(message);
        MessageConsumer messageConsumer = session.createConsumer(queue);
        connection.start();
        TextMessage messageReceived = (TextMessage) messageConsumer.receive(1000);
        System.out.println("Received message:" + messageReceived.getText());
    } finally {
        // Step 7. Stop the embedded broker.
        server.stop();
        System.out.println("Stopped the Embedded Broker");
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) Connection(javax.jms.Connection) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) InitialContext(javax.naming.InitialContext) Date(java.util.Date) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ConnectionFactory(javax.jms.ConnectionFactory) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 90 with ActiveMQJAASSecurityManager

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

the class JMSSecurityTest method testSecurityOnJMSContext.

@Test
public void testSecurityOnJMSContext() throws Exception {
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("IDo", "Exist");
    try {
        JMSContext ctx = cf.createContext("Idont", "exist");
        ctx.close();
    } catch (JMSSecurityRuntimeException e) {
    // expected
    }
    JMSContext ctx = cf.createContext("IDo", "Exist");
    ctx.close();
}
Also used : JMSSecurityRuntimeException(javax.jms.JMSSecurityRuntimeException) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) JMSContext(javax.jms.JMSContext) 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