From 65cba5397294ddd5349bdb9837c4a10d91f2ca0b Mon Sep 17 00:00:00 2001 From: Robert Gemmell Date: Fri, 12 Oct 2012 11:44:13 +0000 Subject: QPID-4335, QPID-4353: Refactored broker plugins to use simplified ServiceLoader-based model rather than embedding Felix to use OSGi. Removed the ability to reload security configuration because this feature is not very useful in its current form and was making our code hard to refactor. Modified all tests to use jars rather than classes. This makes them closer to real-world deployments, e.g. the META-INF/services file is read from within the jar. Also moved various system tests from their respective modules into "systests". This removes the need for most modules to depend on systests, thus simplifying our dependency graph. Applied patch from myself, Keith Wall and Phil Harvey git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1397519 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/qpid/server/Broker.java | 5 +- .../java/org/apache/qpid/server/BrokerOptions.java | 13 - .../server/configuration/ConfigurationManager.java | 54 --- .../server/configuration/QueueConfiguration.java | 4 +- .../server/configuration/ServerConfiguration.java | 90 +--- .../configuration/VirtualHostConfiguration.java | 9 +- .../plugins/AbstractConfiguration.java | 329 ++++++++++++++ .../configuration/plugins/ConfigurationPlugin.java | 493 --------------------- .../plugins/ConfigurationPluginFactory.java | 38 -- .../qpid/server/exchange/AbstractExchange.java | 1 + .../server/exchange/DefaultExchangeFactory.java | 95 ++-- .../server/exchange/DefaultExchangeRegistry.java | 1 + .../qpid/server/exchange/DirectExchange.java | 42 +- .../qpid/server/exchange/DirectExchangeType.java | 33 ++ .../org/apache/qpid/server/exchange/Exchange.java | 1 + .../qpid/server/exchange/ExchangeFactory.java | 4 +- .../qpid/server/exchange/ExchangeInitialiser.java | 1 + .../apache/qpid/server/exchange/ExchangeType.java | 37 -- .../qpid/server/exchange/FanoutExchange.java | 36 +- .../qpid/server/exchange/FanoutExchangeType.java | 31 ++ .../qpid/server/exchange/HeadersExchange.java | 36 +- .../qpid/server/exchange/HeadersExchangeType.java | 32 ++ .../apache/qpid/server/exchange/TopicExchange.java | 37 +- .../qpid/server/exchange/TopicExchangeType.java | 33 ++ .../server/management/plugin/ManagementPlugin.java | 25 ++ .../qpid/server/model/adapter/ExchangeAdapter.java | 2 +- .../server/model/adapter/VirtualHostAdapter.java | 2 +- .../qpid/server/plugin/AccessControlFactory.java | 27 ++ .../plugin/AuthenticationManagerFactory.java | 28 ++ .../apache/qpid/server/plugin/ExchangeType.java | 36 ++ .../qpid/server/plugin/GroupManagerFactory.java | 27 ++ .../qpid/server/plugin/ManagementFactory.java | 28 ++ .../qpid/server/plugin/QpidServiceLoader.java | 72 +++ .../org/apache/qpid/server/plugins/Activator.java | 51 --- .../qpid/server/plugins/OsgiSystemPackageUtil.java | 91 ---- .../server/plugins/OsgiSystemPackages.properties | 135 ------ .../org/apache/qpid/server/plugins/Plugin.java | 32 -- .../apache/qpid/server/plugins/PluginFactory.java | 32 -- .../apache/qpid/server/plugins/PluginManager.java | 392 ---------------- .../apache/qpid/server/queue/SimpleAMQQueue.java | 4 +- .../qpid/server/registry/ApplicationRegistry.java | 171 +++---- .../ConfigurationFileApplicationRegistry.java | 42 -- .../qpid/server/registry/IApplicationRegistry.java | 6 - .../qpid/server/security/AbstractPlugin.java | 57 --- .../qpid/server/security/AbstractProxyPlugin.java | 122 ----- .../apache/qpid/server/security/AccessControl.java | 45 ++ .../qpid/server/security/SecurityManager.java | 179 +++----- .../qpid/server/security/SecurityPlugin.java | 47 -- .../server/security/SecurityPluginActivator.java | 75 ---- .../server/security/SecurityPluginFactory.java | 30 -- .../security/access/plugins/BasicPlugin.java | 43 -- .../security/access/plugins/LegacyAccess.java | 86 ---- .../security/auth/database/PrincipalDatabase.java | 2 + .../auth/database/PropertiesPrincipalDatabase.java | 169 ------- .../manager/AnonymousAuthenticationManager.java | 80 +--- .../AnonymousAuthenticationManagerFactory.java | 38 ++ .../auth/manager/AuthenticationManager.java | 3 +- .../AuthenticationManagerPluginFactory.java | 32 -- .../manager/AuthenticationManagerRegistry.java | 70 +-- .../manager/ExternalAuthenticationManager.java | 82 +--- .../ExternalAuthenticationManagerFactory.java | 38 ++ .../manager/KerberosAuthenticationManager.java | 80 +--- .../KerberosAuthenticationManagerFactory.java | 37 ++ .../PrincipalDatabaseAuthManagerFactory.java | 92 ++++ .../PrincipalDatabaseAuthenticationManager.java | 241 +--------- .../manager/SimpleLDAPAuthenticationManager.java | 143 +----- .../SimpleLDAPAuthenticationManagerFactory.java | 50 +++ .../auth/sasl/crammd5/CRAMMD5HexInitialiser.java | 6 + .../server/security/group/FileGroupManager.java | 108 +---- .../security/group/FileGroupManagerFactory.java | 65 +++ .../qpid/server/security/group/GroupManager.java | 4 +- .../security/group/GroupManagerPluginFactory.java | 27 -- .../qpid/server/signal/SignalHandlerTask.java | 89 ---- .../server/transport/ServerSessionDelegate.java | 2 +- .../qpid/server/virtualhost/VirtualHostImpl.java | 36 +- .../plugins/VirtualHostHouseKeepingPlugin.java | 61 --- .../virtualhost/plugins/VirtualHostPlugin.java | 42 -- .../plugins/VirtualHostPluginFactory.java | 28 -- ...qpid.server.plugin.AuthenticationManagerFactory | 5 + .../org.apache.qpid.server.plugin.ExchangeType | 4 + ...g.apache.qpid.server.plugin.GroupManagerFactory | 1 + 81 files changed, 1380 insertions(+), 3597 deletions(-) delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ManagementFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java create mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManagerPluginFactory.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java delete mode 100644 qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java create mode 100644 qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory create mode 100644 qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType create mode 100644 qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory (limited to 'qpid/java/broker/src/main') diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java index afb8a0029b..3848c97a99 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java @@ -41,7 +41,6 @@ import org.apache.qpid.server.logging.messages.BrokerMessages; import org.apache.qpid.server.protocol.AmqpProtocolVersion; import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory; import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; import org.apache.qpid.server.transport.QpidAcceptor; import org.apache.qpid.ssl.SSLContextFactory; import org.apache.qpid.transport.NetworkTransportConfiguration; @@ -124,8 +123,8 @@ public class Broker configureLogging(logConfigFile, options.getLogWatchFrequency()); - ConfigurationFileApplicationRegistry config = new ConfigurationFileApplicationRegistry(configFile, options.getBundleContext()); - ServerConfiguration serverConfig = config.getConfiguration(); + ServerConfiguration serverConfig = new ServerConfiguration(configFile); + ApplicationRegistry config = new ApplicationRegistry(serverConfig); if (options.getQpidWork() != null) { serverConfig.setQpidWork(options.getQpidWork()); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java index 434d40d557..1a00467c3d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java @@ -20,8 +20,6 @@ */ package org.apache.qpid.server; -import org.osgi.framework.BundleContext; - import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -45,7 +43,6 @@ public class BrokerOptions private String _bind; private Integer _jmxPortRegistryServer; private Integer _jmxPortConnectorServer; - private BundleContext _bundleContext; private Integer _logWatchFrequency = 0; private String _qpidWorkFolder; @@ -156,16 +153,6 @@ public class BrokerOptions _logWatchFrequency = logWatchFrequency; } - public BundleContext getBundleContext() - { - return _bundleContext ; - } - - public void setBundleContext(final BundleContext bundleContext) - { - _bundleContext = bundleContext; - } - public Set getIncludedPorts(final ProtocolInclusion includeProtocol) { final Set includedPorts = _inclusionMap.get(includeProtocol); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java deleted file mode 100644 index 06402fa646..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.configuration; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; -import org.apache.qpid.server.registry.ApplicationRegistry; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class ConfigurationManager -{ - public List getConfigurationPlugins(String configurationElement, Configuration configuration) throws ConfigurationException - { - List plugins = new ArrayList(); - Map, ConfigurationPluginFactory> factories = - ApplicationRegistry.getInstance().getPluginManager().getConfigurationPlugins(); - - for (Entry, ConfigurationPluginFactory> entry : factories.entrySet()) - { - if (entry.getKey().contains(configurationElement)) - { - ConfigurationPluginFactory factory = entry.getValue(); - plugins.add(factory.newInstance(configurationElement, configuration)); - } - } - - return plugins; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java index 38ec5fe53d..06691d8659 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java @@ -24,11 +24,11 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; +import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; import java.util.List; -public class QueueConfiguration extends ConfigurationPlugin +public class QueueConfiguration extends AbstractConfiguration { private String _name; private VirtualHostConfiguration _vHostConfig; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java index d70cec58e0..62ed2e44f4 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java @@ -38,18 +38,14 @@ import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.SystemConfiguration; import org.apache.commons.configuration.XMLConfiguration; import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; +import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; import org.apache.qpid.server.exchange.DefaultExchangeFactory; import org.apache.qpid.server.protocol.AmqpProtocolVersion; import org.apache.qpid.server.queue.AMQQueueFactory; import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.signal.SignalHandlerTask; -import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; - import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; -public class ServerConfiguration extends ConfigurationPlugin +public class ServerConfiguration extends AbstractConfiguration { protected static final Logger _logger = Logger.getLogger(ServerConfiguration.class); @@ -73,8 +69,6 @@ public class ServerConfiguration extends ConfigurationPlugin public static final String QPID_HOME = "QPID_HOME"; public static final String QPID_WORK = "QPID_WORK"; public static final String LIB_DIR = "lib"; - public static final String PLUGIN_DIR = "plugins"; - public static final String CACHE_DIR = "cache"; private Map _virtualHosts = new HashMap(); @@ -157,39 +151,6 @@ public class ServerConfiguration extends ConfigurationPlugin { this(parseConfig(configurationURL)); _configFile = configurationURL; - - if(!Boolean.getBoolean(SKIP_SIGHUP_HANDLER_REGISTRATION)) - { - registerSigHupHandler(); - } - else - { - _logger.info("Skipping registration of Signal HUP handler."); - } - } - - private void registerSigHupHandler() - { - SignalHandlerTask hupReparseTask = new SignalHandlerTask() - { - public void handle() - { - try - { - reparseConfigFileSecuritySections(); - } - catch (ConfigurationException e) - { - _logger.error("Could not reload configuration file security sections", e); - } - } - }; - - if(!hupReparseTask.register("HUP")) - { - _logger.info("Unable to register Signal HUP handler to reload security configuration."); - _logger.info("Signal HUP not supported for this OS / JVM combination - " + SignalHandlerTask.getPlatformDescription()); - } } /** @@ -219,9 +180,6 @@ public class ServerConfiguration extends ConfigurationPlugin * Processes this configuration and setups any VirtualHosts defined in the * configuration. * - * This has been separated from the constructor to allow the PluginManager - * time to be created and provide plugins to the ConfigurationManager for - * processing here. *

* Called by {@link ApplicationRegistry#initialise()}. *

@@ -497,38 +455,6 @@ public class ServerConfiguration extends ConfigurationPlugin return _configFile == null ? "" : _configFile.getAbsolutePath(); } - public void reparseConfigFileSecuritySections() throws ConfigurationException - { - if (_configFile != null) - { - Configuration newConfig = parseConfig(_configFile); - setConfiguration("", newConfig); - ApplicationRegistry.getInstance().getSecurityManager().configureHostPlugins(this); - - // Reload virtualhosts from correct location - Configuration newVhosts; - if (_vhostsFile == null) - { - newVhosts = newConfig.subset("virtualhosts"); - } - else - { - newVhosts = parseConfig(_vhostsFile); - } - - VirtualHostRegistry vhostRegistry = ApplicationRegistry.getInstance().getVirtualHostRegistry(); - for (String hostName : _virtualHosts.keySet()) - { - VirtualHost vhost = vhostRegistry.getVirtualHost(hostName); - Configuration vhostConfig = newVhosts.subset("virtualhost." + escapeTagName(hostName)); - vhost.getConfiguration().setConfiguration("virtualhosts.virtualhost", vhostConfig); - vhost.getSecurityManager().configureGlobalPlugins(this); - vhost.getSecurityManager().configureHostPlugins(vhost.getConfiguration()); - } - - _logger.warn(SECURITY_CONFIG_RELOADED); - } - } public String getQpidWork() { @@ -643,16 +569,6 @@ public class ServerConfiguration extends ConfigurationPlugin return _virtualHosts.keySet().toArray(new String[_virtualHosts.size()]); } - public String getPluginDirectory() - { - return getStringValue("plugin-directory"); - } - - public String getCacheDirectory() - { - return getStringValue("cache-directory"); - } - public VirtualHostConfiguration getVirtualHostConfig(String name) { return _virtualHosts.get(name); @@ -700,6 +616,7 @@ public class ServerConfiguration extends ConfigurationPlugin public String getManagementKeyStorePath() { + // note difference in capitalisation used in fallback final String fallback = getStringValue("management.ssl.keystorePath"); return getStringValue("management.ssl.keyStorePath", fallback); } @@ -711,6 +628,7 @@ public class ServerConfiguration extends ConfigurationPlugin public String getManagementKeyStorePassword() { + // note difference in capitalisation used in fallback final String fallback = getStringValue("management.ssl.keystorePassword"); return getStringValue("management.ssl.keyStorePassword", fallback); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java index 0d59118647..a14977ec1b 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java @@ -24,7 +24,7 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; +import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.store.MemoryMessageStore; @@ -33,7 +33,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -public class VirtualHostConfiguration extends ConfigurationPlugin +public class VirtualHostConfiguration extends AbstractConfiguration { private final String _name; private final Map _queues = new HashMap(); @@ -85,11 +85,6 @@ public class VirtualHostConfiguration extends ConfigurationPlugin return getLongValue("housekeeping.checkPeriod", ApplicationRegistry.getInstance().getConfiguration().getHousekeepingCheckPeriod()); } - public List getCustomExchanges() - { - return getListValue("custom-exchanges.class-name"); - } - public Configuration getStoreConfiguration() { return getConfig().subset("store"); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java new file mode 100644 index 0000000000..0e7c19df87 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java @@ -0,0 +1,329 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.configuration.plugins; + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.ConversionException; +import org.apache.log4j.Logger; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Set; + +public abstract class AbstractConfiguration +{ + protected static final Logger _logger = Logger.getLogger(AbstractConfiguration.class); + + private Configuration _config; + + /** + * The Elements that this Plugin can process. + * + * For a Queues plugin that would be a list containing: + *

    + *
  • queue - the queue entries + *
  • the alerting values for defaults + *
  • exchange - the default exchange + *
  • durable - set the default durablity + *
+ */ + abstract public String[] getElementsProcessed(); + + /** Performs configuration validation. */ + public void validateConfiguration() throws ConfigurationException + { + // Override in sub-classes + } + + public Configuration getConfig() + { + return _config; + } + + /** + * Sets the configuration for this plugin + * + * @param path + * @param configuration the configuration for this plugin. + */ + public void setConfiguration(String path, Configuration configuration) throws ConfigurationException + { + _config = configuration; + + // Extract a list of elements for processing + Iterator keys = configuration.getKeys(); + + Set elements = new HashSet(); + while (keys.hasNext()) + { + String key = (String) keys.next(); + + int elementNameIndex = key.indexOf("."); + + String element = key.trim(); + if (elementNameIndex != -1) + { + element = key.substring(0, elementNameIndex).trim(); + } + + // Trim any element properties + elementNameIndex = element.indexOf("["); + if (elementNameIndex > 0) + { + element = element.substring(0, elementNameIndex).trim(); + } + + elements.add(element); + } + + //Remove the items we already expect in the configuration + for (String tag : getElementsProcessed()) + { + + // Work round the issue with Commons configuration. + // With an XMLConfiguration the key will be [@property] + // but with a CompositeConfiguration it will be @property]. + // Hide this issue from our users so when/if we change the + // configuration they don't have to. + int bracketIndex = tag.indexOf("["); + if (bracketIndex != -1) + { + tag = tag.substring(bracketIndex + 1, tag.length()); + } + + elements.remove(tag); + } + + if (_logger.isInfoEnabled()) + { + if (!elements.isEmpty()) + { + _logger.info("Elements to lookup:" + path); + for (String tag : elements) + { + _logger.info("Tag:'" + tag + "'"); + } + } + } + + validateConfiguration(); + } + + /** Helper method to print out list of keys in a {@link Configuration}. */ + public static final void showKeys(Configuration config) + { + if (config.isEmpty()) + { + _logger.info("Configuration is empty"); + } + else + { + Iterator keys = config.getKeys(); + while (keys.hasNext()) + { + String key = (String) keys.next(); + _logger.info("Configuration key: " + key); + } + } + } + + protected boolean hasConfiguration() + { + return _config != null; + } + + /// Getters + + protected double getDoubleValue(String property) + { + return getDoubleValue(property, 0.0); + } + + protected double getDoubleValue(String property, double defaultValue) + { + return _config.getDouble(property, defaultValue); + } + + protected long getLongValue(String property) + { + return getLongValue(property, 0); + } + + protected long getLongValue(String property, long defaultValue) + { + return _config.getLong(property, defaultValue); + } + + protected int getIntValue(String property) + { + return getIntValue(property, 0); + } + + protected int getIntValue(String property, int defaultValue) + { + return _config.getInt(property, defaultValue); + } + + protected String getStringValue(String property) + { + return getStringValue(property, null); + } + + protected String getStringValue(String property, String defaultValue) + { + return _config.getString(property, defaultValue); + } + + protected boolean getBooleanValue(String property) + { + return getBooleanValue(property, false); + } + + protected boolean getBooleanValue(String property, boolean defaultValue) + { + return _config.getBoolean(property, defaultValue); + } + + protected List getListValue(String property) + { + return getListValue(property, Collections.EMPTY_LIST); + } + + protected List getListValue(String property, List defaultValue) + { + return _config.getList(property, defaultValue); + } + + /// Validation Helpers + + protected boolean contains(String property) + { + return _config.getProperty(property) != null; + } + + /** + * Provide mechanism to validate Configuration contains a Postiive Long Value + * + * @param property + * + * @throws ConfigurationException + */ + protected void validatePositiveLong(String property) throws ConfigurationException + { + try + { + if (!containsPositiveLong(property)) + { + throw new ConfigurationException(this.getClass().getSimpleName() + + ": '" + property + + "' must be a Positive Long value."); + } + } + catch (Exception e) + { + Throwable last = e; + + // Find the first cause + if (e instanceof ConversionException) + { + Throwable t = e.getCause(); + while (t != null) + { + last = t; + t = last.getCause(); + } + } + + throw new ConfigurationException(this.getClass().getSimpleName() + + ": unable to configure invalid " + + property + ":" + + _config.getString(property), + last); + } + } + + protected boolean containsLong(String property) + { + try + { + _config.getLong(property); + return true; + } + catch (NoSuchElementException e) + { + return false; + } + } + + protected boolean containsPositiveLong(String property) + { + try + { + long value = _config.getLong(property); + return value > 0; + } + catch (NoSuchElementException e) + { + return false; + } + + } + + protected boolean containsInt(String property) + { + try + { + _config.getInt(property); + return true; + } + catch (NoSuchElementException e) + { + return false; + } + } + + protected boolean containsBoolean(String property) + { + try + { + _config.getBoolean(property); + return true; + } + catch (NoSuchElementException e) + { + return false; + } + } + + public String escapeTagName(String name) + { + return name.replaceAll("\\.", "\\.\\."); + } + + protected void setConfig(Configuration config) + { + _config = config; + } +} + + diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java deleted file mode 100644 index c7f600df8a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.configuration.plugins; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.ConversionException; -import org.apache.log4j.Logger; - -import org.apache.qpid.server.configuration.ConfigurationManager; -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.registry.IApplicationRegistry; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; - -public abstract class ConfigurationPlugin -{ - protected static final Logger _logger = Logger.getLogger(ConfigurationPlugin.class); - - private Map - _pluginConfiguration = new HashMap(); - - private Configuration _config; - - /** - * The Elements that this Plugin can process. - * - * For a Queues plugin that would be a list containing: - *
    - *
  • queue - the queue entries - *
  • the alerting values for defaults - *
  • exchange - the default exchange - *
  • durable - set the default durablity - *
- */ - abstract public String[] getElementsProcessed(); - - /** Performs configuration validation. */ - public void validateConfiguration() throws ConfigurationException - { - // Override in sub-classes - } - - public Configuration getConfig() - { - return _config; - } - - public C getConfiguration(String plugin) - { - return (C) _pluginConfiguration.get(plugin); - } - - /** - * Sets the configuration for this plugin - * - * @param path - * @param configuration the configuration for this plugin. - */ - public void setConfiguration(String path, Configuration configuration) throws ConfigurationException - { - _config = configuration; - - // Extract a list of elements for processing - Iterator keys = configuration.getKeys(); - - Set elements = new HashSet(); - while (keys.hasNext()) - { - String key = (String) keys.next(); - - int elementNameIndex = key.indexOf("."); - - String element = key.trim(); - if (elementNameIndex != -1) - { - element = key.substring(0, elementNameIndex).trim(); - } - - // Trim any element properties - elementNameIndex = element.indexOf("["); - if (elementNameIndex > 0) - { - element = element.substring(0, elementNameIndex).trim(); - } - - elements.add(element); - } - - //Remove the items we already expect in the configuration - for (String tag : getElementsProcessed()) - { - - // Work round the issue with Commons configuration. - // With an XMLConfiguration the key will be [@property] - // but with a CompositeConfiguration it will be @property]. - // Hide this issue from our users so when/if we change the - // configuration they don't have to. - int bracketIndex = tag.indexOf("["); - if (bracketIndex != -1) - { - tag = tag.substring(bracketIndex + 1, tag.length()); - } - - elements.remove(tag); - } - - if (_logger.isInfoEnabled()) - { - if (!elements.isEmpty()) - { - _logger.info("Elements to lookup:" + path); - for (String tag : elements) - { - _logger.info("Tag:'" + tag + "'"); - } - } - } - - offerRemainingConfigurationToOtherPlugins(path, configuration, elements); - - validateConfiguration(); - } - - private void offerRemainingConfigurationToOtherPlugins(String path, - Configuration configuration, Set elements) throws ConfigurationException - { - final IApplicationRegistry appRegistry = safeGetApplicationRegistryInstance(); - - if (appRegistry == null) - { - // We see this happen during shutdown due to asynchronous reconfig using IO threads. - // Need to remove the responsibility for offering configuration to other class. - _logger.info("Cannot offer remaining config to other plugins, can't find app registry"); - return; - } - - final ConfigurationManager configurationManager = appRegistry.getConfigurationManager(); - // Process the elements in the configuration - for (String element : elements) - { - Configuration handled = element.length() == 0 ? configuration : configuration.subset(element); - - String configurationElement = element; - if (path.length() > 0) - { - configurationElement = path + "." + configurationElement; - } - - List handlers = configurationManager.getConfigurationPlugins(configurationElement, handled); - - if(_logger.isDebugEnabled()) - { - _logger.debug("For '" + element + "' found handlers (" + handlers.size() + "):" + handlers); - } - - for (ConfigurationPlugin plugin : handlers) - { - _pluginConfiguration.put(plugin.getClass().getName(), plugin); - } - } - } - - private IApplicationRegistry safeGetApplicationRegistryInstance() - { - try - { - return ApplicationRegistry.getInstance(); - } - catch (IllegalStateException ise) - { - return null; - } - } - - /** Helper method to print out list of keys in a {@link Configuration}. */ - public static final void showKeys(Configuration config) - { - if (config.isEmpty()) - { - _logger.info("Configuration is empty"); - } - else - { - Iterator keys = config.getKeys(); - while (keys.hasNext()) - { - String key = (String) keys.next(); - _logger.info("Configuration key: " + key); - } - } - } - - protected boolean hasConfiguration() - { - return _config != null; - } - - /// Getters - - protected double getDoubleValue(String property) - { - return getDoubleValue(property, 0.0); - } - - protected double getDoubleValue(String property, double defaultValue) - { - return _config.getDouble(property, defaultValue); - } - - protected long getLongValue(String property) - { - return getLongValue(property, 0); - } - - protected long getLongValue(String property, long defaultValue) - { - return _config.getLong(property, defaultValue); - } - - protected int getIntValue(String property) - { - return getIntValue(property, 0); - } - - protected int getIntValue(String property, int defaultValue) - { - return _config.getInt(property, defaultValue); - } - - protected String getStringValue(String property) - { - return getStringValue(property, null); - } - - protected String getStringValue(String property, String defaultValue) - { - return _config.getString(property, defaultValue); - } - - protected boolean getBooleanValue(String property) - { - return getBooleanValue(property, false); - } - - protected boolean getBooleanValue(String property, boolean defaultValue) - { - return _config.getBoolean(property, defaultValue); - } - - protected List getListValue(String property) - { - return getListValue(property, Collections.EMPTY_LIST); - } - - protected List getListValue(String property, List defaultValue) - { - return _config.getList(property, defaultValue); - } - - /// Validation Helpers - - protected boolean contains(String property) - { - return _config.getProperty(property) != null; - } - - /** - * Provide mechanism to validate Configuration contains a Postiive Long Value - * - * @param property - * - * @throws ConfigurationException - */ - protected void validatePositiveLong(String property) throws ConfigurationException - { - try - { - if (!containsPositiveLong(property)) - { - throw new ConfigurationException(this.getClass().getSimpleName() - + ": '" + property + - "' must be a Positive Long value."); - } - } - catch (Exception e) - { - Throwable last = e; - - // Find the first cause - if (e instanceof ConversionException) - { - Throwable t = e.getCause(); - while (t != null) - { - last = t; - t = last.getCause(); - } - } - - throw new ConfigurationException(this.getClass().getSimpleName() + - ": unable to configure invalid " + - property + ":" + - _config.getString(property), - last); - } - } - - protected boolean containsLong(String property) - { - try - { - _config.getLong(property); - return true; - } - catch (NoSuchElementException e) - { - return false; - } - } - - protected boolean containsPositiveLong(String property) - { - try - { - long value = _config.getLong(property); - return value > 0; - } - catch (NoSuchElementException e) - { - return false; - } - - } - - protected boolean containsInt(String property) - { - try - { - _config.getInt(property); - return true; - } - catch (NoSuchElementException e) - { - return false; - } - } - - protected boolean containsBoolean(String property) - { - try - { - _config.getBoolean(property); - return true; - } - catch (NoSuchElementException e) - { - return false; - } - } - - /** - * Given another configuration merge the configuration into our own config - * - * The new values being merged in will take precedence over existing values. - * - * In the simplistic case this means something like: - * - * So if we have configuration set - * name = 'fooo' - * - * And the new configuration contains a name then that will be reset. - * name = 'new' - * - * However this plugin will simply contain other plugins so the merge will - * be called until we end up at a base plugin that understand how to merge - * items. i.e Alerting values. Where the provided configuration will take - * precedence. - * - * @param configuration the config to merge in to our own. - */ - public void addConfiguration(ConfigurationPlugin configuration) - { - // If given configuration is null then there is nothing to process. - if (configuration == null) - { - return; - } - - // Merge all the sub configuration items - for (Map.Entry newPlugins : configuration._pluginConfiguration.entrySet()) - { - String key = newPlugins.getKey(); - ConfigurationPlugin config = newPlugins.getValue(); - - if (_pluginConfiguration.containsKey(key)) - { - //Merge the configuration if we already have this type of config - _pluginConfiguration.get(key).mergeConfiguration(config); - } - else - { - //otherwise just add it to our config. - _pluginConfiguration.put(key, config); - } - } - - //Merge the configuration itself - String key = configuration.getClass().getName(); - if (_pluginConfiguration.containsKey(key)) - { - //Merge the configuration if we already have this type of config - _pluginConfiguration.get(key).mergeConfiguration(configuration); - } - else - { - //If we are adding a configuration of our own type then merge - if (configuration.getClass() == this.getClass()) - { - mergeConfiguration(configuration); - } - else - { - // just store this in case someone else needs it. - _pluginConfiguration.put(key, configuration); - } - - } - - } - - protected void mergeConfiguration(ConfigurationPlugin configuration) - { - _config = configuration.getConfig(); - } - - public String toString() - { - StringBuilder sb = new StringBuilder(); - - sb.append("\n").append(getClass().getSimpleName()); - sb.append("=[ (").append(formatToString()).append(")"); - - for(Map.Entry item : _pluginConfiguration.entrySet()) - { - sb.append("\n").append(item.getValue()); - } - - sb.append("]\n"); - - return sb.toString(); - } - - public String formatToString() - { - return super.toString(); - } - - public String escapeTagName(String name) - { - return name.replaceAll("\\.", "\\.\\."); - } - - protected void setConfig(Configuration config) - { - _config = config; - } -} - - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java deleted file mode 100644 index fa41f3ef06..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.configuration.plugins; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import java.util.List; - -public interface ConfigurationPluginFactory -{ - /** - * The Parent paths of the configuration that this plugin supports. - * - * For example, {@code queue} elements have a parent path of {@code virtualhosts.virtualhost}. - */ - public List getParentPaths(); - - public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java index 36cdfee6cc..246e056f0b 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java @@ -28,6 +28,7 @@ import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.logging.messages.ExchangeMessages; import org.apache.qpid.server.logging.subjects.ExchangeLogSubject; import org.apache.qpid.server.message.InboundMessage; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.BaseQueue; import org.apache.qpid.server.queue.QueueRegistry; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java index 3fd8da9b6f..5e6e36d330 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java @@ -27,9 +27,9 @@ import org.apache.qpid.AMQSecurityException; import org.apache.qpid.AMQUnknownExchangeType; import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.plugin.ExchangeType; +import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.virtualhost.VirtualHost; import java.util.ArrayList; @@ -40,31 +40,66 @@ import java.util.UUID; public class DefaultExchangeFactory implements ExchangeFactory { - private static final Logger _logger = Logger.getLogger(DefaultExchangeFactory.class); public static final String DEFAULT_DLE_NAME_SUFFIX = "_DLE"; - private Map> _exchangeClassMap = new HashMap>(); + private static final Logger LOGGER = Logger.getLogger(DefaultExchangeFactory.class); + + private static final AMQShortString[] BASE_EXCHANGE_TYPES = + new AMQShortString[]{ExchangeDefaults.DIRECT_EXCHANGE_CLASS, + ExchangeDefaults.FANOUT_EXCHANGE_CLASS, + ExchangeDefaults.HEADERS_EXCHANGE_CLASS, + ExchangeDefaults.TOPIC_EXCHANGE_CLASS}; + private final VirtualHost _host; + private Map> _exchangeClassMap = new HashMap>(); public DefaultExchangeFactory(VirtualHost host) { _host = host; - registerExchangeType(DirectExchange.TYPE); - registerExchangeType(TopicExchange.TYPE); - registerExchangeType(HeadersExchange.TYPE); - registerExchangeType(FanoutExchange.TYPE); + + @SuppressWarnings("rawtypes") + Iterable exchangeTypes = loadExchangeTypes(); + for (ExchangeType exchangeType : exchangeTypes) + { + AMQShortString typeName = exchangeType.getName(); + + if(LOGGER.isDebugEnabled()) + { + LOGGER.debug("Registering exchange type '" + typeName + "' using class '" + exchangeType.getClass().getName() + "'"); + } + + if(_exchangeClassMap.containsKey(typeName)) + { + ExchangeType existingType = _exchangeClassMap.get(typeName); + + throw new IllegalStateException("ExchangeType with type name '" + typeName + "' is already registered using class '" + + existingType.getClass().getName() + "', can not register class '" + + exchangeType.getClass().getName() + "'"); + } + + _exchangeClassMap.put(typeName, exchangeType); + } + + for(AMQShortString type : BASE_EXCHANGE_TYPES) + { + if(!_exchangeClassMap.containsKey(type)) + { + throw new IllegalStateException("Did not find expected exchange type: " + type.asString()); + } + } } - public void registerExchangeType(ExchangeType type) + @SuppressWarnings("rawtypes") + protected Iterable loadExchangeTypes() { - _exchangeClassMap.put(type.getName(), type); + return new QpidServiceLoader().atLeastOneInstanceOf(ExchangeType.class); } public Collection> getRegisteredTypes() { return _exchangeClassMap.values(); } - + public Collection> getPublicCreatableTypes() { Collection> publicTypes = @@ -114,42 +149,4 @@ public class DefaultExchangeFactory implements ExchangeFactory Exchange e = exchType.newInstance(id, _host, exchange, durable, ticket, autoDelete); return e; } - - public void initialise(VirtualHostConfiguration hostConfig) - { - - if (hostConfig == null) - { - return; - } - - for(Object className : hostConfig.getCustomExchanges()) - { - try - { - ExchangeType exchangeType = ApplicationRegistry.getInstance().getPluginManager().getExchanges().get(String.valueOf(className)); - if (exchangeType == null) - { - _logger.error("No such custom exchange class found: \""+String.valueOf(className)+"\""); - continue; - } - Class exchangeTypeClass = exchangeType.getClass(); - ExchangeType type = exchangeTypeClass.newInstance(); - registerExchangeType(type); - } - catch (ClassCastException classCastEx) - { - _logger.error("No custom exchange class: \""+String.valueOf(className)+"\" cannot be registered as it does not extend class \""+ExchangeType.class+"\""); - } - catch (IllegalAccessException e) - { - _logger.error("Cannot create custom exchange class: \""+String.valueOf(className)+"\"",e); - } - catch (InstantiationException e) - { - _logger.error("Cannot create custom exchange class: \""+String.valueOf(className)+"\"",e); - } - } - - } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java index 07813b073b..9cce8d640b 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java @@ -26,6 +26,7 @@ import org.apache.qpid.AMQSecurityException; import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.protocol.AMQConstant; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.virtualhost.VirtualHost; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java index 92326412c1..fc6ce15bc4 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java @@ -20,30 +20,22 @@ */ package org.apache.qpid.server.exchange; -import org.apache.log4j.Logger; - -import org.apache.qpid.AMQException; -import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.message.InboundMessage; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.virtualhost.VirtualHost; -import javax.management.JMException; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; public class DirectExchange extends AbstractExchange { - private static final Logger _logger = Logger.getLogger(DirectExchange.class); - private static final class BindingSet { private CopyOnWriteArraySet _bindings = new CopyOnWriteArraySet(); @@ -55,7 +47,6 @@ public class DirectExchange extends AbstractExchange recalculateQueues(); } - public synchronized void removeBinding(Binding binding) { _bindings.remove(binding); @@ -91,36 +82,7 @@ public class DirectExchange extends AbstractExchange private final ConcurrentHashMap _bindingsByKey = new ConcurrentHashMap(); - public static final ExchangeType TYPE = new ExchangeType() - { - - public AMQShortString getName() - { - return ExchangeDefaults.DIRECT_EXCHANGE_CLASS; - } - - public Class getExchangeClass() - { - return DirectExchange.class; - } - - public DirectExchange newInstance(UUID id, VirtualHost host, - AMQShortString name, - boolean durable, - int ticket, - boolean autoDelete) throws AMQException - { - DirectExchange exch = new DirectExchange(); - exch.initialise(id, host,name,durable,ticket,autoDelete); - return exch; - } - - public AMQShortString getDefaultExchangeName() - { - return ExchangeDefaults.DIRECT_EXCHANGE_NAME; - } - }; - + public static final ExchangeType TYPE = new DirectExchangeType(); public DirectExchange() { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java new file mode 100644 index 0000000000..11f16690ef --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java @@ -0,0 +1,33 @@ +package org.apache.qpid.server.exchange; + +import java.util.UUID; + +import org.apache.qpid.AMQException; +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.plugin.ExchangeType; +import org.apache.qpid.server.virtualhost.VirtualHost; + +public class DirectExchangeType implements ExchangeType +{ + public AMQShortString getName() + { + return ExchangeDefaults.DIRECT_EXCHANGE_CLASS; + } + + public DirectExchange newInstance(UUID id, VirtualHost host, + AMQShortString name, + boolean durable, + int ticket, + boolean autoDelete) throws AMQException + { + DirectExchange exch = new DirectExchange(); + exch.initialise(id, host,name,durable,ticket,autoDelete); + return exch; + } + + public AMQShortString getDefaultExchangeName() + { + return ExchangeDefaults.DIRECT_EXCHANGE_NAME; + } +} \ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java index 62d432cb68..4bafb04c33 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java @@ -27,6 +27,7 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.message.InboundMessage; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.BaseQueue; import org.apache.qpid.server.virtualhost.VirtualHost; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java index aae4ae89bb..e602d476d9 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java @@ -22,7 +22,7 @@ package org.apache.qpid.server.exchange; import org.apache.qpid.AMQException; import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.configuration.VirtualHostConfiguration; +import org.apache.qpid.server.plugin.ExchangeType; import java.util.Collection; import java.util.UUID; @@ -34,8 +34,6 @@ public interface ExchangeFactory int ticket) throws AMQException; - void initialise(VirtualHostConfiguration hostConfig); - Collection> getRegisteredTypes(); Collection> getPublicCreatableTypes(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java index ba4f57a8e0..edb476f3aa 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java @@ -24,6 +24,7 @@ package org.apache.qpid.server.exchange; import org.apache.qpid.AMQException; import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.store.DurableConfigurationStore; public class ExchangeInitialiser diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java deleted file mode 100644 index a01e41f039..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.exchange; - -import java.util.UUID; - -import org.apache.qpid.AMQException; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.virtualhost.VirtualHost; - - -public interface ExchangeType -{ - public AMQShortString getName(); - public Class getExchangeClass(); - public T newInstance(UUID id, VirtualHost host, AMQShortString name, - boolean durable, int ticket, boolean autoDelete) throws AMQException; - public AMQShortString getDefaultExchangeName(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java index 5f4998f77f..8c433ce985 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java @@ -22,19 +22,15 @@ package org.apache.qpid.server.exchange; import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.message.InboundMessage; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.virtualhost.VirtualHost; -import javax.management.JMException; import java.util.ArrayList; -import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; public class FanoutExchange extends AbstractExchange @@ -48,35 +44,7 @@ public class FanoutExchange extends AbstractExchange */ private final ConcurrentHashMap _queues = new ConcurrentHashMap(); - public static final ExchangeType TYPE = new ExchangeType() - { - - public AMQShortString getName() - { - return ExchangeDefaults.FANOUT_EXCHANGE_CLASS; - } - - public Class getExchangeClass() - { - return FanoutExchange.class; - } - - public FanoutExchange newInstance(UUID id, VirtualHost host, - AMQShortString name, - boolean durable, - int ticket, - boolean autoDelete) throws AMQException - { - FanoutExchange exch = new FanoutExchange(); - exch.initialise(id, host, name, durable, ticket, autoDelete); - return exch; - } - - public AMQShortString getDefaultExchangeName() - { - return ExchangeDefaults.FANOUT_EXCHANGE_NAME; - } - }; + public static final ExchangeType TYPE = new FanoutExchangeType(); public FanoutExchange() { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java new file mode 100644 index 0000000000..de70373703 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java @@ -0,0 +1,31 @@ +package org.apache.qpid.server.exchange; + +import java.util.UUID; + +import org.apache.qpid.AMQException; +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.plugin.ExchangeType; +import org.apache.qpid.server.virtualhost.VirtualHost; + +public class FanoutExchangeType implements ExchangeType +{ + public AMQShortString getName() + { + return ExchangeDefaults.FANOUT_EXCHANGE_CLASS; + } + + public FanoutExchange newInstance(UUID id, VirtualHost host, AMQShortString name, + boolean durable, int ticket, boolean autoDelete) + throws AMQException + { + FanoutExchange exch = new FanoutExchange(); + exch.initialise(id, host, name, durable, ticket, autoDelete); + return exch; + } + + public AMQShortString getDefaultExchangeName() + { + return ExchangeDefaults.FANOUT_EXCHANGE_NAME; + } +} \ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java index 6bad59c2ae..746c8ac6bc 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java @@ -22,22 +22,18 @@ package org.apache.qpid.server.exchange; import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; -import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.message.AMQMessageHeader; import org.apache.qpid.server.message.InboundMessage; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.BaseQueue; -import org.apache.qpid.server.virtualhost.VirtualHost; -import javax.management.JMException; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Map; -import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArraySet; @@ -81,40 +77,12 @@ public class HeadersExchange extends AbstractExchange new CopyOnWriteArrayList(); - public static final ExchangeType TYPE = new ExchangeType() - { - - public AMQShortString getName() - { - return ExchangeDefaults.HEADERS_EXCHANGE_CLASS; - } - - public Class getExchangeClass() - { - return HeadersExchange.class; - } - - public HeadersExchange newInstance(UUID id, VirtualHost host, AMQShortString name, boolean durable, int ticket, - boolean autoDelete) throws AMQException - { - HeadersExchange exch = new HeadersExchange(); - - exch.initialise(id, host, name, durable, ticket, autoDelete); - return exch; - } - - public AMQShortString getDefaultExchangeName() - { - - return ExchangeDefaults.HEADERS_EXCHANGE_NAME; - } - }; + public static final ExchangeType TYPE = new HeadersExchangeType(); public HeadersExchange() { super(TYPE); } - public ArrayList doRoute(InboundMessage payload) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java new file mode 100644 index 0000000000..61d9a3c2b0 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java @@ -0,0 +1,32 @@ +package org.apache.qpid.server.exchange; + +import java.util.UUID; + +import org.apache.qpid.AMQException; +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.plugin.ExchangeType; +import org.apache.qpid.server.virtualhost.VirtualHost; + +public class HeadersExchangeType implements ExchangeType +{ + public AMQShortString getName() + { + return ExchangeDefaults.HEADERS_EXCHANGE_CLASS; + } + + public HeadersExchange newInstance(UUID id, VirtualHost host, AMQShortString name, boolean durable, int ticket, + boolean autoDelete) throws AMQException + { + HeadersExchange exch = new HeadersExchange(); + + exch.initialise(id, host, name, durable, ticket, autoDelete); + return exch; + } + + public AMQShortString getDefaultExchangeName() + { + + return ExchangeDefaults.HEADERS_EXCHANGE_NAME; + } +} \ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java index 480d4e4215..6d548be508 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java @@ -27,15 +27,11 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.UUID; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; -import javax.management.JMException; import org.apache.log4j.Logger; -import org.apache.qpid.AMQException; import org.apache.qpid.AMQInvalidArgumentException; import org.apache.qpid.common.AMQPFilterTypes; -import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.filter.SelectorParsingException; import org.apache.qpid.filter.selector.ParseException; import org.apache.qpid.filter.selector.TokenMgrError; @@ -49,44 +45,15 @@ import org.apache.qpid.server.exchange.topic.TopicParser; import org.apache.qpid.server.filter.JMSSelectorFilter; import org.apache.qpid.server.filter.MessageFilter; import org.apache.qpid.server.message.InboundMessage; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.protocol.AMQSessionModel; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.BaseQueue; import org.apache.qpid.server.queue.Filterable; -import org.apache.qpid.server.virtualhost.VirtualHost; public class TopicExchange extends AbstractExchange { - - public static final ExchangeType TYPE = new ExchangeType() - { - - public AMQShortString getName() - { - return ExchangeDefaults.TOPIC_EXCHANGE_CLASS; - } - - public Class getExchangeClass() - { - return TopicExchange.class; - } - - public TopicExchange newInstance(UUID id, VirtualHost host, - AMQShortString name, - boolean durable, - int ticket, - boolean autoDelete) throws AMQException - { - TopicExchange exch = new TopicExchange(); - exch.initialise(id, host, name, durable, ticket, autoDelete); - return exch; - } - - public AMQShortString getDefaultExchangeName() - { - return ExchangeDefaults.TOPIC_EXCHANGE_NAME; - } - }; + public static final ExchangeType TYPE = new TopicExchangeType(); private static final Logger _logger = Logger.getLogger(TopicExchange.class); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java new file mode 100644 index 0000000000..cb4e747a2d --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java @@ -0,0 +1,33 @@ +package org.apache.qpid.server.exchange; + +import java.util.UUID; + +import org.apache.qpid.AMQException; +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.plugin.ExchangeType; +import org.apache.qpid.server.virtualhost.VirtualHost; + +public class TopicExchangeType implements ExchangeType +{ + public AMQShortString getName() + { + return ExchangeDefaults.TOPIC_EXCHANGE_CLASS; + } + + public TopicExchange newInstance(UUID id, VirtualHost host, + AMQShortString name, + boolean durable, + int ticket, + boolean autoDelete) throws AMQException + { + TopicExchange exch = new TopicExchange(); + exch.initialise(id, host, name, durable, ticket, autoDelete); + return exch; + } + + public AMQShortString getDefaultExchangeName() + { + return ExchangeDefaults.TOPIC_EXCHANGE_NAME; + } +} \ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java new file mode 100644 index 0000000000..86de4aa2f0 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.management.plugin; + +public interface ManagementPlugin +{ + void start() throws Exception; + void stop() throws Exception; +} \ No newline at end of file diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java index df0f29fbc3..266fdbd1ba 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java @@ -33,7 +33,6 @@ import org.apache.qpid.AMQSecurityException; import org.apache.qpid.protocol.AMQConstant; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.exchange.ExchangeType; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.Exchange; import org.apache.qpid.server.model.IllegalStateTransitionException; @@ -42,6 +41,7 @@ import org.apache.qpid.server.model.Publisher; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.Statistics; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.virtualhost.VirtualHost; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java index 911618e9e8..e564eabcdd 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java @@ -35,7 +35,6 @@ import org.apache.qpid.AMQException; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.server.connection.IConnectionRegistry; import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.exchange.ExchangeType; import org.apache.qpid.server.message.ServerMessage; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.Connection; @@ -49,6 +48,7 @@ import org.apache.qpid.server.model.Statistics; import org.apache.qpid.server.model.UUIDGenerator; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.model.VirtualHostAlias; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.protocol.AMQConnectionModel; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.AMQQueueFactory; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java new file mode 100644 index 0000000000..82f57c707b --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.plugin; + +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.security.AccessControl; + +public interface AccessControlFactory +{ + AccessControl createInstance(Configuration securityConfig); +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java new file mode 100644 index 0000000000..014b9fb28f --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.plugin; + +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.security.auth.manager.AuthenticationManager; + + +public interface AuthenticationManagerFactory +{ + AuthenticationManager createInstance(Configuration securityConfiguration); +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java new file mode 100644 index 0000000000..40ef6ad6a2 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java @@ -0,0 +1,36 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.plugin; + +import java.util.UUID; + +import org.apache.qpid.AMQException; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.exchange.Exchange; +import org.apache.qpid.server.virtualhost.VirtualHost; + +public interface ExchangeType +{ + public AMQShortString getName(); + public T newInstance(UUID id, VirtualHost host, AMQShortString name, + boolean durable, int ticket, boolean autoDelete) throws AMQException; + public AMQShortString getDefaultExchangeName(); +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java new file mode 100644 index 0000000000..b7f1eeaf29 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.plugin; + +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.security.group.GroupManager; + +public interface GroupManagerFactory +{ + GroupManager createInstance(Configuration securityConfiguration); +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ManagementFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ManagementFactory.java new file mode 100644 index 0000000000..92414b7127 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ManagementFactory.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.plugin; + +import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.management.plugin.ManagementPlugin; +import org.apache.qpid.server.model.Broker; + +public interface ManagementFactory +{ + ManagementPlugin createInstance(ServerConfiguration configuration, Broker broker); +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java new file mode 100644 index 0000000000..a0e0346ce0 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.plugin; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ServiceLoader; + +import org.apache.log4j.Logger; + +/** + * Simple facade over a {@link ServiceLoader} to instantiate all configured implementations of an interface. + */ +public class QpidServiceLoader +{ + private static final Logger _logger = Logger.getLogger(QpidServiceLoader.class); + + public Iterable instancesOf(Class clazz) + { + return instancesOf(clazz, false); + } + + /** + * @throws RuntimeException if at least one implementation is not found. + */ + public Iterable atLeastOneInstanceOf(Class clazz) + { + return instancesOf(clazz, true); + } + + private Iterable instancesOf(Class clazz, boolean atLeastOne) + { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + Iterator serviceLoaderIterator = ServiceLoader.load(clazz, classLoader).iterator(); + + // create a new list so we can log the count + List serviceImplementations = new ArrayList(); + while(serviceLoaderIterator.hasNext()) + { + serviceImplementations.add(serviceLoaderIterator.next()); + } + + if(atLeastOne && serviceImplementations.isEmpty()) + { + throw new RuntimeException("At least one implementation of " + clazz + " expected"); + } + + if(_logger.isDebugEnabled()) + { + _logger.debug("Found " + serviceImplementations.size() + " implementations of " + clazz); + } + + return serviceImplementations; + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java deleted file mode 100644 index 12e1eee9ca..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.plugins; - -import org.apache.log4j.Logger; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import org.apache.qpid.server.configuration.ServerConfiguration; -import org.apache.qpid.server.registry.ApplicationRegistry; - -public class Activator implements BundleActivator -{ - private static final Logger _logger = Logger.getLogger(Activator.class); - - private BundleContext _context = null; - - public void start(BundleContext ctx) throws Exception - { - _context = ctx; - _logger.info("Registering bundle: " + _context.getBundle().getSymbolicName()); - ctx.registerService(ServerConfiguration.class.getName(), ApplicationRegistry.getInstance().getConfiguration(), null); - } - - public void stop(BundleContext ctx) throws Exception - { - _logger.info("Stopping bundle: " + _context.getBundle().getSymbolicName()); - _context = null; - } - - public BundleContext getContext() - { - return _context; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java deleted file mode 100644 index d2bb3e037c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.plugins; - -import org.osgi.framework.Version; - -import java.util.Iterator; -import java.util.Map; - -/** - * Utility class to convert a map of package name to version numbers into the string - * with the format expected of a OSGi system package declaration: - * - * - * org.xyz; version=1.0.0, org.xyz.xyz; version=1.0.0,... - * - * - * Additionally, if the caller has provided a qpidPackageReleaseNumber and the package - * begins org.apache.qpid, this release number will be used, in preference to the one - * found in the Map. - * - * @see org.osgi.framework.Constants#FRAMEWORK_SYSTEMPACKAGES - * - */ -public class OsgiSystemPackageUtil -{ - private static final String APACHE_QPID_PKG_PREFIX = "org.apache.qpid"; - - private final Map _packageNameVersionMap; - private final Version _qpidPackageReleaseNumber; - - public OsgiSystemPackageUtil(final Version qpidPackageReleaseNumber, final Map packageNameVersionMap) - { - _qpidPackageReleaseNumber = qpidPackageReleaseNumber; - _packageNameVersionMap = packageNameVersionMap; - } - - public String getFormattedSystemPackageString() - { - if (_packageNameVersionMap == null || _packageNameVersionMap.size() == 0) - { - return null; - } - - final StringBuilder packages = new StringBuilder(); - - for(Iterator itr = _packageNameVersionMap.keySet().iterator(); itr.hasNext();) - { - final String packageName = itr.next(); - final String packageVersion; - - if (_qpidPackageReleaseNumber != null && packageName.startsWith(APACHE_QPID_PKG_PREFIX)) - { - packageVersion = _qpidPackageReleaseNumber.toString(); - } - else - { - packageVersion = _packageNameVersionMap.get(packageName); - } - - packages.append(packageName); - packages.append("; "); - packages.append("version="); - packages.append(packageVersion); - - if (itr.hasNext()) - { - packages.append(", "); - } - } - - return packages.toString(); - } - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties deleted file mode 100644 index 6479546355..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties +++ /dev/null @@ -1,135 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one# -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# -# OSGi framework system package list -# -# PluginManager uses these properties to construct the FRAMEWORK_SYSTEMPACKAGES list -# - -# Format is: -# = -# and PluginManager will convert this into: -# ; version= -# e.g. org.osgi.framework; version=1.3.0 - -javax.management.openmbean=1.0.0 -javax.management=1.0.0 -javax.management.remote.rmi=1.0.0 -javax.management.remote=1.0.0 -javax.management.monitor=1.0.0 - -javax.crypto=1 -javax.crypto.spec=1 - -javax.servlet=2 -javax.servlet.http=2 - -javax.security.auth=1.0.0 -javax.security.auth.callback=1.0.0 -javax.security.auth.login=1.0.0 -javax.security.sasl=1.0.0 -javax.security=1.0.0 - -javax.rmi.ssl=1.0.0 - -org.xml.sax=1.0.0 -org.xml.sax.helpers=1.0.0 - -org.osgi.framework=1.3.0 -org.osgi.service.packageadmin=1.2.0 -org.osgi.service.startlevel=1.0.0 -org.osgi.service.url=1.0.0 -org.osgi.util.tracker=1.0.0 - -org.apache.commons.codec=1.3.0 -org.apache.commons.codec.binary=1.3.0 - -org.apache.commons.configuration=1.0.0 - -org.apache.commons.lang=1.0.0 -org.apache.commons.lang.builder=1.0.0 -org.apache.commons.lang.time=1.0.0 -org.apache.commons.logging=1.0.0 - -org.apache.log4j=1.2.16 - -org.slf4j=1.6.1 - -org.eclipse.jetty=7.6.3 -org.eclipse.jetty.http=7.6.3 -org.eclipse.jetty.io=7.6.3 -org.eclipse.jetty.io.nio=7.6.3 -org.eclipse.jetty.security=7.6.3 -org.eclipse.jetty.server=7.6.3 -org.eclipse.jetty.server.session=7.6.3 -org.eclipse.jetty.server.ssl=7.6.3 -org.eclipse.jetty.server.nio=7.6.3 -org.eclipse.jetty.servlet=7.6.3 -org.eclipse.jetty.util.ssl=7.6.3 - -org.codehaus.jackson=1.9.0 -org.codehaus.jackson.map=1.9.0 - -# For Qpid packages (org.apache.qpid), the version number is automatically overridden by QpidPropertis#getReleaseVersion() - -org.apache.qpid=0.0.0 -org.apache.qpid.common=0.0.0 -org.apache.qpid.exchange=0.0.0 -org.apache.qpid.framing=0.0.0 -org.apache.qpid.management.common.mbeans.annotations=0.0.0 -org.apache.qpid.management.common.mbeans=0.0.0 -org.apache.qpid.protocol=0.0.0 -org.apache.qpid.transport=0.0.0 -org.apache.qpid.transport.codec=0.0.0 -org.apache.qpid.server.binding=0.0.0 -org.apache.qpid.server.model=0.0.0 -org.apache.qpid.server.model.adapter=0.0.0 -org.apache.qpid.server.model.impl=0.0.0 -org.apache.qpid.server.configuration=0.0.0 -org.apache.qpid.server.configuration.plugins=0.0.0 -org.apache.qpid.server.configuration.management=0.0.0 -org.apache.qpid.server.connection=0.0.0 -org.apache.qpid.server.exchange=0.0.0 -org.apache.qpid.server.logging=0.0.0 -org.apache.qpid.server.logging.log4j=0.0.0 -org.apache.qpid.server.logging.actors=0.0.0 -org.apache.qpid.server.logging.messages=0.0.0 -org.apache.qpid.server.logging.subjects=0.0.0 -org.apache.qpid.server.message=0.0.0 -org.apache.qpid.server.persistent=0.0.0 -org.apache.qpid.server.plugins=0.0.0 -org.apache.qpid.server.protocol=0.0.0 -org.apache.qpid.server.queue=0.0.0 -org.apache.qpid.server.subscription=0.0.0 -org.apache.qpid.server.registry=0.0.0 -org.apache.qpid.server.security=0.0.0 -org.apache.qpid.server.security.access=0.0.0 -org.apache.qpid.server.security.access.plugins=0.0.0 -org.apache.qpid.server.security.auth=0.0.0 -org.apache.qpid.server.security.auth.sasl=0.0.0 -org.apache.qpid.server.security.auth.manager=0.0.0 -org.apache.qpid.server.security.auth.rmi=0.0.0 -org.apache.qpid.server.stats=0.0.0 -org.apache.qpid.server.virtualhost=0.0.0 -org.apache.qpid.server.virtualhost.plugins=0.0.0 -org.apache.qpid.util=0.0.0 - -org.apache.qpid.server.store.berkeleydb=0.0.0 - diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java deleted file mode 100644 index 6dcf688f2a..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.plugins; - -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; - -public interface Plugin -{ - - /** - * Provide Configuration to this plugin - */ - public void configure(ConfigurationPlugin config) throws ConfigurationException; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java deleted file mode 100644 index 7ea2b95b89..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.plugins; - -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; - -public interface PluginFactory

-{ - public Class

getPluginClass(); - - public String getPluginName(); - - public P newInstance(ConfigurationPlugin config) throws ConfigurationException; -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java deleted file mode 100644 index 2080e44467..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.plugins; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.felix.framework.Felix; -import org.apache.felix.framework.util.StringMap; -import org.apache.log4j.Logger; -import org.apache.qpid.common.Closeable; -import org.apache.qpid.common.QpidProperties; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; -import org.apache.qpid.server.exchange.ExchangeType; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.security.SecurityPluginFactory; -import org.apache.qpid.server.security.access.plugins.LegacyAccess; -import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager; -import org.apache.qpid.server.security.auth.manager.AuthenticationManagerPluginFactory; -import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager; -import org.apache.qpid.server.security.auth.manager.KerberosAuthenticationManager; -import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager; -import org.apache.qpid.server.security.auth.manager.SimpleLDAPAuthenticationManager; -import org.apache.qpid.server.security.group.FileGroupManager; -import org.apache.qpid.server.security.group.GroupManagerPluginFactory; -import org.apache.qpid.server.virtualhost.plugins.VirtualHostPluginFactory; -import org.apache.qpid.util.FileUtils; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.Version; -import org.osgi.framework.launch.Framework; -import org.osgi.util.tracker.ServiceTracker; - -import static org.apache.felix.framework.util.FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP; -import static org.apache.felix.main.AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY; -import static org.apache.felix.main.AutoProcessor.AUTO_DEPLOY_DIR_PROPERY; -import static org.apache.felix.main.AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE; -import static org.apache.felix.main.AutoProcessor.AUTO_DEPLOY_START_VALUE; -import static org.apache.felix.main.AutoProcessor.process; -import static org.osgi.framework.Constants.FRAMEWORK_STORAGE; -import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN; -import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT; -import static org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES; - -/** - * Provides access to pluggable elements, such as exchanges - */ -@SuppressWarnings("unchecked") -public class PluginManager implements Closeable -{ - private static final Logger _logger = Logger.getLogger(PluginManager.class); - - private static final int FELIX_STOP_TIMEOUT = 30000; - - private Framework _felix; - - private ServiceTracker _exchangeTracker = null; - private ServiceTracker _securityTracker = null; - private ServiceTracker _configTracker = null; - private ServiceTracker _virtualHostTracker = null; - private ServiceTracker _authenticationManagerTracker = null; - private ServiceTracker _groupManagerTracker = null; - - private Activator _activator; - - private final List _trackers = new ArrayList(); - private Map _securityPlugins = new HashMap(); - private Map, ConfigurationPluginFactory> _configPlugins = new IdentityHashMap, ConfigurationPluginFactory>(); - private Map _vhostPlugins = new HashMap(); - private Map> _authenticationManagerPlugins = new HashMap>(); - private Map> _groupManagerPlugins = new HashMap>(); - - /** The default name of the OSGI system package list. */ - private static final String DEFAULT_RESOURCE_NAME = "org/apache/qpid/server/plugins/OsgiSystemPackages.properties"; - - /** The name of the override system property that holds the name of the OSGI system package list. */ - private static final String FILE_PROPERTY = "qpid.osgisystempackages.properties"; - - private static final String OSGI_SYSTEM_PACKAGES; - - static - { - final String filename = System.getProperty(FILE_PROPERTY); - final InputStream is = FileUtils.openFileOrDefaultResource(filename, DEFAULT_RESOURCE_NAME, - PluginManager.class.getClassLoader()); - - try - { - Version qpidReleaseVersion; - try - { - qpidReleaseVersion = Version.parseVersion(QpidProperties.getReleaseVersion()); - } - catch (IllegalArgumentException iae) - { - qpidReleaseVersion = null; - } - - final Properties p = new Properties(); - p.load(is); - - final OsgiSystemPackageUtil osgiSystemPackageUtil = new OsgiSystemPackageUtil(qpidReleaseVersion, (Map)p); - - OSGI_SYSTEM_PACKAGES = osgiSystemPackageUtil.getFormattedSystemPackageString(); - - _logger.debug("List of OSGi system packages to be added: " + OSGI_SYSTEM_PACKAGES); - } - catch (IOException e) - { - _logger.error("Error reading OSGI system package list", e); - throw new ExceptionInInitializerError(e); - } - } - - - public PluginManager(String pluginPath, String cachePath, BundleContext bundleContext) throws Exception - { - // Store all non-OSGi plugins - // A little gross that we have to add them here, but not all the plugins are OSGIfied - for (SecurityPluginFactory pluginFactory : Arrays.asList(LegacyAccess.FACTORY)) - { - _securityPlugins.put(pluginFactory.getPluginName(), pluginFactory); - } - for (ConfigurationPluginFactory configFactory : Arrays.asList( - SecurityManager.SecurityConfiguration.FACTORY, - LegacyAccess.LegacyAccessConfiguration.FACTORY, - PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration.FACTORY, - AnonymousAuthenticationManager.AnonymousAuthenticationManagerConfiguration.FACTORY, - KerberosAuthenticationManager.KerberosAuthenticationManagerConfiguration.FACTORY, - SimpleLDAPAuthenticationManager.SimpleLDAPAuthenticationManagerConfiguration.FACTORY, - ExternalAuthenticationManager.ExternalAuthenticationManagerConfiguration.FACTORY, - FileGroupManager.FileGroupManagerConfiguration.FACTORY - )) - { - _configPlugins.put(configFactory.getParentPaths(), configFactory); - } - - for (AuthenticationManagerPluginFactory pluginFactory : Arrays.asList( - PrincipalDatabaseAuthenticationManager.FACTORY, AnonymousAuthenticationManager.FACTORY, - KerberosAuthenticationManager.FACTORY, SimpleLDAPAuthenticationManager.FACTORY, - ExternalAuthenticationManager.FACTORY)) - { - _authenticationManagerPlugins.put(pluginFactory.getPluginName(), pluginFactory); - } - - for (GroupManagerPluginFactory pluginFactory : Arrays.asList( - FileGroupManager.FACTORY)) - { - _groupManagerPlugins.put(pluginFactory.getPluginName(), pluginFactory); - } - - if(bundleContext == null) - { - // Check the plugin directory path is set and exist - if (pluginPath == null) - { - _logger.info("No plugin path specified, no plugins will be loaded."); - return; - } - File pluginDir = new File(pluginPath); - if (!pluginDir.exists()) - { - _logger.warn("Plugin dir : " + pluginDir + " does not exist."); - return; - } - - // Add the bundle provided service interface package and the core OSGi - // packages to be exported from the class path via the system bundle. - - // Setup OSGi configuration property map - final StringMap configMap = new StringMap(false); - configMap.put(FRAMEWORK_SYSTEMPACKAGES, OSGI_SYSTEM_PACKAGES); - - // No automatic shutdown hook - configMap.put("felix.shutdown.hook", "false"); - - // Add system activator - List activators = new ArrayList(); - _activator = new Activator(); - activators.add(_activator); - configMap.put(SYSTEMBUNDLE_ACTIVATORS_PROP, activators); - - if (cachePath != null) - { - File cacheDir = new File(cachePath); - if (!cacheDir.exists() && cacheDir.canWrite()) - { - _logger.info("Creating plugin cache directory: " + cachePath); - cacheDir.mkdir(); - } - - // Set plugin cache directory and empty it - _logger.info("Cache bundles in directory " + cachePath); - configMap.put(FRAMEWORK_STORAGE, cachePath); - } - configMap.put(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); - - // Set directory with plugins to auto-deploy - _logger.info("Auto deploying bundles from directory " + pluginPath); - configMap.put(AUTO_DEPLOY_DIR_PROPERY, pluginPath); - configMap.put(AUTO_DEPLOY_ACTION_PROPERY, AUTO_DEPLOY_INSTALL_VALUE + "," + AUTO_DEPLOY_START_VALUE); - - // Start plugin manager - _felix = new Felix(configMap); - try - { - _logger.info("Starting plugin manager framework"); - _felix.init(); - process(configMap, _felix.getBundleContext()); - _felix.start(); - _logger.info("Started plugin manager framework"); - } - catch (BundleException e) - { - throw new ConfigurationException("Could not start plugin manager: " + e.getMessage(), e); - } - - bundleContext = _activator.getContext(); - } - else - { - _logger.info("Using the specified external BundleContext"); - } - - _exchangeTracker = new ServiceTracker(bundleContext, ExchangeType.class.getName(), null); - _exchangeTracker.open(); - _trackers.add(_exchangeTracker); - - _securityTracker = new ServiceTracker(bundleContext, SecurityPluginFactory.class.getName(), null); - _securityTracker.open(); - _trackers.add(_securityTracker); - - _configTracker = new ServiceTracker(bundleContext, ConfigurationPluginFactory.class.getName(), null); - _configTracker.open(); - _trackers.add(_configTracker); - - _virtualHostTracker = new ServiceTracker(bundleContext, VirtualHostPluginFactory.class.getName(), null); - _virtualHostTracker.open(); - _trackers.add(_virtualHostTracker); - - _authenticationManagerTracker = new ServiceTracker(bundleContext, AuthenticationManagerPluginFactory.class.getName(), null); - _authenticationManagerTracker.open(); - _trackers.add(_authenticationManagerTracker); - - _groupManagerTracker = new ServiceTracker(bundleContext, GroupManagerPluginFactory.class.getName(), null); - _groupManagerTracker.open(); - _trackers.add(_groupManagerTracker); - - - _logger.info("Opened service trackers"); - } - - private static Map getServices(ServiceTracker tracker) - { - Map services = new HashMap(); - - if ((tracker != null) && (tracker.getServices() != null)) - { - for (Object service : tracker.getServices()) - { - if (service instanceof PluginFactory) - { - services.put(((PluginFactory) service).getPluginName(), (T) service); - } - else - { - services.put(service.getClass().getName(), (T) service); - } - } - } - - return services; - } - - public static Map getServices(ServiceTracker tracker, Map plugins) - { - Map services = getServices(tracker); - services.putAll(plugins); - return services; - } - - public Map, ConfigurationPluginFactory> getConfigurationPlugins() - { - Map, ConfigurationPluginFactory> services = new IdentityHashMap, ConfigurationPluginFactory>(); - - if (_configTracker != null && _configTracker.getServices() != null) - { - for (Object service : _configTracker.getServices()) - { - ConfigurationPluginFactory factory = (ConfigurationPluginFactory) service; - services.put(factory.getParentPaths(), factory); - } - } - - services.putAll(_configPlugins); - - return services; - } - - public Map getVirtualHostPlugins() - { - return getServices(_virtualHostTracker, _vhostPlugins); - } - - public Map> getExchanges() - { - return getServices(_exchangeTracker); - } - - public Map getSecurityPlugins() - { - return getServices(_securityTracker, _securityPlugins); - } - - public Map> getAuthenticationManagerPlugins() - { - return getServices(_authenticationManagerTracker, _authenticationManagerPlugins); - } - - public Map> getGroupManagerPlugins() - { - return getServices(_groupManagerTracker, _groupManagerPlugins); - } - - public void close() - { - try - { - // Close all bundle trackers - for(ServiceTracker tracker : _trackers) - { - tracker.close(); - } - } - finally - { - if (_felix != null) - { - _logger.info("Stopping plugin manager framework"); - try - { - // FIXME should be stopAndWait() but hangs VM, need upgrade in felix - _felix.stop(); - } - catch (BundleException e) - { - // Ignore - } - - try - { - _felix.waitForStop(FELIX_STOP_TIMEOUT); - } - catch (InterruptedException e) - { - // Ignore - } - _logger.info("Stopped plugin manager framework"); - } - else - { - _logger.info("Plugin manager was started with an external BundleContext, " + - "skipping remaining shutdown tasks"); - } - } - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java index 3c0c8d2029..6f42822b67 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java @@ -42,7 +42,7 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.pool.ReferenceCountingExecutorService; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.configuration.QueueConfiguration; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; +import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.logging.LogActor; import org.apache.qpid.server.logging.LogSubject; @@ -182,7 +182,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes //TODO : persist creation time private long _createTime = System.currentTimeMillis(); - private ConfigurationPlugin _queueConfiguration; + private AbstractConfiguration _queueConfiguration; /** the maximum delivery count for each message on this queue or 0 if maximum delivery count is not to be enforced. */ private int _maximumDeliveryCount = ApplicationRegistry.getInstance().getConfiguration().getMaxDeliveryCount(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java index 63d00fd0fc..c32e85b293 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java @@ -20,14 +20,13 @@ */ package org.apache.qpid.server.registry; +import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; import org.apache.qpid.server.logging.*; -import org.osgi.framework.BundleContext; import org.apache.qpid.common.Closeable; import org.apache.qpid.common.QpidProperties; -import org.apache.qpid.server.configuration.ConfigurationManager; import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.logging.actors.AbstractActor; @@ -35,18 +34,18 @@ import org.apache.qpid.server.logging.actors.BrokerActor; import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.logging.messages.BrokerMessages; import org.apache.qpid.server.logging.messages.VirtualHostMessages; +import org.apache.qpid.server.management.plugin.ManagementPlugin; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.adapter.BrokerAdapter; -import org.apache.qpid.server.plugins.Plugin; -import org.apache.qpid.server.plugins.PluginManager; +import org.apache.qpid.server.plugin.GroupManagerFactory; +import org.apache.qpid.server.plugin.ManagementFactory; +import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.security.SubjectCreator; -import org.apache.qpid.server.security.SecurityManager.SecurityConfiguration; import org.apache.qpid.server.security.auth.manager.AuthenticationManager; import org.apache.qpid.server.security.auth.manager.AuthenticationManagerRegistry; import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry; import org.apache.qpid.server.security.group.GroupManager; -import org.apache.qpid.server.security.group.GroupManagerPluginFactory; import org.apache.qpid.server.security.group.GroupPrincipalAccessor; import org.apache.qpid.server.stats.StatisticsCounter; import org.apache.qpid.server.transport.QpidAcceptor; @@ -66,9 +65,8 @@ import java.util.concurrent.atomic.AtomicReference; *

* Subclasses should handle the construction of the "registered objects" such as the exchange registry. */ -public abstract class ApplicationRegistry implements IApplicationRegistry +public class ApplicationRegistry implements IApplicationRegistry { - private static final Logger _logger = Logger.getLogger(ApplicationRegistry.class); private static AtomicReference _instance = new AtomicReference(null); @@ -84,10 +82,6 @@ public abstract class ApplicationRegistry implements IApplicationRegistry private SecurityManager _securityManager; - private PluginManager _pluginManager; - - private ConfigurationManager _configurationManager; - private volatile RootMessageLogger _rootMessageLogger; private CompositeStartupMessageLogger _startupMessageLogger; @@ -97,8 +91,6 @@ public abstract class ApplicationRegistry implements IApplicationRegistry private Timer _reportingTimer; private StatisticsCounter _messagesDelivered, _dataDelivered, _messagesReceived, _dataReceived; - private BundleContext _bundleContext; - private final List _portBindingListeners = new ArrayList(); private int _httpManagementPort = -1, _httpsManagementPort = -1; @@ -113,6 +105,10 @@ public abstract class ApplicationRegistry implements IApplicationRegistry private List _groupManagerList = new ArrayList(); + private QpidServiceLoader _groupManagerServiceLoader = new QpidServiceLoader(); + + private final List _managmentInstanceList = new ArrayList(); + public Map getAcceptors() { synchronized (_acceptors) @@ -126,16 +122,6 @@ public abstract class ApplicationRegistry implements IApplicationRegistry _securityManager = securityManager; } - protected void setPluginManager(PluginManager pluginManager) - { - _pluginManager = pluginManager; - } - - protected void setConfigurationManager(ConfigurationManager configurationManager) - { - _configurationManager = configurationManager; - } - protected void setRootMessageLogger(RootMessageLogger rootMessageLogger) { _rootMessageLogger = rootMessageLogger; @@ -205,31 +191,9 @@ public abstract class ApplicationRegistry implements IApplicationRegistry } } - protected ApplicationRegistry(ServerConfiguration configuration) - { - this(configuration, null); - } - - protected ApplicationRegistry(ServerConfiguration configuration, BundleContext bundleContext) + public ApplicationRegistry(ServerConfiguration configuration) { _configuration = configuration; - _bundleContext = bundleContext; - } - - public void configure() throws ConfigurationException - { - _configurationManager = new ConfigurationManager(); - - try - { - _pluginManager = new PluginManager(_configuration.getPluginDirectory(), _configuration.getCacheDirectory(), _bundleContext); - } - catch (Exception e) - { - throw new ConfigurationException(e); - } - - _configuration.initialise(); } public void initialise() throws Exception @@ -261,31 +225,17 @@ public abstract class ApplicationRegistry implements IApplicationRegistry _broker = new BrokerAdapter(this); - configure(); - + _configuration.initialise(); logStartupMessages(CurrentActor.get()); - _securityManager = new SecurityManager(_configuration, _pluginManager); - - final Collection> factories = _pluginManager.getGroupManagerPlugins().values(); - final SecurityConfiguration securityConfiguration = _configuration.getConfiguration(SecurityConfiguration.class.getName()); + // Management needs to be registered so that JMXManagement.childAdded can create optional management objects + createAndStartManagementPlugins(_configuration, _broker); - for(GroupManagerPluginFactory factory : factories) - { - final GroupManager groupManager = factory.newInstance(securityConfiguration); - if(groupManager != null) - { - _groupManagerList.add(groupManager); + _securityManager = new SecurityManager(_configuration.getConfig()); - for(GroupManagerChangeListener listener : _groupManagerChangeListeners) - { - listener.groupManagerRegistered(groupManager); - } - } - } - _logger.debug("Created " + _groupManagerList.size() + " group manager(s)"); + _groupManagerList = createGroupManagers(_configuration); - _authenticationManagerRegistry = createAuthenticationManagerRegistry(_configuration, _pluginManager, new GroupPrincipalAccessor(_groupManagerList)); + _authenticationManagerRegistry = createAuthenticationManagerRegistry(_configuration, new GroupPrincipalAccessor(_groupManagerList)); if(!_authManagerChangeListeners.isEmpty()) { @@ -319,10 +269,79 @@ public abstract class ApplicationRegistry implements IApplicationRegistry } } - protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry(ServerConfiguration configuration, PluginManager pluginManager, GroupPrincipalAccessor groupManagerList) + private void createAndStartManagementPlugins(ServerConfiguration configuration, Broker broker) throws Exception + { + QpidServiceLoader factories = new QpidServiceLoader(); + for (ManagementFactory managementFactory: factories.instancesOf(ManagementFactory.class)) + { + ManagementPlugin managementPlugin = managementFactory.createInstance(configuration, broker); + if(managementPlugin != null) + { + try + { + managementPlugin.start(); + } + catch(Exception e) + { + _logger.error("Management plugin " + managementPlugin.getClass().getSimpleName() + " failed to start normally, stopping it now", e); + managementPlugin.stop(); + throw e; + } + + _managmentInstanceList.add(managementPlugin); + } + } + + if (_logger.isDebugEnabled()) + { + _logger.debug("Configured " + _managmentInstanceList.size() + " management instance(s)"); + } + } + + private void closeAllManagementPlugins() + { + for (ManagementPlugin managementPlugin : _managmentInstanceList) + { + try + { + managementPlugin.stop(); + } + catch (Exception e) + { + _logger.error("Exception thrown whilst stopping management plugin " + managementPlugin.getClass().getSimpleName(), e); + } + } + } + + private List createGroupManagers(ServerConfiguration configuration) throws ConfigurationException + { + List groupManagerList = new ArrayList(); + Configuration securityConfig = configuration.getConfig().subset("security"); + + for(GroupManagerFactory factory : _groupManagerServiceLoader.instancesOf(GroupManagerFactory.class)) + { + GroupManager groupManager = factory.createInstance(securityConfig); + if (groupManager != null) + { + groupManagerList.add(groupManager); + for(GroupManagerChangeListener listener : _groupManagerChangeListeners) + { + listener.groupManagerRegistered(groupManager); + } + } + } + + if (_logger.isDebugEnabled()) + { + _logger.debug("Configured " + groupManagerList.size() + " group manager(s)"); + } + return groupManagerList; + } + + protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry(ServerConfiguration configuration, GroupPrincipalAccessor groupPrincipalAccessor) throws ConfigurationException { - return new AuthenticationManagerRegistry(configuration, pluginManager, groupManagerList); + return new AuthenticationManagerRegistry(configuration, groupPrincipalAccessor); } protected void initialiseVirtualHosts() throws Exception @@ -476,11 +495,11 @@ public abstract class ApplicationRegistry implements IApplicationRegistry close(_authenticationManagerRegistry); - close(_pluginManager); - CurrentActor.get().message(BrokerMessages.STOPPED()); _logRecorder.closeLogRecorder(); + + closeAllManagementPlugins(); } finally { @@ -570,16 +589,6 @@ public abstract class ApplicationRegistry implements IApplicationRegistry return _groupManagerList; } - public PluginManager getPluginManager() - { - return _pluginManager; - } - - public ConfigurationManager getConfigurationManager() - { - return _configurationManager; - } - public RootMessageLogger getRootMessageLogger() { return _rootMessageLogger; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java deleted file mode 100644 index 774d0338ef..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.registry; - -import org.apache.commons.configuration.ConfigurationException; -import org.osgi.framework.BundleContext; - -import org.apache.qpid.AMQException; -import org.apache.qpid.server.configuration.ServerConfiguration; - -import java.io.File; - -public class ConfigurationFileApplicationRegistry extends ApplicationRegistry -{ - public ConfigurationFileApplicationRegistry(File configurationURL) throws ConfigurationException - { - this(configurationURL, null); - } - - public ConfigurationFileApplicationRegistry(File configurationURL, BundleContext bundleContext) throws ConfigurationException - { - super(new ServerConfiguration(configurationURL), bundleContext); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java index 8f8872882f..8cdb576f76 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java @@ -20,12 +20,10 @@ */ package org.apache.qpid.server.registry; -import org.apache.qpid.server.configuration.ConfigurationManager; import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.logging.RootMessageLogger; import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.plugins.PluginManager; import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.security.SubjectCreator; import org.apache.qpid.server.security.auth.manager.AuthenticationManager; @@ -78,10 +76,6 @@ public interface IApplicationRegistry extends StatisticsGatherer SecurityManager getSecurityManager(); - PluginManager getPluginManager(); - - ConfigurationManager getConfigurationManager(); - RootMessageLogger getRootMessageLogger(); /** diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java deleted file mode 100644 index 704e50da5c..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.security; - -import org.apache.log4j.Logger; - -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.security.access.ObjectProperties; -import org.apache.qpid.server.security.access.ObjectType; -import org.apache.qpid.server.security.access.Operation; - -/** - * This is intended as the parent for all simple plugins. - */ -public abstract class AbstractPlugin implements SecurityPlugin -{ - private final Logger _logger = Logger.getLogger(getClass()); - - private ConfigurationPlugin _config; - - public Result getDefault() - { - return Result.ABSTAIN; - } - - public abstract Result access(ObjectType object, Object instance); - - public abstract Result authorise(Operation operation, ObjectType object, ObjectProperties properties); - - public void configure(ConfigurationPlugin config) - { - _config = config; - } - - public ConfigurationPlugin getConfig() - { - return _config; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java deleted file mode 100644 index 236931e8cd..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.security; - -import org.apache.qpid.server.security.access.ObjectProperties; -import org.apache.qpid.server.security.access.ObjectType; -import org.apache.qpid.server.security.access.Operation; - -/** - * This {@link SecurityPlugin} proxies the authorise calls to a serries of methods, one per {@link Operation}. - * - */ -public abstract class AbstractProxyPlugin extends AbstractPlugin -{ - public Result authoriseConsume(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result authorisePublish(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result authoriseCreate(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result authoriseAccess(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result authoriseBind(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result authoriseUnbind(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result authoriseDelete(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result authorisePurge(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result authoriseUpdate(ObjectType object, ObjectProperties properties) - { - return getDefault(); - } - - public Result accessVirtualhost(Object instance) - { - return getDefault(); - } - - @Override - public Result access(ObjectType objectType, Object instance) - { - switch (objectType) - { - case VIRTUALHOST: - return accessVirtualhost(instance); - } - - return getDefault(); - } - - @Override - public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties) - { - switch (operation) - { - case CONSUME: - return authoriseConsume(objectType, properties); - case PUBLISH: - return authorisePublish(objectType, properties); - case CREATE: - return authoriseCreate(objectType, properties); - case ACCESS: - return authoriseAccess(objectType, properties); - case BIND: - return authoriseBind(objectType, properties); - case UNBIND: - return authoriseUnbind(objectType, properties); - case DELETE: - return authoriseDelete(objectType, properties); - case PURGE: - return authorisePurge(objectType, properties); - case UPDATE: - return authoriseUpdate(objectType, properties); - } - - return getDefault(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java new file mode 100644 index 0000000000..b4831f83e5 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.security; + +import org.apache.qpid.server.security.access.ObjectProperties; +import org.apache.qpid.server.security.access.ObjectType; +import org.apache.qpid.server.security.access.Operation; + +/** + * The two methods, {@link #access(ObjectType, Object)} and {@link #authorise(Operation, ObjectType, ObjectProperties)}, + * return the {@link Result} of the security decision, which may be to {@link Result#ABSTAIN} if no decision is made. + */ +public interface AccessControl +{ + /** + * Default result for {@link #access(ObjectType, Object)} or {@link #authorise(Operation, ObjectType, ObjectProperties)}. + */ + Result getDefault(); + + /** + * Authorise access granted to an object instance. + */ + Result access(ObjectType objectType, Object instance); + + /** + * Authorise an operation on an object defined by a set of properties. + */ + Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties); +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java index 1e377be1d2..6099d11c46 100755 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java @@ -23,10 +23,10 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.plugins.PluginManager; + +import org.apache.qpid.server.plugin.AccessControlFactory; +import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.security.access.ObjectProperties; import org.apache.qpid.server.security.access.ObjectType; @@ -48,67 +48,31 @@ import static org.apache.qpid.server.security.access.Operation.UNBIND; import javax.security.auth.Subject; import java.net.SocketAddress; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; /** - * The security manager contains references to all loaded {@link SecurityPlugin}s and delegates security decisions to them based + * The security manager contains references to all loaded {@link AccessControl}s and delegates security decisions to them based * on virtual host name. The plugins can be external OSGi .jar files that export the required classes or just internal * objects for simpler plugins. - * - * @see SecurityPlugin + * + * @see AccessControl */ public class SecurityManager { private static final Logger _logger = Logger.getLogger(SecurityManager.class); - + /** Container for the {@link java.security.Principal} that is using to this thread. */ private static final ThreadLocal _subject = new ThreadLocal(); public static final ThreadLocal _accessChecksDisabled = new ClearingThreadLocal(false); - private PluginManager _pluginManager; - private Map _pluginFactories = new HashMap(); - private Map _globalPlugins = new HashMap(); - private Map _hostPlugins = new HashMap(); - - public static class SecurityConfiguration extends ConfigurationPlugin - { - public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory() - { - public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException - { - ConfigurationPlugin instance = new SecurityConfiguration(); - instance.setConfiguration(path, config); - return instance; - } - - public List getParentPaths() - { - return Arrays.asList("security", "virtualhosts.virtualhost.security"); - } - }; - - @Override - public String[] getElementsProcessed() - { - return new String[]{"security"}; - } - - public void validateConfiguration() throws ConfigurationException - { - if (getConfig().isEmpty()) - { - throw new ConfigurationException("security section is incomplete, no elements found."); - } - } - } + private Map _globalPlugins = new HashMap(); + private Map _hostPlugins = new HashMap(); /** * A special ThreadLocal, which calls remove() on itself whenever the value is @@ -155,35 +119,34 @@ public class SecurityManager } } - public SecurityManager(SecurityManager parent) throws ConfigurationException + /* + * Used by the VirtualHost to allow deferring to the broker level security plugins if required. + */ + public SecurityManager(SecurityManager parent, Configuration config) throws ConfigurationException { - _pluginManager = parent._pluginManager; - _pluginFactories = parent._pluginFactories; - + this(config); + // our global plugins are the parent's host plugins _globalPlugins = parent._hostPlugins; } - public SecurityManager(ConfigurationPlugin configuration, PluginManager manager) throws ConfigurationException + public SecurityManager(Configuration config) throws ConfigurationException { - this(configuration, manager, null); - } + Configuration securityConfig = config.subset("security"); - public SecurityManager(ConfigurationPlugin configuration, PluginManager manager, SecurityPluginFactory plugin) throws ConfigurationException - { - _pluginManager = manager; - if (manager == null) // No plugin manager, no plugins + for (AccessControlFactory provider : (new QpidServiceLoader()).instancesOf(AccessControlFactory.class)) { - return; + AccessControl accessControl = provider.createInstance(securityConfig); + if(accessControl != null) + { + addHostPlugin(accessControl); + } } - _pluginFactories = _pluginManager.getSecurityPlugins(); - if (plugin != null) + if(_logger.isDebugEnabled()) { - _pluginFactories.put(plugin.getPluginName(), plugin); + _logger.debug("Configured " + _hostPlugins.size() + " access control plugins"); } - - configureHostPlugins(configuration); } public static Subject getThreadSubject() @@ -196,41 +159,6 @@ public class SecurityManager _subject.set(subject); } - public void configureHostPlugins(ConfigurationPlugin hostConfig) throws ConfigurationException - { - _hostPlugins = configurePlugins(hostConfig); - } - - public void configureGlobalPlugins(ConfigurationPlugin configuration) throws ConfigurationException - { - _globalPlugins = configurePlugins(configuration); - } - - public Map configurePlugins(ConfigurationPlugin hostConfig) throws ConfigurationException - { - Map plugins = new HashMap(); - SecurityConfiguration securityConfig = hostConfig.getConfiguration(SecurityConfiguration.class.getName()); - - // If we have no security Configuration then there is nothing to configure. - if (securityConfig != null) - { - for (SecurityPluginFactory factory : _pluginFactories.values()) - { - SecurityPlugin plugin = factory.newInstance(securityConfig); - if (plugin != null) - { - plugins.put(factory.getPluginName(), plugin); - } - } - } - return plugins; - } - - public void addHostPlugin(SecurityPlugin plugin) - { - _hostPlugins.put(plugin.getClass().getName(), plugin); - } - public static Logger getLogger() { return _logger; @@ -247,7 +175,7 @@ public class SecurityManager private abstract class AccessCheck { - abstract Result allowed(SecurityPlugin plugin); + abstract Result allowed(AccessControl plugin); } private boolean checkAllPlugins(AccessCheck checker) @@ -257,16 +185,16 @@ public class SecurityManager return true; } - Map remainingPlugins = _globalPlugins.isEmpty() - ? Collections.emptyMap() - : _hostPlugins.isEmpty() ? _globalPlugins : new HashMap(_globalPlugins); - - if(!_hostPlugins.isEmpty()) + Map remainingPlugins = _globalPlugins.isEmpty() + ? Collections.emptyMap() + : _hostPlugins.isEmpty() ? _globalPlugins : new HashMap(_globalPlugins); + + if(!_hostPlugins.isEmpty()) { - for (Entry hostEntry : _hostPlugins.entrySet()) + for (Entry hostEntry : _hostPlugins.entrySet()) { // Create set of global only plugins - SecurityPlugin globalPlugin = remainingPlugins.get(hostEntry.getKey()); + AccessControl globalPlugin = remainingPlugins.get(hostEntry.getKey()); if (globalPlugin != null) { remainingPlugins.remove(hostEntry.getKey()); @@ -314,7 +242,7 @@ public class SecurityManager } } - for (SecurityPlugin plugin : remainingPlugins.values()) + for (AccessControl plugin : remainingPlugins.values()) { Result remaining = checker.allowed(plugin); if (remaining == Result.DEFER) @@ -326,16 +254,16 @@ public class SecurityManager return false; } } - + // getting here means either allowed or abstained from all plugins return true; } - + public boolean authoriseBind(final Exchange exch, final AMQQueue queue, final AMQShortString routingKey) { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(BIND, EXCHANGE, new ObjectProperties(exch, queue, routingKey)); } @@ -346,7 +274,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { ObjectProperties properties = new ObjectProperties(); properties.setName(methodName); @@ -364,7 +292,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.access(ObjectType.MANAGEMENT, null); } @@ -375,7 +303,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.access(VIRTUALHOST, remoteAddress); } @@ -386,7 +314,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(CONSUME, QUEUE, new ObjectProperties(queue)); } @@ -398,7 +326,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(CREATE, EXCHANGE, new ObjectProperties(autoDelete, durable, exchangeName, internal, nowait, passive, exchangeType)); @@ -411,7 +339,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(CREATE, QUEUE, new ObjectProperties(autoDelete, durable, exclusive, nowait, passive, queueName, owner)); } @@ -422,7 +350,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(DELETE, QUEUE, new ObjectProperties(queue)); } @@ -433,7 +361,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(DELETE, EXCHANGE, new ObjectProperties(exchange.getName())); } @@ -444,7 +372,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(operation, GROUP, new ObjectProperties(groupName)); } @@ -455,7 +383,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(operation, USER, new ObjectProperties(userName)); } @@ -502,7 +430,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(PURGE, QUEUE, new ObjectProperties(queue)); } @@ -513,7 +441,7 @@ public class SecurityManager { return checkAllPlugins(new AccessCheck() { - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(UNBIND, EXCHANGE, new ObjectProperties(exch, queue, routingKey)); } @@ -539,9 +467,16 @@ public class SecurityManager _props = props; } - Result allowed(SecurityPlugin plugin) + Result allowed(AccessControl plugin) { return plugin.authorise(PUBLISH, EXCHANGE, _props); } } + + + public void addHostPlugin(AccessControl plugin) + { + _hostPlugins.put(plugin.getClass().getName(), plugin); + } + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java deleted file mode 100644 index c3c06bf206..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.security; - -import org.apache.qpid.server.plugins.Plugin; -import org.apache.qpid.server.security.access.ObjectProperties; -import org.apache.qpid.server.security.access.ObjectType; -import org.apache.qpid.server.security.access.Operation; - -/** - * The two methods, {@link #access(ObjectType, Object)} and {@link #authorise(Operation, ObjectType, ObjectProperties)}, - * return the {@link Result} of the security decision, which may be to {@link Result#ABSTAIN} if no decision is made - * by this plugin. - */ -public interface SecurityPlugin extends Plugin -{ - /** - * Default result for {@link #access(ObjectType, Object)} or {@link #authorise(Operation, ObjectType, ObjectProperties)}. - */ - Result getDefault(); - - /** - * Authorise access granted to an object instance. - */ - Result access(ObjectType objectType, Object instance); - - /** - * Authorise an operation on an object defined by a set of properties. - */ - Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java deleted file mode 100644 index 21c2d1cda5..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.security; - -import org.apache.log4j.Logger; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; - -/** - * An OSGi {@link BundleActivator} that loads a {@link SecurityPluginFactory}. - */ -public abstract class SecurityPluginActivator implements BundleActivator -{ - private static final Logger _logger = Logger.getLogger(SecurityPluginActivator.class); - - private SecurityPluginFactory _factory; - private ConfigurationPluginFactory _config; - private BundleContext _ctx; - private String _bundleName; - - /** Implement this to return the factory this plugin activates. */ - public abstract SecurityPluginFactory getFactory(); - - /** Implement this to return the factory this plugin activates. */ - public abstract ConfigurationPluginFactory getConfigurationFactory(); - - /** - * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext ctx) throws Exception - { - _ctx = ctx; - _factory = getFactory(); - _config = getConfigurationFactory(); - _bundleName = ctx.getBundle().getSymbolicName(); - - // register the service - _logger.info("Registering security plugin: " + _bundleName); - _ctx.registerService(SecurityPluginFactory.class.getName(), _factory, null); - _ctx.registerService(ConfigurationPluginFactory.class.getName(), _config, null); - } - - /** - * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception - { - _logger.info("Stopping security plugin: " + _bundleName); - - // null object references - _factory = null; - _config = null; - _ctx = null; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java deleted file mode 100644 index fe81cba282..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.security; - -import org.apache.qpid.server.plugins.PluginFactory; - -/** - * The factory that generates instances of security plugins. Usually implemented as a static member class in the plugin itself. - */ -public interface SecurityPluginFactory extends PluginFactory -{ -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java deleted file mode 100644 index 4df135a4ca..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.security.access.plugins; - -import org.apache.qpid.server.security.AbstractPlugin; -import org.apache.qpid.server.security.Result; -import org.apache.qpid.server.security.access.ObjectProperties; -import org.apache.qpid.server.security.access.ObjectType; -import org.apache.qpid.server.security.access.Operation; - -/** - * This {@link org.apache.qpid.server.security.SecurityPlugin} simply abstains from all authorisation requests and ignores configuration. - */ -public abstract class BasicPlugin extends AbstractPlugin -{ - public Result access(ObjectType objectType, Object instance) - { - return getDefault(); - } - - public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties) - { - return getDefault(); - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java deleted file mode 100644 index 4b7a2fb457..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.security.access.plugins; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; -import org.apache.qpid.server.security.SecurityPluginFactory; - -import java.util.Arrays; -import java.util.List; - -/** - * The LegacyAccess plugin is used internally and simply ignores legacy elements of the configuration file. - */ -public class LegacyAccess extends BasicPlugin -{ - public static class LegacyAccessConfiguration extends ConfigurationPlugin { - public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory() - { - public List getParentPaths() - { - return Arrays.asList("security.msg-auth", "virtualhosts.virtualhost.security.msg-auth"); - } - - public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException - { - ConfigurationPlugin instance = new LegacyAccessConfiguration(); - instance.setConfiguration(path, config); - return instance; - } - }; - - public String[] getElementsProcessed() - { - return new String[] { "" }; - } - } - - public static final SecurityPluginFactory FACTORY = new SecurityPluginFactory() - { - public LegacyAccess newInstance(ConfigurationPlugin config) throws ConfigurationException - { - LegacyAccessConfiguration configuration = config.getConfiguration(LegacyAccessConfiguration.class.getName()); - - // If there is no configuration for this plugin then don't load it. - if (configuration == null) - { - return null; - } - - LegacyAccess plugin = new LegacyAccess(); - plugin.configure(configuration); - return plugin; - } - - public String getPluginName() - { - return LegacyAccess.class.getName(); - } - - public Class getPluginClass() - { - return LegacyAccess.class; - } - }; - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java index 67f4b7344a..605d2d019d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java @@ -32,6 +32,8 @@ import java.util.Map; /** Represents a "user database" which is really a way of storing principals (i.e. usernames) and passwords. */ public interface PrincipalDatabase { + void setPasswordFile(String passwordFile) throws IOException; + /** * Set the password for a given principal in the specified callback. This is used for certain SASL providers. The * user database implementation should look up the password in any way it chooses and set it in the callback by diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java deleted file mode 100644 index ecf08de72e..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * - */ -package org.apache.qpid.server.security.auth.database; - -import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser; -import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5Initialiser; -import org.apache.qpid.server.security.auth.sasl.plain.PlainInitialiser; - -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.login.AccountNotFoundException; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.Principal; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -public class PropertiesPrincipalDatabase implements PrincipalDatabase -{ - private Properties _users; - - private Map _saslServers; - - public PropertiesPrincipalDatabase(Properties users) - { - _users = users; - - _saslServers = new HashMap(); - - /** - * Create Authenticators for Properties Principal Database. - */ - - // Accept MD5 incomming and use plain comparison with the file - PlainInitialiser cram = new PlainInitialiser(); - cram.initialise(this); - // Accept Plain incomming and hash it for comparison to the file. - CRAMMD5Initialiser plain = new CRAMMD5Initialiser(); - plain.initialise(this, CRAMMD5Initialiser.HashDirection.INCOMMING); - - _saslServers.put(plain.getMechanismName(), cram); - _saslServers.put(cram.getMechanismName(), plain); - } - - public void setPassword(Principal principal, PasswordCallback callback) throws IOException, AccountNotFoundException - { - if (principal == null) - { - throw new IllegalArgumentException("principal must not be null"); - } - - - - final String pwd = _users.getProperty(principal.getName()); - - if (pwd != null) - { - callback.setPassword(pwd.toCharArray()); - } - else - { - throw new AccountNotFoundException("No account found for principal " + principal); - } - } - - public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException - { - //fixme this is not correct as toCharArray is not safe based on the type of string. - char[] pwd = _users.getProperty(principal).toCharArray(); - - return compareCharArray(pwd, password); - } - - public boolean updatePassword(Principal principal, char[] password) throws AccountNotFoundException - { - return false; // updates denied - } - - public boolean createPrincipal(Principal principal, char[] password) - { - return false; // updates denied - } - - public boolean deletePrincipal(Principal principal) throws AccountNotFoundException - { - return false; // updates denied - } - - private boolean compareCharArray(char[] a, char[] b) - { - boolean equal = false; - if (a.length == b.length) - { - equal = true; - int index = 0; - while (equal && index < a.length) - { - equal = a[index] == b[index]; - index++; - } - } - return equal; - } - - private char[] convertPassword(String password) throws UnsupportedEncodingException - { - byte[] passwdBytes = password.getBytes("utf-8"); - - char[] passwd = new char[passwdBytes.length]; - - int index = 0; - - for (byte b : passwdBytes) - { - passwd[index++] = (char) b; - } - - return passwd; - } - - - public Map getMechanisms() - { - return _saslServers; - } - - public List getUsers() - { - return new LinkedList(); //todo - } - - public Principal getUser(String username) - { - if (_users.getProperty(username) != null) - { - return new UsernamePrincipal(username); - } - else - { - return null; - } - } - - public void reload() throws IOException - { - //No file to update from, so do nothing. - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java index 9ac7a8b11a..dd4c2e717a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java @@ -21,16 +21,11 @@ package org.apache.qpid.server.security.auth.manager; import java.security.Principal; -import java.util.Arrays; -import java.util.List; + import javax.security.auth.Subject; import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; + import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.auth.UsernamePrincipal; import org.apache.qpid.server.security.auth.sasl.anonymous.AnonymousInitialiser; @@ -38,8 +33,6 @@ import org.apache.qpid.server.security.auth.sasl.anonymous.AnonymousSaslServer; public class AnonymousAuthenticationManager implements AuthenticationManager { - private static final Logger _logger = Logger.getLogger(AnonymousAuthenticationManager.class); - private static final AnonymousInitialiser SASL_INITIALISER = new AnonymousInitialiser(); private static final String ANONYMOUS = SASL_INITIALISER.getMechanismName(); @@ -58,69 +51,7 @@ public class AnonymousAuthenticationManager implements AuthenticationManager static final AnonymousAuthenticationManager INSTANCE = new AnonymousAuthenticationManager(); - public static class AnonymousAuthenticationManagerConfiguration extends ConfigurationPlugin - { - - public static final ConfigurationPluginFactory FACTORY = - new ConfigurationPluginFactory() - { - public List getParentPaths() - { - return Arrays.asList("security.anonymous-auth-manager"); - } - - public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException - { - final ConfigurationPlugin instance = new AnonymousAuthenticationManagerConfiguration(); - - instance.setConfiguration(path, config); - return instance; - } - }; - - public String[] getElementsProcessed() - { - return new String[0]; - } - - public void validateConfiguration() throws ConfigurationException - { - } - - } - - - public static final AuthenticationManagerPluginFactory FACTORY = new AuthenticationManagerPluginFactory() - { - public AnonymousAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException - { - AnonymousAuthenticationManagerConfiguration configuration = - config == null - ? null - : (AnonymousAuthenticationManagerConfiguration) config.getConfiguration(AnonymousAuthenticationManagerConfiguration.class.getName()); - - // If there is no configuration for this plugin then don't load it. - if (configuration == null) - { - _logger.info("No authentication-manager configuration found for AnonymousAuthenticationManager"); - return null; - } - return INSTANCE; - } - - public Class getPluginClass() - { - return AnonymousAuthenticationManager.class; - } - - public String getPluginName() - { - return AnonymousAuthenticationManager.class.getName(); - } - }; - - - private AnonymousAuthenticationManager() + AnonymousAuthenticationManager() { } @@ -182,9 +113,4 @@ public class AnonymousAuthenticationManager implements AuthenticationManager public void close() { } - - @Override - public void configure(ConfigurationPlugin config) throws ConfigurationException - { - } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java new file mode 100644 index 0000000000..1dabb3d203 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.manager; + +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; + +public class AnonymousAuthenticationManagerFactory implements AuthenticationManagerFactory +{ + @Override + public AuthenticationManager createInstance(Configuration configuration) + { + if (configuration.subset("anonymous-auth-manager").isEmpty()) + { + return null; + } + + return new AnonymousAuthenticationManager(); + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java index ba635cd023..c1a694f148 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java @@ -24,7 +24,6 @@ import java.security.Principal; import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; import org.apache.qpid.common.Closeable; -import org.apache.qpid.server.plugins.Plugin; import org.apache.qpid.server.security.auth.AuthenticationResult; /** @@ -40,7 +39,7 @@ import org.apache.qpid.server.security.auth.AuthenticationResult; * the manager. The {@link #close()} method must reverse this registration. *

*/ -public interface AuthenticationManager extends Closeable, Plugin +public interface AuthenticationManager extends Closeable { /** The name for the required SASL Server mechanisms */ public static final String PROVIDER_NAME= "AMQSASLProvider-Server"; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java deleted file mode 100644 index a51f195761..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.security.auth.manager; - -import org.apache.qpid.server.plugins.PluginFactory; - -/** - * Factory producing authentication producing configured, initialised authentication - * managers. - */ -public interface AuthenticationManagerPluginFactory extends PluginFactory -{ - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java index 323ee15dd9..0f311e9aca 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java @@ -22,18 +22,17 @@ package org.apache.qpid.server.security.auth.manager; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.common.Closeable; import org.apache.qpid.server.configuration.ServerConfiguration; -import org.apache.qpid.server.plugins.Plugin; -import org.apache.qpid.server.plugins.PluginManager; -import org.apache.qpid.server.security.SecurityManager.SecurityConfiguration; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; +import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.security.SubjectCreator; import org.apache.qpid.server.security.group.GroupPrincipalAccessor; @@ -55,24 +54,24 @@ public class AuthenticationManagerRegistry implements Closeable, IAuthentication private final Map _portToSubjectCreatorMap; private final List _listeners = Collections.synchronizedList(new ArrayList()); + private final QpidServiceLoader _authManagerFactoryServiceLoader; - public AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, PluginManager _pluginManager, GroupPrincipalAccessor groupPrincipalAccessor) + public AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupPrincipalAccessor) throws ConfigurationException { - final Collection> factories = _pluginManager.getAuthenticationManagerPlugins().values(); - - if (factories.size() == 0) - { - throw new ConfigurationException("No authentication manager factory plugins found. Check the desired authentication" + - " manager plugin has been placed in the plugins directory."); - } + this(serverConfiguration, groupPrincipalAccessor, new QpidServiceLoader()); + } - final SecurityConfiguration securityConfiguration = serverConfiguration.getConfiguration(SecurityConfiguration.class.getName()); + // Exists as separate constructor for unit testing purposes + AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupPrincipalAccessor, QpidServiceLoader authManagerFactoryServiceLoader) + throws ConfigurationException + { + _authManagerFactoryServiceLoader = authManagerFactoryServiceLoader; boolean willClose = true; try { - createAuthenticationManagersRejectingDuplicates(factories, securityConfiguration); + createAuthManagers(serverConfiguration.getConfig()); if(_classToAuthManagerMap.isEmpty()) { @@ -86,7 +85,7 @@ public class AuthenticationManagerRegistry implements Closeable, IAuthentication } finally { - // if anything went wrong whilst configuring the registry, try to close all the AuthentcationManagers instantiated so far. + // if anyConfigurationExceptionthing went wrong whilst configuring the registry, try to close all the AuthentcationManagers instantiated so far. // This is done to allow the AuthenticationManager to undo any security registrations that they have performed. if (willClose) { @@ -115,32 +114,35 @@ public class AuthenticationManagerRegistry implements Closeable, IAuthentication } } - private void createAuthenticationManagersRejectingDuplicates( - final Collection> factories, - final SecurityConfiguration securityConfiguration) - throws ConfigurationException + private void createAuthManagers(Configuration config) { - for(AuthenticationManagerPluginFactory factory : factories) + Configuration securityConfiguration = config.subset("security"); + + for(AuthenticationManagerFactory factory : _authManagerFactoryServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)) { - final AuthenticationManager tmp = factory.newInstance(securityConfiguration); - if (tmp != null) + AuthenticationManager plugin = factory.createInstance(securityConfiguration); + if(plugin != null) { - if(_classToAuthManagerMap.containsKey(tmp.getClass().getSimpleName())) - { - throw new ConfigurationException("Cannot configure more than one authentication manager of type " - + tmp.getClass().getSimpleName() + "." - + " Remove configuration for one of the authentication managers."); - } - _classToAuthManagerMap.put(tmp.getClass().getSimpleName(),tmp); - - for(RegistryChangeListener listener : _listeners) - { - listener.authenticationManagerRegistered(tmp); - } + validateAndInitialiseAuthenticationManager(plugin); } } } + private void validateAndInitialiseAuthenticationManager(AuthenticationManager authenticationManager) + { + // TODO Should be a user-defined name rather than the classname. + final String authManagerName = authenticationManager.getClass().getSimpleName(); + if (_classToAuthManagerMap.containsKey(authManagerName)) + { + throw new RuntimeException("Cannot configure more than one authentication manager with name " + + authManagerName + "."); + } + + authenticationManager.initialise(); + + _classToAuthManagerMap.put(authManagerName, authenticationManager); + } + private SubjectCreator createDefaultSubectCreator( ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupAccessor) throws ConfigurationException diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java index 7ca296cc47..9ed8cf7fed 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java @@ -19,90 +19,19 @@ package org.apache.qpid.server.security.auth.manager; import java.security.Principal; -import java.util.Arrays; -import java.util.List; + import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; + import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.auth.UsernamePrincipal; import org.apache.qpid.server.security.auth.sasl.external.ExternalSaslServer; public class ExternalAuthenticationManager implements AuthenticationManager { - private static final Logger _logger = Logger.getLogger(ExternalAuthenticationManager.class); - private static final String EXTERNAL = "EXTERNAL"; - static final ExternalAuthenticationManager INSTANCE = new ExternalAuthenticationManager(); - - public static class ExternalAuthenticationManagerConfiguration extends ConfigurationPlugin - { - - public static final ConfigurationPluginFactory FACTORY = - new ConfigurationPluginFactory() - { - public List getParentPaths() - { - return Arrays.asList("security.external-auth-manager"); - } - - public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException - { - final ConfigurationPlugin instance = new ExternalAuthenticationManagerConfiguration(); - - instance.setConfiguration(path, config); - return instance; - } - }; - - public String[] getElementsProcessed() - { - return new String[0]; - } - - public void validateConfiguration() throws ConfigurationException - { - } - - } - - - public static final AuthenticationManagerPluginFactory FACTORY = new AuthenticationManagerPluginFactory() - { - public ExternalAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException - { - ExternalAuthenticationManagerConfiguration configuration = - config == null - ? null - : (ExternalAuthenticationManagerConfiguration) config.getConfiguration(ExternalAuthenticationManagerConfiguration.class.getName()); - - // If there is no configuration for this plugin then don't load it. - if (configuration == null) - { - _logger.info("No authentication-manager configuration found for ExternalAuthenticationManager"); - return null; - } - return INSTANCE; - } - - public Class getPluginClass() - { - return ExternalAuthenticationManager.class; - } - - public String getPluginName() - { - return ExternalAuthenticationManager.class.getName(); - } - }; - - - private ExternalAuthenticationManager() + ExternalAuthenticationManager() { } @@ -167,9 +96,4 @@ public class ExternalAuthenticationManager implements AuthenticationManager public void close() { } - - @Override - public void configure(ConfigurationPlugin config) throws ConfigurationException - { - } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java new file mode 100644 index 0000000000..686f084c93 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.manager; + +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; + +public class ExternalAuthenticationManagerFactory implements AuthenticationManagerFactory +{ + @Override + public AuthenticationManager createInstance(Configuration configuration) + { + if (configuration.subset("external-auth-manager").isEmpty()) + { + return null; + } + + return new ExternalAuthenticationManager(); + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java index ed15d244eb..3c1b709648 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java @@ -20,9 +20,7 @@ package org.apache.qpid.server.security.auth.manager; import java.io.IOException; import java.security.Principal; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.UnsupportedCallbackException; @@ -30,86 +28,15 @@ import javax.security.sasl.AuthorizeCallback; import javax.security.sasl.Sasl; import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.auth.UsernamePrincipal; public class KerberosAuthenticationManager implements AuthenticationManager { - private static final Logger _logger = Logger.getLogger(KerberosAuthenticationManager.class); - private static final String GSSAPI_MECHANISM = "GSSAPI"; private final CallbackHandler _callbackHandler = new GssApiCallbackHandler(); - public static class KerberosAuthenticationManagerConfiguration extends ConfigurationPlugin - { - - public static final ConfigurationPluginFactory FACTORY = - new ConfigurationPluginFactory() - { - public List getParentPaths() - { - return Arrays.asList("security.kerberos-auth-manager"); - } - - public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException - { - final ConfigurationPlugin instance = new KerberosAuthenticationManagerConfiguration(); - - instance.setConfiguration(path, config); - return instance; - } - }; - - public String[] getElementsProcessed() - { - return new String[0]; - } - - public void validateConfiguration() throws ConfigurationException - { - } - - } - - - public static final AuthenticationManagerPluginFactory FACTORY = new AuthenticationManagerPluginFactory() - { - public KerberosAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException - { - KerberosAuthenticationManagerConfiguration configuration = - config == null - ? null - : (KerberosAuthenticationManagerConfiguration) config.getConfiguration(KerberosAuthenticationManagerConfiguration.class.getName()); - - // If there is no configuration for this plugin then don't load it. - if (configuration == null) - { - _logger.info("No authentication-manager configuration found for KerberosAuthenticationManager"); - return null; - } - KerberosAuthenticationManager kerberosAuthenticationManager = new KerberosAuthenticationManager(); - kerberosAuthenticationManager.configure(configuration); - return kerberosAuthenticationManager; - } - - public Class getPluginClass() - { - return KerberosAuthenticationManager.class; - } - - public String getPluginName() - { - return KerberosAuthenticationManager.class.getName(); - } - }; - - - private KerberosAuthenticationManager() + KerberosAuthenticationManager() { } @@ -182,11 +109,6 @@ public class KerberosAuthenticationManager implements AuthenticationManager { } - @Override - public void configure(ConfigurationPlugin config) throws ConfigurationException - { - } - private static class GssApiCallbackHandler implements CallbackHandler { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java new file mode 100644 index 0000000000..470a51b6a6 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.manager; + +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; + +public class KerberosAuthenticationManagerFactory implements AuthenticationManagerFactory +{ + @Override + public AuthenticationManager createInstance(Configuration configuration) + { + if (configuration.subset("kerberos-auth-manager").isEmpty()) + { + return null; + } + + return new KerberosAuthenticationManager(); + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java new file mode 100644 index 0000000000..d616bbb7ae --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.manager; + +import java.io.IOException; + +import org.apache.commons.configuration.Configuration; +import org.apache.log4j.Logger; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; +import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase; +import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; +import org.apache.qpid.server.security.auth.database.PrincipalDatabase; + +/** + * Factory for {@link PrincipalDatabaseAuthenticationManager} objects configured with either the + * Plain or Base64MD5 digest {@link PrincipalDatabase} implementation. + */ +public class PrincipalDatabaseAuthManagerFactory implements AuthenticationManagerFactory +{ + private static final Logger LOGGER = Logger.getLogger(PrincipalDatabaseAuthManagerFactory.class); + + @Override + public AuthenticationManager createInstance(Configuration configuration) + { + if(configuration.subset("pd-auth-manager").isEmpty()) + { + return null; + } + + String clazz = configuration.getString("pd-auth-manager.principal-database.class"); + String passwordArgumentName = configuration.getString("pd-auth-manager.principal-database.attributes.attribute.name"); + String passwordFile = configuration.getString("pd-auth-manager.principal-database.attributes.attribute.value"); + + PrincipalDatabase principalDatabase = createKnownImplementation(clazz); + if (principalDatabase == null) + { + LOGGER.warn("Config for pd-auth-manager found but principal-database class specified in config " + clazz + + " not recognised."); + return null; + } + + if (!"passwordFile".equals(passwordArgumentName) || passwordFile == null) + { + LOGGER.warn("Config for pd-auth-manager found but config incomplete - expected attributes not found."); + return null; + } + + try + { + principalDatabase.setPasswordFile(passwordFile); + } + catch (IOException e) + { + throw new RuntimeException(e.getMessage(), e); + } + + return new PrincipalDatabaseAuthenticationManager(principalDatabase); + } + + private PrincipalDatabase createKnownImplementation(String clazz) + { + if (PlainPasswordFilePrincipalDatabase.class.getName().equals(clazz)) + { + return new PlainPasswordFilePrincipalDatabase(); + } + else if (Base64MD5PasswordFilePrincipalDatabase.class.getName().equals(clazz)) + { + return new Base64MD5PasswordFilePrincipalDatabase(); + } + else + { + return null; + } + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java index 529f2bf6a8..8f84732f36 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java @@ -21,14 +21,8 @@ package org.apache.qpid.server.security.auth.manager; import java.security.Principal; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; -import org.apache.qpid.configuration.PropertyException; -import org.apache.qpid.configuration.PropertyUtils; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; import org.apache.qpid.server.security.auth.database.PrincipalDatabase; @@ -42,16 +36,10 @@ import javax.security.sasl.Sasl; import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; import javax.security.sasl.SaslServerFactory; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; + import java.security.Security; -import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.TreeMap; @@ -59,27 +47,12 @@ import java.util.TreeMap; * Concrete implementation of the AuthenticationManager that determines if supplied * user credentials match those appearing in a PrincipalDatabase. The implementation * of the PrincipalDatabase is determined from the configuration. - * - * This implementation also registers the JMX UserManagemement MBean. - * - * This plugin expects configuration such as: - * - *
- * <pd-auth-manager>
- *   <principal-database>
- *      <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
- *      <attributes>
- *         <attribute>
- *              <name>passwordFile</name>
- *              <value>${conf}/passwd</value>
- *          </attribute>
- *      </attributes>
- *   </principal-database>
- * </pd-auth-manager>
- * 
*/ public class PrincipalDatabaseAuthenticationManager implements AuthenticationManager { + public static final String PD_CLASS = "pd.class"; + public static final String PD_PASSWORD_FILE = "pd.passwordFile"; + private static final Logger _logger = Logger.getLogger(PrincipalDatabaseAuthenticationManager.class); /** The list of mechanisms, in the order in which they are configured (i.e. preferred order) */ @@ -94,96 +67,11 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan */ private final Map> _serverCreationProperties = new HashMap>(); - private PrincipalDatabase _principalDatabase = null; - - public static final AuthenticationManagerPluginFactory FACTORY = new AuthenticationManagerPluginFactory() - { - public PrincipalDatabaseAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException - { - final PrincipalDatabaseAuthenticationManagerConfiguration configuration = - config == null - ? null - : (PrincipalDatabaseAuthenticationManagerConfiguration) config.getConfiguration(PrincipalDatabaseAuthenticationManagerConfiguration.class.getName()); - - // If there is no configuration for this plugin then don't load it. - if (configuration == null) - { - _logger.info("No authentication-manager configuration found for PrincipalDatabaseAuthenticationManager"); - return null; - } - - final PrincipalDatabaseAuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager(); - pdam.configure(configuration); - pdam.initialise(); - return pdam; - } - - public Class getPluginClass() - { - return PrincipalDatabaseAuthenticationManager.class; - } - - public String getPluginName() - { - return PrincipalDatabaseAuthenticationManager.class.getName(); - } - }; - - public static class PrincipalDatabaseAuthenticationManagerConfiguration extends ConfigurationPlugin { - - public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory() - { - public List getParentPaths() - { - return Arrays.asList("security.pd-auth-manager"); - } - - public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException - { - final ConfigurationPlugin instance = new PrincipalDatabaseAuthenticationManagerConfiguration(); - - instance.setConfiguration(path, config); - return instance; - } - }; - - public String[] getElementsProcessed() - { - return new String[] {"principal-database.class", - "principal-database.attributes.attribute.name", - "principal-database.attributes.attribute.value"}; - } - - public void validateConfiguration() throws ConfigurationException - { - } - - public String getPrincipalDatabaseClass() - { - return getConfig().getString("principal-database.class"); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public Map getPdClassAttributeMap() throws ConfigurationException - { - final List argumentNames = (List) getConfig().getList("principal-database.attributes.attribute.name"); - final List argumentValues = (List) getConfig().getList("principal-database.attributes.attribute.value"); - final Map attributes = new HashMap(argumentNames.size()); - - for (int i = 0; i < argumentNames.size(); i++) - { - final String argName = argumentNames.get(i); - final String argValue = argumentValues.get(i); - - attributes.put(argName, argValue); - } - - return Collections.unmodifiableMap(attributes); - } - } + private final PrincipalDatabase _principalDatabase; - protected PrincipalDatabaseAuthenticationManager() + public PrincipalDatabaseAuthenticationManager(PrincipalDatabase pd) { + _principalDatabase = pd; } public void initialise() @@ -246,21 +134,6 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan _logger.info("Initialised " + mechanism + " SASL provider successfully"); } - /** - * @see org.apache.qpid.server.plugins.Plugin#configure(org.apache.qpid.server.configuration.plugins.ConfigurationPlugin) - */ - public void configure(final ConfigurationPlugin config) throws ConfigurationException - { - final PrincipalDatabaseAuthenticationManagerConfiguration pdamConfig = (PrincipalDatabaseAuthenticationManagerConfiguration) config; - final String pdClazz = pdamConfig.getPrincipalDatabaseClass(); - - _logger.info("PrincipalDatabase concrete implementation : " + pdClazz); - - _principalDatabase = createPrincipalDatabaseImpl(pdClazz); - - configPrincipalDatabase(_principalDatabase, pdamConfig); - } - public String getMechanisms() { return _mechanisms; @@ -268,8 +141,11 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException { - return Sasl.createSaslServer(mechanism, "AMQP", localFQDN, _serverCreationProperties.get(mechanism), - _callbackHandlerMap.get(mechanism)); + Map properties = _serverCreationProperties.get(mechanism); + CallbackHandler callbackHandler = _callbackHandlerMap.get(mechanism); + + return Sasl.createSaslServer(mechanism, "AMQP", localFQDN, properties, + callbackHandler); } /** @@ -326,101 +202,8 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan Security.removeProvider(PROVIDER_NAME); } - private PrincipalDatabase createPrincipalDatabaseImpl(final String pdClazz) throws ConfigurationException - { - try - { - return (PrincipalDatabase) Class.forName(pdClazz).newInstance(); - } - catch (InstantiationException ie) - { - throw new ConfigurationException("Cannot instantiate " + pdClazz, ie); - } - catch (IllegalAccessException iae) - { - throw new ConfigurationException("Cannot access " + pdClazz, iae); - } - catch (ClassNotFoundException cnfe) - { - throw new ConfigurationException("Cannot load " + pdClazz + " implementation", cnfe); - } - catch (ClassCastException cce) - { - throw new ConfigurationException("Expecting a " + PrincipalDatabase.class + " implementation", cce); - } - } - public PrincipalDatabase getPrincipalDatabase() { return _principalDatabase; } - - protected void setPrincipalDatabase(final PrincipalDatabase principalDatabase) - { - _principalDatabase = principalDatabase; - } - - private void configPrincipalDatabase(final PrincipalDatabase principalDatabase, final PrincipalDatabaseAuthenticationManagerConfiguration config) - throws ConfigurationException - { - - final Map attributes = config.getPdClassAttributeMap(); - - for (Iterator> iterator = attributes.entrySet().iterator(); iterator.hasNext();) - { - final Entry nameValuePair = iterator.next(); - final String methodName = generateSetterName(nameValuePair.getKey()); - final Method method; - try - { - method = principalDatabase.getClass().getMethod(methodName, String.class); - } - catch (Exception e) - { - throw new ConfigurationException("No method " + methodName + " found in class " - + principalDatabase.getClass() - + " hence unable to configure principal database. The method must be public and " - + "have a single String argument with a void return type", e); - } - try - { - method.invoke(principalDatabase, PropertyUtils.replaceProperties(nameValuePair.getValue())); - } - catch (IllegalArgumentException e) - { - throw new ConfigurationException(e.getMessage(), e); - } - catch (PropertyException e) - { - throw new ConfigurationException(e.getMessage(), e); - } - catch (IllegalAccessException e) - { - throw new ConfigurationException(e.getMessage(), e); - } - catch (InvocationTargetException e) - { - // QPID-1347.. InvocationTargetException wraps the checked exception thrown from the reflective - // method call. Pull out the underlying message and cause to make these more apparent to the user. - throw new ConfigurationException(e.getCause().getMessage(), e.getCause()); - } - } - } - - private String generateSetterName(String argName) throws ConfigurationException - { - if ((argName == null) || (argName.length() == 0)) - { - throw new ConfigurationException("Argument names must have length >= 1 character"); - } - - if (Character.isLowerCase(argName.charAt(0))) - { - argName = Character.toUpperCase(argName.charAt(0)) + argName.substring(1); - } - - final String methodName = "set" + argName; - return methodName; - } - } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java index 8490a1c373..69c3c19a69 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java @@ -21,10 +21,8 @@ package org.apache.qpid.server.security.auth.manager; import java.io.IOException; import java.security.Principal; -import java.util.Arrays; import java.util.HashMap; import java.util.Hashtable; -import java.util.List; import javax.naming.Context; import javax.naming.NamingEnumeration; import javax.naming.NamingException; @@ -40,11 +38,7 @@ import javax.security.sasl.AuthorizeCallback; import javax.security.sasl.Sasl; import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.auth.UsernamePrincipal; import org.apache.qpid.server.security.auth.sasl.plain.PlainPasswordCallback; @@ -54,123 +48,25 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager private static final Logger _logger = Logger.getLogger(SimpleLDAPAuthenticationManager.class); private static final String PLAIN_MECHANISM = "PLAIN"; - private static final String DEFAULT_LDAP_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory"; - private String _providerSearchURL; - private String _searchContext; - private String _searchFilter; - private String _providerAuthURL; - private String _ldapContextFactory; - - public static class SimpleLDAPAuthenticationManagerConfiguration extends ConfigurationPlugin - { - - public static final ConfigurationPluginFactory FACTORY = - new ConfigurationPluginFactory() - { - public List getParentPaths() - { - return Arrays.asList("security.simple-ldap-auth-manager"); - } - - public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException - { - final ConfigurationPlugin instance = new SimpleLDAPAuthenticationManagerConfiguration(); - - instance.setConfiguration(path, config); - return instance; - } - }; - - private static final String PROVIDER_URL = "provider-url"; - private static final String PROVIDER_SEARCH_URL = "provider-search-url"; - private static final String PROVIDER_AUTH_URL = "provider-auth-url"; - private static final String SEARCH_CONTEXT = "search-context"; - private static final String SEARCH_FILTER = "search-filter"; - private static final String LDAP_CONTEXT_FACTORY = "ldap-context-factory"; - - public String[] getElementsProcessed() - { - return new String[] {PROVIDER_URL, PROVIDER_SEARCH_URL, PROVIDER_AUTH_URL, SEARCH_CONTEXT, SEARCH_FILTER, - LDAP_CONTEXT_FACTORY}; - } - - public void validateConfiguration() throws ConfigurationException - { - } - - public String getLDAPContextFactory() - { - return getConfig().getString(LDAP_CONTEXT_FACTORY, DEFAULT_LDAP_CONTEXT_FACTORY); - } - - - public String getProviderURL() - { - return getConfig().getString(PROVIDER_URL); - } + private final String _providerSearchURL; + private final String _providerAuthURL; + private final String _searchContext; + private final String _searchFilter; + private final String _ldapContextFactory; - public String getProviderSearchURL() - { - return getConfig().getString(PROVIDER_SEARCH_URL, getProviderURL()); - } - - public String getSearchContext() - { - return getConfig().getString(SEARCH_CONTEXT); - } - - public String getSearchFilter() - { - return getConfig().getString(SEARCH_FILTER); - } - - public String getProviderAuthURL() - { - return getConfig().getString(PROVIDER_AUTH_URL, getProviderURL()); - } - } - - - public static final AuthenticationManagerPluginFactory FACTORY = new AuthenticationManagerPluginFactory() - { - public SimpleLDAPAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException - { - SimpleLDAPAuthenticationManagerConfiguration configuration = - config == null - ? null - : (SimpleLDAPAuthenticationManagerConfiguration) config.getConfiguration(SimpleLDAPAuthenticationManagerConfiguration.class.getName()); - - // If there is no configuration for this plugin then don't load it. - if (configuration == null) - { - _logger.info("No authentication-manager configuration found for SimpleLDAPAuthenticationManager"); - return null; - } - SimpleLDAPAuthenticationManager simpleLDAPAuthenticationManager = new SimpleLDAPAuthenticationManager(); - simpleLDAPAuthenticationManager.configure(configuration); - return simpleLDAPAuthenticationManager; - } - - public Class getPluginClass() - { - return SimpleLDAPAuthenticationManager.class; - } - - public String getPluginName() - { - return SimpleLDAPAuthenticationManager.class.getName(); - } - }; - - - private SimpleLDAPAuthenticationManager() + SimpleLDAPAuthenticationManager(String providerSearchUrl, String providerAuthUrl, String searchContext, String searchFilter, String ldapContextFactory) { + _providerSearchURL = providerSearchUrl; + _providerAuthURL = providerAuthUrl; + _searchContext = searchContext; + _searchFilter = searchFilter; + _ldapContextFactory = ldapContextFactory; } @Override public void initialise() { - + validateInitialDirContext(); } @Override @@ -257,17 +153,8 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager { } - @Override - public void configure(ConfigurationPlugin config) throws ConfigurationException + private void validateInitialDirContext() { - SimpleLDAPAuthenticationManagerConfiguration ldapConfig = (SimpleLDAPAuthenticationManagerConfiguration) config; - - _ldapContextFactory = ldapConfig.getLDAPContextFactory(); - _providerSearchURL = ldapConfig.getProviderSearchURL(); - _providerAuthURL = ldapConfig.getProviderAuthURL(); - _searchContext = ldapConfig.getSearchContext(); - _searchFilter = ldapConfig.getSearchFilter(); - Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, _ldapContextFactory); env.put(Context.PROVIDER_URL, _providerSearchURL); @@ -275,11 +162,11 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager try { - new InitialDirContext(env); + new InitialDirContext(env).close(); } catch (NamingException e) { - throw new ConfigurationException("Unable to establish anonymous connection to the ldap server at " + _providerSearchURL, e); + throw new RuntimeException("Unable to establish anonymous connection to the ldap server at " + _providerSearchURL, e); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java new file mode 100644 index 0000000000..8a1d23ffb1 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.manager; + +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; + +public class SimpleLDAPAuthenticationManagerFactory implements AuthenticationManagerFactory +{ + + private static final String DEFAULT_LDAP_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory"; + + @Override + public AuthenticationManager createInstance(Configuration configuration) + { + + final Configuration subset = configuration.subset("simple-ldap-auth-manager"); + if(subset.isEmpty()) + { + return null; + } + + String providerUrl = configuration.getString("simple-ldap-auth-manager.provider-url"); + String providerSearchUrl = configuration.getString("simple-ldap-auth-manager.provider-search-url", providerUrl); + String providerAuthUrl = configuration.getString("simple-ldap-auth-manager.provider-auth-url", providerUrl); + String searchContext = configuration.getString("simple-ldap-auth-manager.search-context"); + String searchFilter = configuration.getString("simple-ldap-auth-manager.search-filter"); + String ldapContextFactory = configuration.getString("simple-ldap-auth-manager.ldap-context-factory", DEFAULT_LDAP_CONTEXT_FACTORY); + + return new SimpleLDAPAuthenticationManager(providerSearchUrl, providerAuthUrl, searchContext, searchFilter, ldapContextFactory); + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java index 478f195530..4e12ac0750 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java @@ -139,6 +139,12 @@ public class CRAMMD5HexInitialiser extends UsernamePasswordInitialiser { _realPricipalDatabase.reload(); } + + @Override + public void setPasswordFile(String passwordFile) throws IOException + { + throw new UnsupportedOperationException(); + } } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java index 1b393c3ecf..5cc1085a0d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java @@ -21,19 +21,11 @@ package org.apache.qpid.server.security.group; import java.io.IOException; import java.security.Principal; -import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Set; -import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; import org.apache.qpid.server.security.auth.UsernamePrincipal; /** @@ -54,107 +46,11 @@ import org.apache.qpid.server.security.auth.UsernamePrincipal; */ public class FileGroupManager implements GroupManager { - private static final Logger LOGGER = Logger.getLogger(FileGroupManager.class); + private final FileGroupDatabase _groupDatabase; - public static final GroupManagerPluginFactory FACTORY = new GroupManagerPluginFactory() - { - public FileGroupManager newInstance(final ConfigurationPlugin config) throws ConfigurationException - { - final FileGroupManagerConfiguration configuration = - config == null - ? null - : (FileGroupManagerConfiguration) config.getConfiguration(FileGroupManagerConfiguration.class.getName()); - - // If there is no configuration for this plugin then don't load it. - if (configuration == null) - { - LOGGER.info("No file-group-manager configuration found for FileGroupManager"); - return null; - } - - final FileGroupManager fgm = new FileGroupManager(); - fgm.configure(configuration); - return fgm; - } - - public Class getPluginClass() - { - return FileGroupManager.class; - } - - public String getPluginName() - { - return FileGroupManager.class.getName(); - } - }; - - private FileGroupDatabase _groupDatabase; - - public static class FileGroupManagerConfiguration extends ConfigurationPlugin { - - public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory() - { - public List getParentPaths() - { - return Arrays.asList("security.file-group-manager"); - } - - public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException - { - final ConfigurationPlugin instance = new FileGroupManagerConfiguration(); - - instance.setConfiguration(path, config); - return instance; - } - }; - public String[] getElementsProcessed() - { - return new String[] {"attributes.attribute.name", - "attributes.attribute.value"}; - } - - public void validateConfiguration() throws ConfigurationException - { - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public Map getAttributeMap() throws ConfigurationException - { - final List argumentNames = (List) getConfig().getList("attributes.attribute.name"); - final List argumentValues = (List) getConfig().getList("attributes.attribute.value"); - final Map attributes = new HashMap(argumentNames.size()); - - for (int i = 0; i < argumentNames.size(); i++) - { - final String argName = argumentNames.get(i); - final String argValue = argumentValues.get(i); - - attributes.put(argName, argValue); - } - - return Collections.unmodifiableMap(attributes); - } - } - - @Override - public void configure(ConfigurationPlugin config) - throws ConfigurationException + public FileGroupManager(String groupFile) throws ConfigurationException { - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("configuring file group plugin"); - } - - FileGroupManagerConfiguration fileGroupMangerConfig = (FileGroupManagerConfiguration) config; - Map attribMap = fileGroupMangerConfig.getAttributeMap(); - String groupFile = attribMap.get("groupFile"); - - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("Group file : " + groupFile); - } - _groupDatabase = new FileGroupDatabase(); try { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java new file mode 100644 index 0000000000..a55cdbf602 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.security.group; + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.plugin.GroupManagerFactory; + +public class FileGroupManagerFactory implements GroupManagerFactory +{ + private static final String GROUP_FILE_MARKER = "groupFile"; + private static final String FILE_ATTRIBUTE_VALUE = "file-group-manager.attributes.attribute.value"; + private static final String FILE_ATTRIBUTE_NAME = "file-group-manager.attributes.attribute.name"; + + @Override + public GroupManager createInstance(Configuration configuration) + { + if(configuration.subset("file-group-manager").isEmpty()) + { + return null; + } + + String groupFileArgumentName = configuration.getString(FILE_ATTRIBUTE_NAME); + String groupFile = configuration.getString(FILE_ATTRIBUTE_VALUE); + + if (!GROUP_FILE_MARKER.equals(groupFileArgumentName)) + { + throw new RuntimeException("Config for file-group-manager found but " + FILE_ATTRIBUTE_NAME + + " has no value or " + groupFileArgumentName + + " does not equal " + GROUP_FILE_MARKER); + } + + if (groupFile == null) + { + throw new RuntimeException("Config for file-group-manager found but " + FILE_ATTRIBUTE_VALUE + " has no value." + + " Filename expected."); + } + + try + { + return new FileGroupManager(groupFile); + } + catch (ConfigurationException e) + { + throw new RuntimeException(e); + } + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java index 30510eaad5..6d2df86919 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java @@ -22,9 +22,7 @@ package org.apache.qpid.server.security.group; import java.security.Principal; import java.util.Set; -import org.apache.qpid.server.plugins.Plugin; - -public interface GroupManager extends Plugin +public interface GroupManager { Set getGroupPrincipalsForUser(String user); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManagerPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManagerPluginFactory.java deleted file mode 100644 index dc5ab33668..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManagerPluginFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.security.group; - -import org.apache.qpid.server.plugins.PluginFactory; - -public interface GroupManagerPluginFactory extends PluginFactory -{ - -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java deleted file mode 100644 index bdcfd86f82..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.signal; - -import org.apache.log4j.Logger; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -public abstract class SignalHandlerTask -{ - private static final Logger LOGGER = Logger.getLogger(SignalHandlerTask.class); - - private static final String HANDLE_METHOD = "handle"; - private static final String SUN_MISC_SIGNAL_CLASS = "sun.misc.Signal"; - private static final String SUN_MISC_SIGNAL_HANDLER_CLASS = "sun.misc.SignalHandler"; - - public boolean register(final String signalName) - { - try - { - //try to load the signal handling classes - Class signalClazz = Class.forName(SUN_MISC_SIGNAL_CLASS); - Class handlerClazz = Class.forName(SUN_MISC_SIGNAL_HANDLER_CLASS); - - //create an InvocationHandler that just executes the SignalHandlerTask - InvocationHandler invoker = new InvocationHandler() - { - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable - { - handle(); - - return null; - } - }; - - //create a dynamic proxy implementing SignalHandler - Object handler = Proxy.newProxyInstance(handlerClazz.getClassLoader(), new Class[]{handlerClazz}, invoker); - - //create the Signal to handle - Constructor signalConstructor = signalClazz.getConstructor(String.class); - Object signal = signalConstructor.newInstance(signalName); - - //invoke the Signal.handle(signal, handler) method - Method handleMethod = signalClazz.getMethod(HANDLE_METHOD, signalClazz, handlerClazz); - handleMethod.invoke(null, signal, handler); - } - catch (Exception e) - { - LOGGER.debug("Unable to register handler for Signal " + signalName + " due to exception: " + e, e); - return false; - } - - return true; - } - - public abstract void handle(); - - public static String getPlatformDescription() - { - String name = System.getProperty("os.name"); - String osVer = System.getProperty("os.version"); - String jvmVendor = System.getProperty("java.vm.vendor"); - String jvmName = System.getProperty("java.vm.name"); - String javaRuntimeVer = System.getProperty("java.runtime.version"); - - return "OS: " + name + " " + osVer + ", JVM:" + jvmVendor + " " + jvmName + " " + javaRuntimeVer; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java index 05963ee874..2c9edb4ffe 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java @@ -31,7 +31,6 @@ import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.exchange.ExchangeFactory; import org.apache.qpid.server.exchange.ExchangeInUseException; import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.exchange.ExchangeType; import org.apache.qpid.server.exchange.HeadersExchange; import org.apache.qpid.server.filter.FilterManager; import org.apache.qpid.server.filter.FilterManagerFactory; @@ -41,6 +40,7 @@ import org.apache.qpid.server.logging.messages.ExchangeMessages; import org.apache.qpid.server.message.MessageMetaData_0_10; import org.apache.qpid.server.message.MessageTransferMessage; import org.apache.qpid.server.model.UUIDGenerator; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.AMQQueueFactory; import org.apache.qpid.server.queue.BaseQueue; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java index 7e1ffb7ed8..caff2b11d2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -65,8 +64,6 @@ import org.apache.qpid.server.store.HAMessageStore; import org.apache.qpid.server.store.MessageStore; import org.apache.qpid.server.store.OperationalLoggingListener; import org.apache.qpid.server.txn.DtxRegistry; -import org.apache.qpid.server.virtualhost.plugins.VirtualHostPlugin; -import org.apache.qpid.server.virtualhost.plugins.VirtualHostPluginFactory; public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.RegistryChangeListener, EventListener { @@ -130,8 +127,7 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr CurrentActor.get().message(VirtualHostMessages.CREATED(_name)); - _securityManager = new SecurityManager(_appRegistry.getSecurityManager()); - _securityManager.configureHostPlugins(_vhostConfig); + _securityManager = new SecurityManager(_appRegistry.getSecurityManager(), _vhostConfig.getConfig()); _connectionRegistry = new ConnectionRegistry(); _connectionRegistry.addRegistryChangeListener(this); @@ -141,7 +137,6 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr _queueRegistry = new DefaultQueueRegistry(this); _exchangeFactory = new DefaultExchangeFactory(this); - _exchangeFactory.initialise(_vhostConfig); _exchangeRegistry = new DefaultExchangeRegistry(this); @@ -187,38 +182,9 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr */ private void initialiseHouseKeeping(long period) { - if (period != 0L) { scheduleHouseKeepingTask(period, new VirtualHostHouseKeepingTask()); - - Map plugins = _appRegistry.getPluginManager().getVirtualHostPlugins(); - - if (plugins != null) - { - for (Map.Entry entry : plugins.entrySet()) - { - String pluginName = entry.getKey(); - VirtualHostPluginFactory factory = entry.getValue(); - try - { - VirtualHostPlugin plugin = factory.newInstance(this); - - // If we had configuration for the plugin the schedule it. - if (plugin != null) - { - _houseKeepingTasks.scheduleAtFixedRate(plugin, plugin.getDelay() / 2, - plugin.getDelay(), plugin.getTimeUnit()); - - _logger.info("Loaded VirtualHostPlugin:" + plugin); - } - } - catch (RuntimeException e) - { - _logger.error("Unable to load VirtualHostPlugin:" + pluginName + " due to:" + e.getMessage(), e); - } - } - } } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java deleted file mode 100644 index 191f8041d2..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.virtualhost.plugins; - -import org.apache.log4j.Logger; - -import org.apache.qpid.server.virtualhost.HouseKeepingTask; -import org.apache.qpid.server.virtualhost.VirtualHost; - -import java.util.concurrent.TimeUnit; - -public abstract class VirtualHostHouseKeepingPlugin extends HouseKeepingTask implements VirtualHostPlugin -{ - private final Logger _logger = Logger.getLogger(getClass()); - - public VirtualHostHouseKeepingPlugin(VirtualHost vhost) - { - super(vhost); - } - - - /** - * Long value representing the delay between repeats - * - * @return - */ - public abstract long getDelay(); - - /** - * Option to specify what the delay value represents - * - * @return - * - * @see java.util.concurrent.TimeUnit for valid value. - */ - public abstract TimeUnit getTimeUnit(); - - - protected Logger getLogger() - { - return _logger; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java deleted file mode 100644 index 35f6228ab9..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.virtualhost.plugins; - -import org.apache.qpid.server.plugins.Plugin; - -import java.util.concurrent.TimeUnit; - -public interface VirtualHostPlugin extends Runnable, Plugin -{ - /** - * Long value representing the delay between repeats - * - * @return - */ - public long getDelay(); - - /** - * Option to specify what the delay value represents - * @see java.util.concurrent.TimeUnit for valid value. - * @return - */ - public TimeUnit getTimeUnit(); -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java deleted file mode 100644 index c8bea18444..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.virtualhost.plugins; - -import org.apache.qpid.server.virtualhost.VirtualHost; - -public interface VirtualHostPluginFactory -{ - public VirtualHostHouseKeepingPlugin newInstance(VirtualHost vhost); -} diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory new file mode 100644 index 0000000000..afbc7c886a --- /dev/null +++ b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory @@ -0,0 +1,5 @@ +org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory +org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManagerFactory +org.apache.qpid.server.security.auth.manager.KerberosAuthenticationManagerFactory +org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthManagerFactory +org.apache.qpid.server.security.auth.manager.SimpleLDAPAuthenticationManagerFactory diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType new file mode 100644 index 0000000000..26aa70c31f --- /dev/null +++ b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType @@ -0,0 +1,4 @@ +org.apache.qpid.server.exchange.DirectExchangeType +org.apache.qpid.server.exchange.TopicExchangeType +org.apache.qpid.server.exchange.FanoutExchangeType +org.apache.qpid.server.exchange.HeadersExchangeType diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory new file mode 100644 index 0000000000..33ae92181b --- /dev/null +++ b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory @@ -0,0 +1 @@ +org.apache.qpid.server.security.group.FileGroupManagerFactory \ No newline at end of file -- cgit v1.2.1