Search in sources :

Example 1 with SecuritySettingPlugin

use of org.apache.activemq.artemis.core.server.SecuritySettingPlugin in project activemq-artemis by apache.

the class ActiveMQServerImpl method stop.

/**
 * Stops the server
 *
 * @param criticalIOError whether we have encountered an IO error with the journal etc
 */
void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boolean restarting, boolean isShutdown) {
    synchronized (this) {
        if (state == SERVER_STATE.STOPPED || state == SERVER_STATE.STOPPING) {
            return;
        }
        state = SERVER_STATE.STOPPING;
        if (fileStoreMonitor != null) {
            fileStoreMonitor.stop();
            fileStoreMonitor = null;
        }
        if (failoverOnServerShutdown) {
            activation.sendLiveIsStopping();
        }
        stopComponent(connectorsService);
        // aren't removed in case of failover
        if (groupingHandler != null) {
            managementService.removeNotificationListener(groupingHandler);
            stopComponent(groupingHandler);
        }
        stopComponent(clusterManager);
        if (remotingService != null) {
            remotingService.pauseAcceptors();
        }
        // allows for graceful shutdown
        if (remotingService != null && configuration.isGracefulShutdownEnabled()) {
            long timeout = configuration.getGracefulShutdownTimeout();
            try {
                if (timeout == -1) {
                    remotingService.getConnectionCountLatch().await();
                } else {
                    remotingService.getConnectionCountLatch().await(timeout);
                }
            } catch (InterruptedException e) {
                ActiveMQServerLogger.LOGGER.interruptWhilstStoppingComponent(remotingService.getClass().getName());
            }
        }
        freezeConnections();
    }
    activation.postConnectionFreeze();
    closeAllServerSessions(criticalIOError);
    if (storageManager != null)
        storageManager.clearContext();
    // before we stop any components deactivate any callbacks
    callDeActiveCallbacks();
    stopComponent(backupManager);
    try {
        activation.preStorageClose();
    } catch (Throwable t) {
        ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, activation.getClass().getName());
    }
    stopComponent(pagingManager);
    if (storageManager != null)
        try {
            storageManager.stop(criticalIOError, failoverOnServerShutdown);
        } catch (Throwable t) {
            ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, storageManager.getClass().getName());
        }
    // error shutdown
    if (remotingService != null)
        try {
            remotingService.stop(criticalIOError);
        } catch (Throwable t) {
            ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, remotingService.getClass().getName());
        }
    // Stop the management service after the remoting service to ensure all acceptors are deregistered with JMX
    if (managementService != null)
        try {
            managementService.unregisterServer();
        } catch (Throwable t) {
            ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, managementService.getClass().getName());
        }
    stopComponent(managementService);
    stopComponent(resourceManager);
    stopComponent(postOffice);
    if (scheduledPool != null && !scheduledPoolSupplied) {
        // we just interrupt all running tasks, these are supposed to be pings and the like.
        scheduledPool.shutdownNow();
    }
    stopComponent(memoryManager);
    for (SecuritySettingPlugin securitySettingPlugin : configuration.getSecuritySettingPlugins()) {
        securitySettingPlugin.stop();
    }
    if (threadPool != null && !threadPoolSupplied) {
        shutdownPool(threadPool);
    }
    if (ioExecutorPool != null) {
        shutdownPool(ioExecutorPool);
    }
    if (!threadPoolSupplied)
        threadPool = null;
    if (!scheduledPoolSupplied)
        scheduledPool = null;
    if (securityStore != null) {
        try {
            securityStore.stop();
        } catch (Throwable t) {
            ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, managementService.getClass().getName());
        }
    }
    pagingManager = null;
    securityStore = null;
    resourceManager = null;
    postOffice = null;
    queueFactory = null;
    resourceManager = null;
    messagingServerControl = null;
    memoryManager = null;
    backupManager = null;
    storageManager = null;
    sessions.clear();
    activateCallbacks.clear();
    state = SERVER_STATE.STOPPED;
    activationLatch.setCount(1);
    // to display in the log message
    SimpleString tempNodeID = getNodeID();
    if (activation != null) {
        try {
            activation.close(failoverOnServerShutdown, restarting);
        } catch (Throwable t) {
            ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, activation.getClass().getName());
        }
    }
    if (activationThread != null) {
        try {
            activationThread.join(30000);
        } catch (InterruptedException e) {
            ActiveMQServerLogger.LOGGER.interruptWhilstStoppingComponent(activationThread.getClass().getName());
        }
        if (activationThread.isAlive()) {
            ActiveMQServerLogger.LOGGER.activationDidntFinish(this);
            activationThread.interrupt();
        }
    }
    stopComponent(nodeManager);
    nodeManager = null;
    addressSettingsRepository.clearListeners();
    addressSettingsRepository.clearCache();
    scaledDownNodeIDs.clear();
    for (ActiveMQComponent externalComponent : externalComponents) {
        try {
            if (externalComponent instanceof ServiceComponent) {
                ((ServiceComponent) externalComponent).stop(isShutdown);
            } else {
                externalComponent.stop();
            }
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.errorStoppingComponent(e, externalComponent.getClass().getName());
        }
    }
    try {
        this.analyzer.stop();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
    } finally {
        this.analyzer = null;
    }
    if (identity != null) {
        ActiveMQServerLogger.LOGGER.serverStopped("identity=" + identity + ",version=" + getVersion().getFullVersion(), tempNodeID, getUptime());
    } else {
        ActiveMQServerLogger.LOGGER.serverStopped(getVersion().getFullVersion(), tempNodeID, getUptime());
    }
}
Also used : ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) ServiceComponent(org.apache.activemq.artemis.core.server.ServiceComponent) SecuritySettingPlugin(org.apache.activemq.artemis.core.server.SecuritySettingPlugin) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) IOException(java.io.IOException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQDeleteAddressException(org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException)

Example 2 with SecuritySettingPlugin

use of org.apache.activemq.artemis.core.server.SecuritySettingPlugin in project activemq-artemis by apache.

the class FileConfigurationParser method parseSecuritySettingPlugins.

private Pair<SecuritySettingPlugin, Map<String, String>> parseSecuritySettingPlugins(Node item) {
    final String clazz = item.getAttributes().getNamedItem("class-name").getNodeValue();
    final Map<String, String> settings = new HashMap<>();
    NodeList children = item.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
        Node child = children.item(j);
        final String nodeName = child.getNodeName();
        if (SETTING_ELEMENT_NAME.equalsIgnoreCase(nodeName)) {
            final String settingName = getAttributeValue(child, NAME_ATTR_NAME);
            final String settingValue = getAttributeValue(child, VALUE_ATTR_NAME);
            settings.put(settingName, settingValue);
        }
    }
    SecuritySettingPlugin securitySettingPlugin = AccessController.doPrivileged(new PrivilegedAction<SecuritySettingPlugin>() {

        @Override
        public SecuritySettingPlugin run() {
            return (SecuritySettingPlugin) ClassloadingUtil.newInstanceFromClassLoader(clazz);
        }
    });
    return new Pair<>(securitySettingPlugin, settings);
}
Also used : HashMap(java.util.HashMap) SecuritySettingPlugin(org.apache.activemq.artemis.core.server.SecuritySettingPlugin) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 3 with SecuritySettingPlugin

use of org.apache.activemq.artemis.core.server.SecuritySettingPlugin in project activemq-artemis by apache.

the class FileConfigurationParser method parseSecurity.

/**
 * @param e
 * @param config
 */
private void parseSecurity(final Element e, final Configuration config) {
    NodeList elements = e.getElementsByTagName("security-settings");
    if (elements.getLength() != 0) {
        Element node = (Element) elements.item(0);
        NodeList list = node.getElementsByTagName(SECURITY_ROLE_MAPPING_NAME);
        for (int i = 0; i < list.getLength(); i++) {
            Map<String, Set<String>> roleMappings = parseSecurityRoleMapping(list.item(i));
            for (Map.Entry<String, Set<String>> roleMapping : roleMappings.entrySet()) {
                config.addSecurityRoleNameMapping(roleMapping.getKey(), roleMapping.getValue());
            }
        }
        list = node.getElementsByTagName(SECURITY_ELEMENT_NAME);
        for (int i = 0; i < list.getLength(); i++) {
            Pair<String, Set<Role>> securityItem = parseSecurityRoles(list.item(i), config.getSecurityRoleNameMappings());
            config.putSecurityRoles(securityItem.getA(), securityItem.getB());
        }
        list = node.getElementsByTagName(SECURITY_PLUGIN_ELEMENT_NAME);
        for (int i = 0; i < list.getLength(); i++) {
            Pair<SecuritySettingPlugin, Map<String, String>> securityItem = parseSecuritySettingPlugins(list.item(i));
            config.addSecuritySettingPlugin(securityItem.getA().init(securityItem.getB()));
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SecuritySettingPlugin(org.apache.activemq.artemis.core.server.SecuritySettingPlugin) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 4 with SecuritySettingPlugin

use of org.apache.activemq.artemis.core.server.SecuritySettingPlugin in project activemq-artemis by apache.

the class FileConfigurationTest method testSecuritySettingPlugin.

@Test
public void testSecuritySettingPlugin() throws Exception {
    FileConfiguration fc = new FileConfiguration();
    FileDeploymentManager deploymentManager = new FileDeploymentManager("securitySettingPlugin.xml");
    deploymentManager.addDeployable(fc);
    deploymentManager.readConfiguration();
    List<SecuritySettingPlugin> securitySettingPlugins = fc.getSecuritySettingPlugins();
    SecuritySettingPlugin securitySettingPlugin = securitySettingPlugins.get(0);
    assertTrue(securitySettingPlugin instanceof LegacyLDAPSecuritySettingPlugin);
    LegacyLDAPSecuritySettingPlugin legacyLDAPSecuritySettingPlugin = (LegacyLDAPSecuritySettingPlugin) securitySettingPlugin;
    assertEquals(legacyLDAPSecuritySettingPlugin.getInitialContextFactory(), "testInitialContextFactory");
    assertEquals(legacyLDAPSecuritySettingPlugin.getConnectionURL(), "testConnectionURL");
    assertEquals(legacyLDAPSecuritySettingPlugin.getConnectionUsername(), "testConnectionUsername");
    assertEquals(legacyLDAPSecuritySettingPlugin.getConnectionPassword(), "testConnectionPassword");
    assertEquals(legacyLDAPSecuritySettingPlugin.getConnectionProtocol(), "testConnectionProtocol");
    assertEquals(legacyLDAPSecuritySettingPlugin.getAuthentication(), "testAuthentication");
    assertEquals(legacyLDAPSecuritySettingPlugin.getDestinationBase(), "testDestinationBase");
    assertEquals(legacyLDAPSecuritySettingPlugin.getFilter(), "testFilter");
    assertEquals(legacyLDAPSecuritySettingPlugin.getRoleAttribute(), "testRoleAttribute");
    assertEquals(legacyLDAPSecuritySettingPlugin.getAdminPermissionValue(), "testAdminPermissionValue");
    assertEquals(legacyLDAPSecuritySettingPlugin.getReadPermissionValue(), "testReadPermissionValue");
    assertEquals(legacyLDAPSecuritySettingPlugin.getWritePermissionValue(), "testWritePermissionValue");
    assertEquals(legacyLDAPSecuritySettingPlugin.isEnableListener(), false);
}
Also used : SecuritySettingPlugin(org.apache.activemq.artemis.core.server.SecuritySettingPlugin) LegacyLDAPSecuritySettingPlugin(org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin) FileDeploymentManager(org.apache.activemq.artemis.core.config.FileDeploymentManager) LegacyLDAPSecuritySettingPlugin(org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin) Test(org.junit.Test)

Aggregations

SecuritySettingPlugin (org.apache.activemq.artemis.core.server.SecuritySettingPlugin)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 HashMap (java.util.HashMap)2 NodeList (org.w3c.dom.NodeList)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ActiveMQDeleteAddressException (org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)1 Pair (org.apache.activemq.artemis.api.core.Pair)1 FileDeploymentManager (org.apache.activemq.artemis.core.config.FileDeploymentManager)1 ActiveMQComponent (org.apache.activemq.artemis.core.server.ActiveMQComponent)1 ServiceComponent (org.apache.activemq.artemis.core.server.ServiceComponent)1 LegacyLDAPSecuritySettingPlugin (org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1