org.apache.activemq.artemis.core.server.SecuritySettingPlugin

Here are the examples of the java api class org.apache.activemq.artemis.core.server.SecuritySettingPlugin taken from open source projects.

1. FileConfigurationTest#testSecuritySettingPlugin()

Project: activemq-artemis
File: FileConfigurationTest.java
@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);
}

2. FileConfigurationParser#parseSecuritySettingPlugins()

Project: activemq-artemis
File: FileConfigurationParser.java
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);
}

3. ActiveMQServerImpl#deploySecurityFromConfiguration()

Project: activemq-artemis
File: ActiveMQServerImpl.java
private void deploySecurityFromConfiguration() {
    for (Map.Entry<String, Set<Role>> entry : configuration.getSecurityRoles().entrySet()) {
        securityRepository.addMatch(entry.getKey(), entry.getValue(), true);
    }
    for (SecuritySettingPlugin securitySettingPlugin : configuration.getSecuritySettingPlugins()) {
        securitySettingPlugin.setSecurityRepository(securityRepository);
    }
}

4. ActiveMQServerImpl#stop()

Project: activemq-artemis
File: ActiveMQServerImpl.java
/**
    * 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) {
    synchronized (this) {
        if (state == SERVER_STATE.STOPPED || state == SERVER_STATE.STOPPING) {
            return;
        }
        state = SERVER_STATE.STOPPING;
        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);
        } 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) {
        threadPool.shutdown();
        try {
            if (!threadPool.awaitTermination(10, TimeUnit.SECONDS)) {
                ActiveMQServerLogger.LOGGER.timedOutStoppingThreadpool(threadPool);
                for (Runnable r : threadPool.shutdownNow()) {
                    logger.debug("Cancelled the execution of " + r);
                }
            }
        } catch (InterruptedException e) {
            ActiveMQServerLogger.LOGGER.interruptWhilstStoppingComponent(threadPool.getClass().getName());
        }
    }
    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();
    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 (backupActivationThread != null) {
        try {
            backupActivationThread.join(30000);
        } catch (InterruptedException e) {
            ActiveMQServerLogger.LOGGER.interruptWhilstStoppingComponent(backupActivationThread.getClass().getName());
        }
        if (backupActivationThread.isAlive()) {
            ActiveMQServerLogger.LOGGER.backupActivationDidntFinish(this);
            backupActivationThread.interrupt();
        }
    }
    stopComponent(nodeManager);
    nodeManager = null;
    addressSettingsRepository.clearListeners();
    addressSettingsRepository.clearCache();
    scaledDownNodeIDs.clear();
    if (identity != null) {
        ActiveMQServerLogger.LOGGER.serverStopped("identity=" + identity + ",version=" + getVersion().getFullVersion(), tempNodeID, getUptime());
    } else {
        ActiveMQServerLogger.LOGGER.serverStopped(getVersion().getFullVersion(), tempNodeID, getUptime());
    }
}

5. ConfigurationImpl#getSecurityRoles()

Project: activemq-artemis
File: ConfigurationImpl.java
@Override
public Map<String, Set<Role>> getSecurityRoles() {
    for (SecuritySettingPlugin securitySettingPlugin : securitySettingPlugins) {
        Map<String, Set<Role>> settings = securitySettingPlugin.getSecurityRoles();
        if (settings != null) {
            securitySettings.putAll(settings);
        }
    }
    return securitySettings;
}