Search in sources :

Example 1 with ActiveMQJAASSecurityManager

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

the class ActiveMQServers method newActiveMQServer.

public static ActiveMQServer newActiveMQServer(final Configuration config, final boolean enablePersistence) {
    ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
    ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, ManagementFactory.getPlatformMBeanServer(), securityManager, enablePersistence);
    return server;
}
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) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager)

Example 2 with ActiveMQJAASSecurityManager

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

the class ActiveMQServers method newActiveMQServer.

public static ActiveMQServer newActiveMQServer(Configuration config, String defUser, String defPass) {
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
    securityManager.getConfiguration().addUser(defUser, defPass);
    ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, ManagementFactory.getPlatformMBeanServer(), securityManager, config.isPersistenceEnabled());
    return server;
}
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)

Example 3 with ActiveMQJAASSecurityManager

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

the class OsgiBroker method activate.

@Activate
public void activate(ComponentContext cctx) throws Exception {
    final BundleContext context = cctx.getBundleContext();
    final Dictionary<String, Object> properties = cctx.getProperties();
    configurationUrl = getMandatory(properties, "config");
    name = getMandatory(properties, "name");
    rolePrincipalClass = (String) properties.get("rolePrincipalClass");
    String domain = getMandatory(properties, "domain");
    ActiveMQJAASSecurityManager security = new ActiveMQJAASSecurityManager(domain);
    if (rolePrincipalClass != null) {
        security.setRolePrincipalClass(rolePrincipalClass);
    }
    String brokerInstance = null;
    String karafDataDir = System.getProperty("karaf.data");
    if (karafDataDir != null) {
        brokerInstance = karafDataDir + "/artemis/" + name;
    }
    // todo if we start to pullout more configs from the main config then we
    // should pull out the configuration objects from factories if available
    FileConfiguration configuration = new FileConfiguration();
    if (brokerInstance != null) {
        configuration.setBrokerInstance(new File(brokerInstance));
    }
    FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration();
    FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl);
    fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration).readConfiguration();
    components = fileDeploymentManager.buildService(security, ManagementFactory.getPlatformMBeanServer());
    final ActiveMQServer server = (ActiveMQServer) components.get("core");
    String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations());
    ServerTrackerCallBack callback = new ServerTrackerCallBackImpl(server, context, properties);
    StoreConfiguration storeConfiguration = server.getConfiguration().getStoreConfiguration();
    String dataSourceName = String.class.cast(properties.get("dataSourceName"));
    if (storeConfiguration != null && storeConfiguration.getStoreType() == StoreType.DATABASE && dataSourceName != null && !dataSourceName.isEmpty()) {
        callback.setDataSourceDependency(true);
        String filter = "(&(objectClass=javax.sql.DataSource)(osgi.jndi.service.name=" + dataSourceName + "))";
        DataSourceTracker trackerCust = new DataSourceTracker(name, context, DatabaseStorageConfiguration.class.cast(storeConfiguration), (ServerTrackerCallBack) callback);
        dataSourceTracker = new ServiceTracker(context, context.createFilter(filter), trackerCust);
        dataSourceTracker.open();
    }
    ProtocolTracker trackerCust = new ProtocolTracker(name, context, requiredProtocols, callback);
    tracker = new ServiceTracker(context, ProtocolManagerFactory.class, trackerCust);
    tracker.open();
}
Also used : ProtocolManagerFactory(org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) FileConfiguration(org.apache.activemq.artemis.core.config.impl.FileConfiguration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) FileJMSConfiguration(org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) FileDeploymentManager(org.apache.activemq.artemis.core.config.FileDeploymentManager) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Activate(org.osgi.service.component.annotations.Activate)

Example 4 with ActiveMQJAASSecurityManager

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

the class FileBrokerTest method startTwoBrokersWithSameDataDir.

@Test
public void startTwoBrokersWithSameDataDir() throws Exception {
    ServerDTO serverDTO1 = new ServerDTO();
    ServerDTO serverDTO2 = new ServerDTO();
    serverDTO1.configuration = "FileBrokerTest-broker1.xml";
    serverDTO2.configuration = "FileBrokerTest-broker2.xml";
    FileBroker broker1 = new FileBroker(serverDTO1, new ActiveMQJAASSecurityManager());
    FileBroker broker2 = new FileBroker(serverDTO2, new ActiveMQJAASSecurityManager());
    try {
        broker1.start();
        Assert.assertTrue(broker1.isStarted());
        Thread thread = new Thread(() -> {
            try {
                broker2.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        thread.start();
        Assert.assertFalse(broker2.isStarted());
        // only if broker1 is stopped can broker2 be fully started
        broker1.stop();
        broker1 = null;
        thread.join(5000);
        Assert.assertTrue(broker2.isStarted());
        broker2.stop();
    } finally {
        if (broker1 != null) {
            broker1.stop();
        }
        if (broker2 != null) {
            broker2.stop();
        }
    }
}
Also used : FileBroker(org.apache.activemq.artemis.integration.FileBroker) ServerDTO(org.apache.activemq.artemis.dto.ServerDTO) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with ActiveMQJAASSecurityManager

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

the class HangConsumerTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Configuration config = createDefaultInVMConfig().setMessageExpiryScanPeriod(10);
    ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
    server = addServer(new MyActiveMQServer(config, ManagementFactory.getPlatformMBeanServer(), securityManager));
    server.start();
    locator = createInVMNonHALocator();
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) 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) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) Before(org.junit.Before)

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