summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/java/broker/src')
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java5
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java13
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java54
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java4
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java90
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java9
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java)170
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java1
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java95
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java1
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java42
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java33
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java1
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java4
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java1
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java36
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java31
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java36
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java32
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java37
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java33
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManagerPluginFactory.java)12
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java2
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java2
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java27
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java28
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java)5
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java27
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ManagementFactory.java28
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java72
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java51
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java91
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties135
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java32
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java32
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java392
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java4
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java171
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java42
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java6
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java57
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java122
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java)14
-rwxr-xr-xqpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java179
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java75
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java30
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java43
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java86
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java2
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java80
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java)26
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java3
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java70
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java82
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java)32
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java80
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java)19
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java92
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java241
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java143
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java50
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java6
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java108
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java65
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java4
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java89
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java2
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java36
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java61
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java28
-rw-r--r--qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory5
-rw-r--r--qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType4
-rw-r--r--qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory1
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java39
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java (renamed from qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java)12
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java226
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java8
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java94
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java55
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java2
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java)23
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java42
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java303
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java49
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java139
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java318
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java46
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java6
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java90
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java61
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java119
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java4
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java28
93 files changed, 1759 insertions, 3727 deletions
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<Integer> getIncludedPorts(final ProtocolInclusion includeProtocol)
{
final Set<Integer> 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<ConfigurationPlugin> getConfigurationPlugins(String configurationElement, Configuration configuration) throws ConfigurationException
- {
- List<ConfigurationPlugin> plugins = new ArrayList<ConfigurationPlugin>();
- Map<List<String>, ConfigurationPluginFactory> factories =
- ApplicationRegistry.getInstance().getPluginManager().getConfigurationPlugins();
-
- for (Entry<List<String>, 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<String, VirtualHostConfiguration> _virtualHosts = new HashMap<String, VirtualHostConfiguration>();
@@ -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.
* <p>
* Called by {@link ApplicationRegistry#initialise()}.
* <p>
@@ -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<String, QueueConfiguration> _queues = new HashMap<String, QueueConfiguration>();
@@ -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/ConfigurationPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java
index c7f600df8a..0e7c19df87 100644
--- 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/AbstractConfiguration.java
@@ -23,25 +23,16 @@ 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
+public abstract class AbstractConfiguration
{
- protected static final Logger _logger = Logger.getLogger(ConfigurationPlugin.class);
-
- private Map<String, ConfigurationPlugin>
- _pluginConfiguration = new HashMap<String, ConfigurationPlugin>();
+ protected static final Logger _logger = Logger.getLogger(AbstractConfiguration.class);
private Configuration _config;
@@ -69,11 +60,6 @@ public abstract class ConfigurationPlugin
return _config;
}
- public <C extends ConfigurationPlugin> C getConfiguration(String plugin)
- {
- return (C) _pluginConfiguration.get(plugin);
- }
-
/**
* Sets the configuration for this plugin
*
@@ -118,7 +104,7 @@ public abstract class ConfigurationPlugin
// 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.
+ // configuration they don't have to.
int bracketIndex = tag.indexOf("[");
if (bracketIndex != -1)
{
@@ -140,62 +126,9 @@ public abstract class ConfigurationPlugin
}
}
- offerRemainingConfigurationToOtherPlugins(path, configuration, elements);
-
validateConfiguration();
}
- private void offerRemainingConfigurationToOtherPlugins(String path,
- Configuration configuration, Set<String> 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<ConfigurationPlugin> 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)
{
@@ -382,103 +315,6 @@ public abstract class ConfigurationPlugin
}
}
- /**
- * 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<String, ConfigurationPlugin> 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<String,ConfigurationPlugin> 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("\\.", "\\.\\.");
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<AMQShortString, ExchangeType<? extends Exchange>> _exchangeClassMap = new HashMap<AMQShortString, ExchangeType<? extends Exchange>>();
+ 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<AMQShortString, ExchangeType<? extends Exchange>> _exchangeClassMap = new HashMap<AMQShortString, ExchangeType<? extends Exchange>>();
public DefaultExchangeFactory(VirtualHost host)
{
_host = host;
- registerExchangeType(DirectExchange.TYPE);
- registerExchangeType(TopicExchange.TYPE);
- registerExchangeType(HeadersExchange.TYPE);
- registerExchangeType(FanoutExchange.TYPE);
+
+ @SuppressWarnings("rawtypes")
+ Iterable<ExchangeType> 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<? extends Exchange> type)
+ @SuppressWarnings("rawtypes")
+ protected Iterable<ExchangeType> loadExchangeTypes()
{
- _exchangeClassMap.put(type.getName(), type);
+ return new QpidServiceLoader<ExchangeType>().atLeastOneInstanceOf(ExchangeType.class);
}
public Collection<ExchangeType<? extends Exchange>> getRegisteredTypes()
{
return _exchangeClassMap.values();
}
-
+
public Collection<ExchangeType<? extends Exchange>> getPublicCreatableTypes()
{
Collection<ExchangeType<? extends Exchange>> 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<? extends ExchangeType> exchangeTypeClass = exchangeType.getClass();
- ExchangeType<? extends 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<Binding> _bindings = new CopyOnWriteArraySet<Binding>();
@@ -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<String, BindingSet> _bindingsByKey =
new ConcurrentHashMap<String, BindingSet>();
- public static final ExchangeType<DirectExchange> TYPE = new ExchangeType<DirectExchange>()
- {
-
- public AMQShortString getName()
- {
- return ExchangeDefaults.DIRECT_EXCHANGE_CLASS;
- }
-
- public Class<DirectExchange> 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<DirectExchange> 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<DirectExchange>
+{
+ 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<ExchangeType<? extends Exchange>> getRegisteredTypes();
Collection<ExchangeType<? extends Exchange>> 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/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<AMQQueue,Integer> _queues = new ConcurrentHashMap<AMQQueue,Integer>();
- public static final ExchangeType<FanoutExchange> TYPE = new ExchangeType<FanoutExchange>()
- {
-
- public AMQShortString getName()
- {
- return ExchangeDefaults.FANOUT_EXCHANGE_CLASS;
- }
-
- public Class<FanoutExchange> 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<FanoutExchange> 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<FanoutExchange>
+{
+ 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<HeadersBinding>();
- public static final ExchangeType<HeadersExchange> TYPE = new ExchangeType<HeadersExchange>()
- {
-
- public AMQShortString getName()
- {
- return ExchangeDefaults.HEADERS_EXCHANGE_CLASS;
- }
-
- public Class<HeadersExchange> 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<HeadersExchange> TYPE = new HeadersExchangeType();
public HeadersExchange()
{
super(TYPE);
}
-
public ArrayList<BaseQueue> 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<HeadersExchange>
+{
+ 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<TopicExchange> TYPE = new ExchangeType<TopicExchange>()
- {
-
- public AMQShortString getName()
- {
- return ExchangeDefaults.TOPIC_EXCHANGE_CLASS;
- }
-
- public Class<TopicExchange> 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<TopicExchange> 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<TopicExchange>
+{
+ 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/security/group/GroupManagerPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java
index dc5ab33668..86de4aa2f0 100644
--- 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/management/plugin/ManagementPlugin.java
@@ -15,13 +15,11 @@
* 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;
+package org.apache.qpid.server.management.plugin;
-public interface GroupManagerPluginFactory<S extends GroupManager> extends PluginFactory<S>
+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/exchange/ExchangeType.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java
index a01e41f039..40ef6ad6a2 100644
--- 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/plugin/ExchangeType.java
@@ -18,19 +18,18 @@
* under the License.
*
*/
-package org.apache.qpid.server.exchange;
+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<T extends Exchange>
{
public AMQShortString getName();
- public Class<T> 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/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<C>
+{
+ private static final Logger _logger = Logger.getLogger(QpidServiceLoader.class);
+
+ public Iterable<C> instancesOf(Class<C> clazz)
+ {
+ return instancesOf(clazz, false);
+ }
+
+ /**
+ * @throws RuntimeException if at least one implementation is not found.
+ */
+ public Iterable<C> atLeastOneInstanceOf(Class<C> clazz)
+ {
+ return instancesOf(clazz, true);
+ }
+
+ private Iterable<C> instancesOf(Class<C> clazz, boolean atLeastOne)
+ {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ Iterator<C> serviceLoaderIterator = ServiceLoader.load(clazz, classLoader).iterator();
+
+ // create a new list so we can log the count
+ List<C> serviceImplementations = new ArrayList<C>();
+ 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:
- *
- * <code>
- * org.xyz; version=1.0.0, org.xyz.xyz; version=1.0.0,...
- * </code>
- *
- * 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<String, String> _packageNameVersionMap;
- private final Version _qpidPackageReleaseNumber;
-
- public OsgiSystemPackageUtil(final Version qpidPackageReleaseNumber, final Map<String, String> packageNameVersionMap)
- {
- _qpidPackageReleaseNumber = qpidPackageReleaseNumber;
- _packageNameVersionMap = packageNameVersionMap;
- }
-
- public String getFormattedSystemPackageString()
- {
- if (_packageNameVersionMap == null || _packageNameVersionMap.size() == 0)
- {
- return null;
- }
-
- final StringBuilder packages = new StringBuilder();
-
- for(Iterator<String> 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:
-# <package>=<version>
-# and PluginManager will convert this into:
-# <package>; version=<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<P extends Plugin>
-{
- public Class<P> 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<ServiceTracker> _trackers = new ArrayList<ServiceTracker>();
- private Map<String, SecurityPluginFactory> _securityPlugins = new HashMap<String, SecurityPluginFactory>();
- private Map<List<String>, ConfigurationPluginFactory> _configPlugins = new IdentityHashMap<List<String>, ConfigurationPluginFactory>();
- private Map<String, VirtualHostPluginFactory> _vhostPlugins = new HashMap<String, VirtualHostPluginFactory>();
- private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> _authenticationManagerPlugins = new HashMap<String, AuthenticationManagerPluginFactory<? extends Plugin>>();
- private Map<String, GroupManagerPluginFactory<? extends Plugin>> _groupManagerPlugins = new HashMap<String, GroupManagerPluginFactory<? extends Plugin>>();
-
- /** 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<? extends Plugin> pluginFactory : Arrays.asList(
- PrincipalDatabaseAuthenticationManager.FACTORY, AnonymousAuthenticationManager.FACTORY,
- KerberosAuthenticationManager.FACTORY, SimpleLDAPAuthenticationManager.FACTORY,
- ExternalAuthenticationManager.FACTORY))
- {
- _authenticationManagerPlugins.put(pluginFactory.getPluginName(), pluginFactory);
- }
-
- for (GroupManagerPluginFactory<? extends Plugin> 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<BundleActivator> activators = new ArrayList<BundleActivator>();
- _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 <T> Map<String, T> getServices(ServiceTracker tracker)
- {
- Map<String, T> services = new HashMap<String, T>();
-
- 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 <T> Map<String, T> getServices(ServiceTracker tracker, Map<String, T> plugins)
- {
- Map<String, T> services = getServices(tracker);
- services.putAll(plugins);
- return services;
- }
-
- public Map<List<String>, ConfigurationPluginFactory> getConfigurationPlugins()
- {
- Map<List<String>, ConfigurationPluginFactory> services = new IdentityHashMap<List<String>, 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<String, VirtualHostPluginFactory> getVirtualHostPlugins()
- {
- return getServices(_virtualHostTracker, _vhostPlugins);
- }
-
- public Map<String, ExchangeType<?>> getExchanges()
- {
- return getServices(_exchangeTracker);
- }
-
- public Map<String, SecurityPluginFactory> getSecurityPlugins()
- {
- return getServices(_securityTracker, _securityPlugins);
- }
-
- public Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> getAuthenticationManagerPlugins()
- {
- return getServices(_authenticationManagerTracker, _authenticationManagerPlugins);
- }
-
- public Map<String, GroupManagerPluginFactory<? extends Plugin>> 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;
* <p/>
* 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<IApplicationRegistry> _instance = new AtomicReference<IApplicationRegistry>(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<PortBindingListener> _portBindingListeners = new ArrayList<PortBindingListener>();
private int _httpManagementPort = -1, _httpsManagementPort = -1;
@@ -113,6 +105,10 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
private List<GroupManager> _groupManagerList = new ArrayList<GroupManager>();
+ private QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader = new QpidServiceLoader<GroupManagerFactory>();
+
+ private final List<ManagementPlugin> _managmentInstanceList = new ArrayList<ManagementPlugin>();
+
public Map<InetSocketAddress, QpidAcceptor> 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<GroupManagerPluginFactory<? extends Plugin>> 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<? extends Plugin> 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<ManagementFactory> factories = new QpidServiceLoader<ManagementFactory>();
+ 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<GroupManager> createGroupManagers(ServerConfiguration configuration) throws ConfigurationException
+ {
+ List<GroupManager> groupManagerList = new ArrayList<GroupManager>();
+ 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/SecurityPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java
index c3c06bf206..b4831f83e5 100644
--- 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/AccessControl.java
@@ -18,28 +18,26 @@
*/
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.
+ * 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 SecurityPlugin extends Plugin
-{
+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.
*/
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 <em>OSGi</em> .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> _subject = new ThreadLocal<Subject>();
public static final ThreadLocal<Boolean> _accessChecksDisabled = new ClearingThreadLocal(false);
- private PluginManager _pluginManager;
- private Map<String, SecurityPluginFactory> _pluginFactories = new HashMap<String, SecurityPluginFactory>();
- private Map<String, SecurityPlugin> _globalPlugins = new HashMap<String, SecurityPlugin>();
- private Map<String, SecurityPlugin> _hostPlugins = new HashMap<String, SecurityPlugin>();
-
- 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<String> 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<String, AccessControl> _globalPlugins = new HashMap<String, AccessControl>();
+ private Map<String, AccessControl> _hostPlugins = new HashMap<String, AccessControl>();
/**
* 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<AccessControlFactory>()).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<String, SecurityPlugin> configurePlugins(ConfigurationPlugin hostConfig) throws ConfigurationException
- {
- Map<String, SecurityPlugin> plugins = new HashMap<String, SecurityPlugin>();
- 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<String, SecurityPlugin> remainingPlugins = _globalPlugins.isEmpty()
- ? Collections.<String, SecurityPlugin>emptyMap()
- : _hostPlugins.isEmpty() ? _globalPlugins : new HashMap<String, SecurityPlugin>(_globalPlugins);
-
- if(!_hostPlugins.isEmpty())
+ Map<String, AccessControl> remainingPlugins = _globalPlugins.isEmpty()
+ ? Collections.<String, AccessControl>emptyMap()
+ : _hostPlugins.isEmpty() ? _globalPlugins : new HashMap<String, AccessControl>(_globalPlugins);
+
+ if(!_hostPlugins.isEmpty())
{
- for (Entry<String, SecurityPlugin> hostEntry : _hostPlugins.entrySet())
+ for (Entry<String, AccessControl> 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/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<S extends SecurityPlugin> extends PluginFactory<S>
-{
-}
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 <code>LegacyAccess</code> 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<String> 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<LegacyAccess> FACTORY = new SecurityPluginFactory<LegacyAccess>()
- {
- 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<LegacyAccess> 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/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<String> 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<AnonymousAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<AnonymousAuthenticationManager>()
- {
- 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<AnonymousAuthenticationManager> 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/configuration/plugins/ConfigurationPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java
index fa41f3ef06..1dabb3d203 100644
--- 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/security/auth/manager/AnonymousAuthenticationManagerFactory.java
@@ -1,5 +1,4 @@
/*
- *
* 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
@@ -18,21 +17,22 @@
* under the License.
*
*/
-package org.apache.qpid.server.configuration.plugins;
+package org.apache.qpid.server.security.auth.manager;
import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import java.util.List;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
-public interface ConfigurationPluginFactory
+public class AnonymousAuthenticationManagerFactory implements AuthenticationManagerFactory
{
- /**
- * 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<String> getParentPaths();
+ @Override
+ public AuthenticationManager createInstance(Configuration configuration)
+ {
+ if (configuration.subset("anonymous-auth-manager").isEmpty())
+ {
+ return null;
+ }
+
+ return new AnonymousAuthenticationManager();
+ }
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException;
}
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.
* </p>
*/
-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/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<Integer, SubjectCreator> _portToSubjectCreatorMap;
private final List<RegistryChangeListener> _listeners =
Collections.synchronizedList(new ArrayList<RegistryChangeListener>());
+ private final QpidServiceLoader<AuthenticationManagerFactory> _authManagerFactoryServiceLoader;
- public AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, PluginManager _pluginManager, GroupPrincipalAccessor groupPrincipalAccessor)
+ public AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupPrincipalAccessor)
throws ConfigurationException
{
- final Collection<AuthenticationManagerPluginFactory<? extends Plugin>> 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<AuthenticationManagerFactory>());
+ }
- final SecurityConfiguration securityConfiguration = serverConfiguration.getConfiguration(SecurityConfiguration.class.getName());
+ // Exists as separate constructor for unit testing purposes
+ AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupPrincipalAccessor, QpidServiceLoader<AuthenticationManagerFactory> 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<AuthenticationManagerPluginFactory<? extends Plugin>> factories,
- final SecurityConfiguration securityConfiguration)
- throws ConfigurationException
+ private void createAuthManagers(Configuration config)
{
- for(AuthenticationManagerPluginFactory<? extends Plugin> 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<String> 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<ExternalAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<ExternalAuthenticationManager>()
- {
- 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<ExternalAuthenticationManager> 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/virtualhost/plugins/VirtualHostPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java
index 35f6228ab9..686f084c93 100644
--- 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/security/auth/manager/ExternalAuthenticationManagerFactory.java
@@ -1,5 +1,4 @@
/*
- *
* 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
@@ -18,25 +17,22 @@
* under the License.
*
*/
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.qpid.server.plugins.Plugin;
+package org.apache.qpid.server.security.auth.manager;
-import java.util.concurrent.TimeUnit;
+import org.apache.commons.configuration.Configuration;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
-public interface VirtualHostPlugin extends Runnable, Plugin
+public class ExternalAuthenticationManagerFactory implements AuthenticationManagerFactory
{
- /**
- * Long value representing the delay between repeats
- *
- * @return
- */
- public long getDelay();
+ @Override
+ public AuthenticationManager createInstance(Configuration configuration)
+ {
+ if (configuration.subset("external-auth-manager").isEmpty())
+ {
+ return null;
+ }
+
+ return new ExternalAuthenticationManager();
+ }
- /**
- * 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/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<String> 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<KerberosAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<KerberosAuthenticationManager>()
- {
- 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<KerberosAuthenticationManager> 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/AuthenticationManagerPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java
index a51f195761..470a51b6a6 100644
--- 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/KerberosAuthenticationManagerFactory.java
@@ -1,5 +1,4 @@
/*
- *
* 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
@@ -20,13 +19,19 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import org.apache.qpid.server.plugins.PluginFactory;
+import org.apache.commons.configuration.Configuration;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
-/**
- * Factory producing authentication producing configured, initialised authentication
- * managers.
- */
-public interface AuthenticationManagerPluginFactory<S extends AuthenticationManager> extends PluginFactory<S>
+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:
- *
- * <pre>
- * &lt;pd-auth-manager&gt;
- * &lt;principal-database&gt;
- * &lt;class&gt;org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase&lt;/class&gt;
- * &lt;attributes&gt;
- * &lt;attribute&gt;
- * &lt;name>passwordFile&lt;/name&gt;
- * &lt;value>${conf}/passwd&lt;/value&gt;
- * &lt;/attribute&gt;
- * &lt;/attributes&gt;
- * &lt;/principal-database&gt;
- * &lt;/pd-auth-manager&gt;
- * </pre>
*/
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<String, Map<String, ?>> _serverCreationProperties = new HashMap<String, Map<String, ?>>();
- private PrincipalDatabase _principalDatabase = null;
-
- public static final AuthenticationManagerPluginFactory<PrincipalDatabaseAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<PrincipalDatabaseAuthenticationManager>()
- {
- 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<PrincipalDatabaseAuthenticationManager> 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<String> 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<String,String> getPdClassAttributeMap() throws ConfigurationException
- {
- final List<String> argumentNames = (List) getConfig().getList("principal-database.attributes.attribute.name");
- final List<String> argumentValues = (List) getConfig().getList("principal-database.attributes.attribute.value");
- final Map<String,String> attributes = new HashMap<String,String>(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<String, ?> 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<String,String> attributes = config.getPdClassAttributeMap();
-
- for (Iterator<Entry<String, String>> iterator = attributes.entrySet().iterator(); iterator.hasNext();)
- {
- final Entry<String, String> 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<String> 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<SimpleLDAPAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<SimpleLDAPAuthenticationManager>()
- {
- 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<SimpleLDAPAuthenticationManager> 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<String,Object> env = new Hashtable<String, Object>();
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<FileGroupManager> FACTORY = new GroupManagerPluginFactory<FileGroupManager>()
- {
- 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<FileGroupManager> 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<String> 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<String,String> getAttributeMap() throws ConfigurationException
- {
- final List<String> argumentNames = (List) getConfig().getList("attributes.attribute.name");
- final List<String> argumentValues = (List) getConfig().getList("attributes.attribute.value");
- final Map<String,String> attributes = new HashMap<String,String>(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<String,String> 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<Principal> getGroupPrincipalsForUser(String user);
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<String, VirtualHostPluginFactory> plugins = _appRegistry.getPluginManager().getVirtualHostPlugins();
-
- if (plugins != null)
- {
- for (Map.Entry<String, VirtualHostPluginFactory> 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/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
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
index 00b0ad7e39..c77732e356 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
@@ -27,7 +27,6 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.protocol.AmqpProtocolVersion;
import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry;
import org.apache.qpid.server.util.TestApplicationRegistry;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
@@ -116,32 +115,6 @@ public class ServerConfigurationTest extends QpidTestCase
assertEquals(false, _serverConfig.getPlatformMbeanserver());
}
- public void testGetPluginDirectory() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(null, _serverConfig.getPluginDirectory());
-
- // Check value we set
- _config.setProperty("plugin-directory", "/path/to/plugins");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("/path/to/plugins", _serverConfig.getPluginDirectory());
- }
-
- public void testGetCacheDirectory() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(null, _serverConfig.getCacheDirectory());
-
- // Check value we set
- _config.setProperty("cache-directory", "/path/to/cache");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("/path/to/cache", _serverConfig.getCacheDirectory());
- }
-
public void testGetFrameSize() throws ConfigurationException
{
// Check default
@@ -926,7 +899,7 @@ public class ServerConfigurationTest extends QpidTestCase
// Load config
ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
+ ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
ApplicationRegistry.initialise(reg);
// Test config
@@ -959,7 +932,7 @@ public class ServerConfigurationTest extends QpidTestCase
// Load config
ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
+ ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
ApplicationRegistry.initialise(reg);
// Test config
@@ -994,7 +967,7 @@ public class ServerConfigurationTest extends QpidTestCase
// Load config
ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
+ ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
ApplicationRegistry.initialise(reg);
// Test config
@@ -1039,7 +1012,7 @@ public class ServerConfigurationTest extends QpidTestCase
try
{
ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
+ ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
ApplicationRegistry.initialise(reg);
fail("Different virtualhost XML configurations not allowed");
}
@@ -1074,7 +1047,7 @@ public class ServerConfigurationTest extends QpidTestCase
try
{
ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
+ ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
ApplicationRegistry.initialise(reg);
fail("Multiple virtualhost XML configurations not allowed");
}
@@ -1557,7 +1530,7 @@ public class ServerConfigurationTest extends QpidTestCase
// Load config
ApplicationRegistry.remove();
- ApplicationRegistry registry = new ConfigurationFileApplicationRegistry(xml);
+ ApplicationRegistry registry = new ApplicationRegistry(new ServerConfiguration(xml));
ApplicationRegistry.initialise(registry);
ServerConfiguration serverConfiguration = ApplicationRegistry.getInstance().getConfiguration();
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java
index 14c7b8cb20..164e54ac3e 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java
@@ -32,14 +32,14 @@ import java.util.List;
* Test that verifies that given a Configuration a ConfigurationPlugin can
* process and validate that data.
*/
-public class ConfigurationPluginTest extends InternalBrokerBaseCase
+public class AbstractConfigurationTest extends InternalBrokerBaseCase
{
private static final double DOUBLE = 3.14;
private static final long POSITIVE_LONG = 1000;
private static final long NEGATIVE_LONG = -1000;
private static final int LIST_SIZE = 3;
- class ConfigPlugin extends ConfigurationPlugin
+ class TestConfigPlugin extends AbstractConfiguration
{
@Override
public String[] getElementsProcessed()
@@ -68,7 +68,7 @@ public class ConfigurationPluginTest extends InternalBrokerBaseCase
}
- private ConfigPlugin _plugin;
+ private TestConfigPlugin _plugin;
@Override
public void setUp() throws Exception
@@ -93,7 +93,7 @@ public class ConfigurationPluginTest extends InternalBrokerBaseCase
CompositeConfiguration composite = new CompositeConfiguration();
composite.addConfiguration(xmlconfig);
- _plugin = new ConfigPlugin();
+ _plugin = new TestConfigPlugin();
try
{
@@ -110,7 +110,7 @@ public class ConfigurationPluginTest extends InternalBrokerBaseCase
public void testHasConfiguration()
{
assertTrue("Plugin has no configuration ", _plugin.hasConfiguration());
- _plugin = new ConfigPlugin();
+ _plugin = new TestConfigPlugin();
assertFalse("Plugins has configuration", _plugin.hasConfiguration());
}
@@ -142,7 +142,7 @@ public class ConfigurationPluginTest extends InternalBrokerBaseCase
catch (ConfigurationException e)
{
assertEquals("negativeLong should not be reported as positive",
- "ConfigPlugin: unable to configure invalid negativeLong:" + NEGATIVE_LONG, e.getMessage());
+ "TestConfigPlugin: unable to configure invalid negativeLong:" + NEGATIVE_LONG, e.getMessage());
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java
new file mode 100644
index 0000000000..341ab1b372
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java
@@ -0,0 +1,226 @@
+/*
+ *
+ * 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.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.plugin.ExchangeType;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+@SuppressWarnings("rawtypes")
+public class DefaultExchangeFactoryTest extends QpidTestCase
+{
+ private DirectExchangeType _directExchangeType;
+ private TopicExchangeType _topicExchangeType;
+ private FanoutExchangeType _fanoutExchangeType;
+ private HeadersExchangeType _headersExchangeType;
+
+ private List<ExchangeType> _stubbedExchangeTypes;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ _directExchangeType = new DirectExchangeType();
+ _topicExchangeType = new TopicExchangeType();
+ _fanoutExchangeType = new FanoutExchangeType();
+ _headersExchangeType = new HeadersExchangeType();
+ _stubbedExchangeTypes = new ArrayList<ExchangeType>();
+ }
+
+ public void testCreateDefaultExchangeFactory()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ DefaultExchangeFactory factory = new TestExchangeFactory();
+
+ Collection<ExchangeType<? extends Exchange>> registeredTypes = factory.getRegisteredTypes();
+ assertEquals("Unexpected number of exchange types", _stubbedExchangeTypes.size(), registeredTypes.size());
+ assertTrue("Direct exchange type is not found", registeredTypes.contains(_directExchangeType));
+ assertTrue("Fanout exchange type is not found", registeredTypes.contains(_fanoutExchangeType));
+ assertTrue("Topic exchange type is not found", registeredTypes.contains(_topicExchangeType));
+ assertTrue("Headers exchange type is not found", registeredTypes.contains(_headersExchangeType));
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutAllBaseExchangeTypes()
+ {
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ // pass
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutDireactExchangeType()
+ {
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _directExchangeType.getName(), e.getMessage());
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutTopicExchangeType()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _topicExchangeType.getName(), e.getMessage());
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutFanoutExchangeType()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _fanoutExchangeType.getName(), e.getMessage());
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutHeadersExchangeType()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _headersExchangeType.getName(), e.getMessage());
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithDuplicateExchangeTypeName()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_directExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory with duplicate exchange type names");
+ }
+ catch (IllegalStateException e)
+ {
+ assertTrue( "Unexpected exception message", e.getMessage().contains("ExchangeType with type name '"
+ + _directExchangeType.getName() + "' is already registered using class '"
+ + DirectExchangeType.class.getName()));
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithCustomExchangeType()
+ {
+ ExchangeType<?> customeExchangeType = new ExchangeType<Exchange>()
+ {
+ @Override
+ public AMQShortString getName()
+ {
+ return new AMQShortString("my-custom-exchange");
+ }
+
+ @Override
+ public Exchange newInstance(UUID id, VirtualHost host, AMQShortString name, boolean durable, int ticket,
+ boolean autoDelete) throws AMQException
+ {
+ return null;
+ }
+
+ @Override
+ public AMQShortString getDefaultExchangeName()
+ {
+ return null;
+ }
+ };
+
+ _stubbedExchangeTypes.add(customeExchangeType);
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ DefaultExchangeFactory factory = new TestExchangeFactory();
+
+ Collection<ExchangeType<? extends Exchange>> registeredTypes = factory.getRegisteredTypes();
+ assertEquals("Unexpected number of exchange types", _stubbedExchangeTypes.size(), registeredTypes.size());
+ assertTrue("Direct exchange type is not found", registeredTypes.contains(_directExchangeType));
+ assertTrue("Fanout exchange type is not found", registeredTypes.contains(_fanoutExchangeType));
+ assertTrue("Topic exchange type is not found", registeredTypes.contains(_topicExchangeType));
+ assertTrue("Headers exchange type is not found", registeredTypes.contains(_headersExchangeType));
+ assertTrue("Custom exchange type is not found", registeredTypes.contains(customeExchangeType));
+ }
+
+ private final class TestExchangeFactory extends DefaultExchangeFactory
+ {
+ private TestExchangeFactory()
+ {
+ super(null);
+ }
+
+ @Override
+ protected Iterable<ExchangeType> loadExchangeTypes()
+ {
+ return _stubbedExchangeTypes;
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
index 6cb9d9b2e6..72b34868ba 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
@@ -20,10 +20,12 @@
package org.apache.qpid.server.logging.log4j;
import java.io.File;
+import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Level;
+import org.apache.qpid.test.utils.TestFileUtils;
import org.apache.qpid.util.FileUtils;
import junit.framework.TestCase;
@@ -236,10 +238,6 @@ public class LoggingManagementFacadeTest extends TestCase
private String createTestLog4jXml() throws Exception
{
- File dst = File.createTempFile("log4j." + getName(), "xml");
- File filename = new File(getClass().getResource("LoggingFacadeTest.log4j.xml").toURI());
- FileUtils.copy(filename, dst);
- dst.deleteOnExit();
- return dst.getAbsolutePath();
+ return TestFileUtils.createTempFileFromResource(this, "LoggingFacadeTest.log4j.xml").getAbsolutePath();
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java
deleted file mode 100644
index 20abdd48cd..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java
+++ /dev/null
@@ -1,94 +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 org.apache.qpid.test.utils.QpidTestCase;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- *
- */
-public class OsgiSystemPackageUtilTest extends QpidTestCase
-{
- private OsgiSystemPackageUtil _util = null; // Object under test
-
- private Map<String, String> _map = new TreeMap<String, String>(); // Use a TreeMap for unit test in order for determinstic results.
-
- public void testWithOnePackage() throws Exception
- {
- _map.put("org.xyz", "1.0.0");
-
- _util = new OsgiSystemPackageUtil(null, _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertEquals("org.xyz; version=1.0.0", systemPackageString);
- }
-
- public void testWithTwoPackages() throws Exception
- {
- _map.put("org.xyz", "1.0.0");
- _map.put("org.abc", "1.2.3");
-
- _util = new OsgiSystemPackageUtil(null, _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertEquals("org.abc; version=1.2.3, org.xyz; version=1.0.0", systemPackageString);
- }
-
- public void testWithNoPackages() throws Exception
- {
- _util = new OsgiSystemPackageUtil(null, _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertNull(systemPackageString);
- }
-
- public void testWithQpidPackageWithQpidReleaseNumberSet() throws Exception
- {
- _map.put("org.apache.qpid.xyz", "1.0.0");
- _map.put("org.abc", "1.2.3");
-
- _util = new OsgiSystemPackageUtil(new Version("0.19"), _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=0.19.0", systemPackageString);
- }
-
- public void testWithQpidPackageWithoutQpidReleaseNumberSet() throws Exception
- {
- _map.put("org.apache.qpid.xyz", "1.0.0");
- _map.put("org.abc", "1.2.3");
-
- _util = new OsgiSystemPackageUtil(null, _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=1.0.0", systemPackageString);
- }
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java
deleted file mode 100644
index b4bda9a032..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java
+++ /dev/null
@@ -1,55 +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.qpid.server.exchange.ExchangeType;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-import java.util.Map;
-
-public class PluginTest extends InternalBrokerBaseCase
-{
- private static final String TEST_EXCHANGE_CLASS = "org.apache.qpid.extras.exchanges.example.TestExchangeType";
-
- private static final String PLUGIN_DIRECTORY = System.getProperty("example.plugin.target");
- private static final String CACHE_DIRECTORY = System.getProperty("example.cache.target");
-
- @Override
- public void configure()
- {
- getConfiguration().getConfig().addProperty("plugin-directory", PLUGIN_DIRECTORY);
- getConfiguration().getConfig().addProperty("cache-directory", CACHE_DIRECTORY);
- }
-
- public void disabled_testLoadExchanges() throws Exception
- {
- PluginManager manager = getRegistry().getPluginManager();
- Map<String, ExchangeType<?>> exchanges = manager.getExchanges();
- assertNotNull("No exchanges found in " + PLUGIN_DIRECTORY, exchanges);
- assertEquals("Wrong number of exchanges found in " + PLUGIN_DIRECTORY, 2, exchanges.size());
- assertNotNull("Wrong exchange found in " + PLUGIN_DIRECTORY, exchanges.get(TEST_EXCHANGE_CLASS));
- }
-
- public void testNoExchanges() throws Exception
- {
- PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp", null);
- Map<String, ExchangeType<?>> exchanges = manager.getExchanges();
- assertTrue("Exchanges found", exchanges.isEmpty());
- }
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
index 63d4d196e1..358246330a 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
@@ -24,7 +24,7 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
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.LogSubject;
import org.apache.qpid.server.message.ServerMessage;
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java
index ecf08de72e..f670d80ae8 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java
@@ -28,7 +28,6 @@ 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;
@@ -123,22 +122,6 @@ public class PropertiesPrincipalDatabase implements PrincipalDatabase
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<String, AuthenticationProviderInitialiser> getMechanisms()
{
@@ -166,4 +149,10 @@ public class PropertiesPrincipalDatabase implements PrincipalDatabase
{
//No file to update from, so do nothing.
}
+
+ @Override
+ public void setPasswordFile(String passwordFile)
+ {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
index a36e97199f..cfeb7c525b 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
@@ -24,24 +24,13 @@ import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHel
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+
import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase
+public class AnonymousAuthenticationManagerTest extends QpidTestCase
{
-
- private AuthenticationManager _manager = null;
-
- public void setUp() throws Exception
- {
- _manager = AnonymousAuthenticationManager.INSTANCE;
- }
-
+ private AuthenticationManager _manager = new AnonymousAuthenticationManager();
public void tearDown() throws Exception
{
@@ -51,29 +40,6 @@ public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase
}
}
- private ConfigurationPlugin getPlainDatabaseConfig() throws ConfigurationException
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
- }
-
-
- public void testConfiguration() throws Exception
- {
- AuthenticationManager authenticationManager =
- AnonymousAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig());
-
- assertNull("AnonymousAuthenticationManager unexpectedly created when not in config", authenticationManager);
- }
-
public void testGetMechanisms() throws Exception
{
assertEquals("ANONYMOUS", _manager.getMechanisms());
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java
index 9b7131c71a..aeab1e4343 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java
@@ -19,112 +19,101 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
-import java.util.ArrayList;
+import java.security.Principal;
+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 javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
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.auth.AuthenticationResult;
import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
-import org.mockito.Mockito;
-
-import junit.framework.TestCase;
public class AuthenticationManagerRegistryTest extends TestCase
{
- private static final Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> EMPTY_PLUGINMAP = Collections.emptyMap();
+ @SuppressWarnings("unchecked")
+ private QpidServiceLoader<AuthenticationManagerFactory> _authManagerServiceLoader = mock(QpidServiceLoader.class);
- private PluginManager _pluginManager = Mockito.mock(PluginManager.class);
- private ServerConfiguration _serverConfiguration = Mockito.mock(ServerConfiguration.class);
- private SecurityConfiguration _securityConfiguration = Mockito.mock(SecurityConfiguration.class);
+ private ServerConfiguration _serverConfiguration = mock(ServerConfiguration.class);
+ private Configuration _serverCommonsConfig = mock(Configuration.class);
+ private Configuration _securityCommonsConfig = mock(Configuration.class);
- private List<AuthenticationManager> _allCreatedAuthManagers = new ArrayList<AuthenticationManager>();
+ private GroupPrincipalAccessor _groupPrincipalAccessor = mock(GroupPrincipalAccessor.class);
- private GroupPrincipalAccessor _groupPrincipalAccessor = mock(GroupPrincipalAccessor.class);;
+ private TestAuthenticationManager1 _testAuthManager1 = new TestAuthenticationManager1();
+ private TestAuthenticationManager2 _testAuthManager2 = new TestAuthenticationManager2();
+
+ private AuthenticationManagerFactory _testAuthManager1Factory = newMockFactoryProducing(_testAuthManager1);
+ private AuthenticationManagerFactory _testAuthManager2Factory = newMockFactoryProducing(_testAuthManager2);
@Override
protected void setUp() throws Exception
{
super.setUp();
-
- // Setup server configuration to return mock security config.
- when(_serverConfiguration.getConfiguration(SecurityConfiguration.class.getName())).thenReturn(_securityConfiguration);
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- try
- {
- verifyAllCreatedAuthManagersClosed();
- }
- finally
- {
- super.tearDown();
- }
+ when(_serverConfiguration.getConfig()).thenReturn(_serverCommonsConfig);
+ when(_serverCommonsConfig.subset("security")).thenReturn(_securityCommonsConfig);
}
public void testNoAuthenticationManagerFactoryPluginsFound() throws Exception
{
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(EMPTY_PLUGINMAP);
+ String noServicesMessage = "mock exception - no services found";
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenThrow(new RuntimeException(noServicesMessage));
try
{
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
fail("Exception not thrown");
}
- catch (ConfigurationException ce)
+ catch (RuntimeException ce)
{
// PASS
- assertEquals("No authentication manager factory plugins found. Check the desired authentication manager plugin has been placed in the plugins directory.",
- ce.getMessage());
+ assertEquals(noServicesMessage, ce.getMessage());
}
}
public void testSameAuthenticationManagerSpecifiedTwice() throws Exception
{
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
+ List<AuthenticationManagerFactory> duplicateFactories = Arrays.asList(_testAuthManager1Factory, _testAuthManager1Factory);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory, myAuthManagerFactory);
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(duplicateFactories);
try
{
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
fail("Exception not thrown");
}
- catch (ConfigurationException ce)
+ catch (RuntimeException e)
{
- // PASS
- assertEquals("Cannot configure more than one authentication manager of type " + myAuthManagerFactory.getPluginClass().getSimpleName() + ". Remove configuration for one of the authentication managers.",
- ce.getMessage());
+ assertTrue(e.getMessage().contains("Cannot configure more than one authentication manager with name"));
+ assertTrue(e.getMessage().contains(TestAuthenticationManager1.class.getSimpleName()));
}
}
public void testMultipleAuthenticationManagersSpecifiedButNoDefaultSpecified() throws Exception
{
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class);
-
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2);
+ List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory);
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(null);
try
{
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
fail("Exception not thrown");
}
catch (ConfigurationException ce)
@@ -139,17 +128,14 @@ public class AuthenticationManagerRegistryTest extends TestCase
{
String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager";
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class);
+ List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2);
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(myDefaultAuthManagerSimpleClassName);
try
{
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
fail("Exception not thrown");
}
catch (ConfigurationException ce)
@@ -165,16 +151,14 @@ public class AuthenticationManagerRegistryTest extends TestCase
String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager";
int portNumber = 1234;
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
-
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1);
+ List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory);
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(portNumber, myDefaultAuthManagerSimpleClassName));
try
{
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
fail("Exception not thrown");
}
catch (ConfigurationException ce)
@@ -186,123 +170,186 @@ public class AuthenticationManagerRegistryTest extends TestCase
public void testGetAuthenticationManagerForInetSocketAddress() throws Exception
{
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1);
+ List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory);
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
SubjectCreator subjectCreator = registry.getSubjectCreator(new InetSocketAddress(1234));
- assertEquals("TestAuthenticationManager1", subjectCreator.getMechanisms());
-
- registry.close();
+ assertSubjectCreatorUsingExpectedAuthManager(_testAuthManager1, subjectCreator);
}
public void testGetAuthenticationManagerForNonInetSocketAddress() throws Exception
{
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1);
+ List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory);
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
SubjectCreator subjectCreator = registry.getSubjectCreator(mock(SocketAddress.class));
- assertEquals("TestAuthenticationManager1", subjectCreator.getMechanisms());
-
- registry.close();
+ assertSubjectCreatorUsingExpectedAuthManager(_testAuthManager1, subjectCreator);
}
public void testGetAuthenticationManagerWithMultipleAuthenticationManager() throws Exception
{
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2);
+ List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory);
+
+ AuthenticationManager defaultAuthManger = _testAuthManager1;
+ AuthenticationManager unmappedAuthManager = _testAuthManager2;
+
+ String defaultAuthMangerName = defaultAuthManger.getClass().getSimpleName();
+ String mappedAuthManagerName = unmappedAuthManager.getClass().getSimpleName();
- String defaultAuthManger = myAuthManagerFactory1.getPluginName();
int unmappedPortNumber = 1234;
int mappedPortNumber = 1235;
- String mappedAuthManager = myAuthManagerFactory2.getPluginName();
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthManger);
- when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(mappedPortNumber, mappedAuthManager));
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
+ when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthMangerName);
+ when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(mappedPortNumber, mappedAuthManagerName));
- SubjectCreator subjectCreator = registry.getSubjectCreator(new InetSocketAddress(unmappedPortNumber));
- assertEquals("TestAuthenticationManager1", subjectCreator.getMechanisms());
+ AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
- SubjectCreator subjectCreator2 = registry.getSubjectCreator(new InetSocketAddress(mappedPortNumber));
- assertEquals("TestAuthenticationManager2", subjectCreator2.getMechanisms());
+ SubjectCreator subjectCreatorForDefaultAuthManager = registry.getSubjectCreator(new InetSocketAddress(unmappedPortNumber));
+ assertSubjectCreatorUsingExpectedAuthManager(defaultAuthManger, subjectCreatorForDefaultAuthManager);
- registry.close();
+ SubjectCreator subjectCreatorForUnmappedAuthManager = registry.getSubjectCreator(new InetSocketAddress(mappedPortNumber));
+ assertSubjectCreatorUsingExpectedAuthManager(unmappedAuthManager, subjectCreatorForUnmappedAuthManager);
}
public void testAuthenticationManagersAreClosed() throws Exception
{
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2);
+ AuthenticationManager defaultAuthManager = mock(MockAuthenticationManager1.class);
+ AuthenticationManagerFactory defaultAuthManagerFactory = newMockFactoryProducing(defaultAuthManager);
+
+ AuthenticationManager authManager2 = mock(MockAuthenticationManager2.class);
+ AuthenticationManagerFactory authManagerFactory2 = newMockFactoryProducing(authManager2);
- String defaultAuthManger = myAuthManagerFactory1.getPluginName();
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthManger);
+ List<AuthenticationManagerFactory> factoryList = Arrays.asList(defaultAuthManagerFactory, authManagerFactory2);
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+ String defaultAuthMangerName = defaultAuthManager.getClass().getSimpleName();
+ when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthMangerName);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
+
+ AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
registry.close();
+
+ verify(defaultAuthManager).close();
+ verify(authManager2).close();
}
- private AuthenticationManagerPluginFactory<? extends Plugin> newMockFactoryProducingMockAuthManagerImplementing(Class<? extends AuthenticationManager> authManagerClazz)
- throws ConfigurationException
+ public void testAlreadyInitialisedAuthManagersAreClosedWhenAnotherAuthManagerInitFails() throws Exception
{
- AuthenticationManager myAuthManager = mock(authManagerClazz);
- when(myAuthManager.getMechanisms()).thenReturn(authManagerClazz.getSimpleName()); // used to verify the getAuthenticationManagerFor returns expected impl.
+ AuthenticationManager authManger1 = mock(MockAuthenticationManager1.class);
+ AuthenticationManagerFactory authManager1Factory = newMockFactoryProducing(authManger1);
- AuthenticationManagerPluginFactory myAuthManagerFactory = mock(AuthenticationManagerPluginFactory.class);
- when(myAuthManagerFactory.getPluginClass()).thenReturn(myAuthManager.getClass());
- when(myAuthManagerFactory.getPluginName()).thenReturn(myAuthManager.getClass().getSimpleName());
- when(myAuthManagerFactory.newInstance(_securityConfiguration)).thenReturn(myAuthManager);
+ AuthenticationManager authManager2 = mock(MockAuthenticationManager2.class);
+ AuthenticationManagerFactory authManagerFactory2 = newMockFactoryProducing(authManager2);
- _allCreatedAuthManagers.add(myAuthManager);
+ List<AuthenticationManagerFactory> factoryList = Arrays.asList(authManager1Factory, authManagerFactory2);
+ when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
+
+ doThrow(new RuntimeException("mock auth manager 2 init exception")).when(authManager2).initialise();
+
+ try
+ {
+ new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
+ fail("Exception not thrown");
+ }
+ catch (RuntimeException e)
+ {
+ // PASS
+ }
+
+ verify(authManger1).close();
+ }
+
+
+ private AuthenticationManagerFactory newMockFactoryProducing(AuthenticationManager myAuthManager)
+ {
+ AuthenticationManagerFactory myAuthManagerFactory = mock(AuthenticationManagerFactory.class);
+ when(myAuthManagerFactory.createInstance(_securityCommonsConfig)).thenReturn(myAuthManager);
return myAuthManagerFactory;
}
- private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> createPluginMap(
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory)
+ private void assertSubjectCreatorUsingExpectedAuthManager(AuthenticationManager expectedAuthenticationManager, SubjectCreator subjectCreator)
{
- return createPluginMap(myAuthManagerFactory, null);
+ assertEquals(
+ "The subject creator should be using " + expectedAuthenticationManager + " so its mechanisms should match",
+ expectedAuthenticationManager.getMechanisms(),
+ subjectCreator.getMechanisms());
}
- private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> createPluginMap(
- AuthenticationManagerPluginFactory<? extends Plugin> authManagerFactory1,
- AuthenticationManagerPluginFactory<? extends Plugin> authManagerFactory2)
+ /** @see MockAuthenticationManager2 */
+ private interface MockAuthenticationManager1 extends AuthenticationManager
{
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = new HashMap<String, AuthenticationManagerPluginFactory<? extends Plugin>>();
- pluginMap.put("config.path.unused1", authManagerFactory1);
- if (authManagerFactory2 != null)
- {
- pluginMap.put("config.path.unused2", authManagerFactory2);
- }
- return pluginMap;
}
- private void verifyAllCreatedAuthManagersClosed()
+ /**
+ * I only exist so that mock implementations of me have a different class to {@link MockAuthenticationManager1},
+ * as mandated by {@link AuthenticationManagerRegistry}
+ */
+ private interface MockAuthenticationManager2 extends AuthenticationManager
{
- for (Iterator<AuthenticationManager> iterator = _allCreatedAuthManagers.iterator(); iterator.hasNext();)
+ }
+
+ /**
+ * We use a stub rather than a mock because {@link AuthenticationManagerRegistry} relies on {@link AuthenticationManager} class names,
+ * which are hard to predict for mocks.
+ */
+ private abstract class TestAuthenticationManager implements AuthenticationManager
+ {
+ @Override
+ public void close()
{
- AuthenticationManager authenticationManager = (AuthenticationManager) iterator.next();
- verify(authenticationManager).close();
+ // no-op
+ }
+
+ @Override
+ public void initialise()
+ {
+ // no-op
+ }
+
+ @Override
+ public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public AuthenticationResult authenticate(SaslServer server, byte[] response)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public AuthenticationResult authenticate(String username, String password)
+ {
+ throw new UnsupportedOperationException();
}
}
- private interface TestAuthenticationManager1 extends AuthenticationManager
+ private class TestAuthenticationManager1 extends TestAuthenticationManager
{
+ @Override
+ public String getMechanisms()
+ {
+ return "MECHANISMS1";
+ }
}
- private interface TestAuthenticationManager2 extends AuthenticationManager
+ private class TestAuthenticationManager2 extends TestAuthenticationManager
{
+ /**
+ * Needs to different from {@link TestAuthenticationManager1#getMechanisms()} to aid our test assertions.
+ */
+ @Override
+ public String getMechanisms()
+ {
+ return "MECHANISMS2";
+ }
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
index 4e0643e229..a66d73c47d 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
@@ -23,56 +23,13 @@ import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHel
import javax.security.auth.x500.X500Principal;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ExternalAuthenticationManagerTest extends InternalBrokerBaseCase
+public class ExternalAuthenticationManagerTest extends QpidTestCase
{
-
- private AuthenticationManager _manager = null;
-
- public void setUp() throws Exception
- {
- _manager = ExternalAuthenticationManager.INSTANCE;
- }
-
-
- public void tearDown() throws Exception
- {
- if(_manager != null)
- {
- _manager = null;
- }
- }
-
- private ConfigurationPlugin getPlainDatabaseConfig() throws ConfigurationException
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
- }
-
-
- public void testConfiguration() throws Exception
- {
- AuthenticationManager authenticationManager =
- ExternalAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig());
-
- assertNull("ExternalAuthenticationManager unexpectedly created when not in config", authenticationManager);
- }
+ private AuthenticationManager _manager = new ExternalAuthenticationManager();
public void testGetMechanisms() throws Exception
{
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java
new file mode 100644
index 0000000000..d76ea2674c
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java
@@ -0,0 +1,139 @@
+/*
+ * 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.File;
+import java.io.FileNotFoundException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
+import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
+
+import junit.framework.TestCase;
+
+public class PrincipalDatabaseAuthManagerFactoryTest extends TestCase
+{
+ PrincipalDatabaseAuthManagerFactory _factory = new PrincipalDatabaseAuthManagerFactory();
+ private Configuration _configuration = new XMLConfiguration();
+ private File _emptyPasswordFile;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _emptyPasswordFile = File.createTempFile(getName(), "passwd");
+ _emptyPasswordFile.deleteOnExit();
+ }
+
+ public void testPlainInstanceCreated() throws Exception
+ {
+ _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath());
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
+ assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof PlainPasswordFilePrincipalDatabase);
+ }
+
+ public void testBase64MD5nstanceCreated() throws Exception
+ {
+ _configuration.setProperty("pd-auth-manager.principal-database.class", Base64MD5PasswordFilePrincipalDatabase.class.getName());
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath());
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
+ assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof Base64MD5PasswordFilePrincipalDatabase);
+ }
+
+ public void testPasswordFileNotFound() throws Exception
+ {
+ _emptyPasswordFile.delete();
+
+ _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath());
+
+ try
+ {
+ _factory.createInstance(_configuration);
+ }
+ catch (RuntimeException re)
+ {
+ assertTrue(re.getCause() instanceof FileNotFoundException);
+ }
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForOtherPDImplementation() throws Exception
+ {
+ _configuration.setProperty("pd-auth-manager.principal-database.class", "mypdimpl");
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified() throws Exception
+ {
+ _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
+ // no pd-auth-manager.attributes.attribute.value
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForPlainPDImplementationWrongArgumentName() throws Exception
+ {
+ _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "wrong");
+ _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", "/does/not/matter");
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ if (_emptyPasswordFile == null && _emptyPasswordFile.exists())
+ {
+ _emptyPasswordFile.delete();
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java
index 391eb4e665..1ae667804a 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java
@@ -21,133 +21,91 @@
package org.apache.qpid.server.security.auth.manager;
import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
+import java.security.Provider;
+import java.security.Security;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
+import javax.security.sasl.SaslServerFactory;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
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.PlainPasswordFilePrincipalDatabase;
import org.apache.qpid.server.security.auth.UsernamePrincipal;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-import javax.security.sasl.SaslException;
-import javax.security.sasl.SaslServer;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.security.Provider;
-import java.security.Security;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser;
+import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser;
+import org.apache.qpid.test.utils.QpidTestCase;
/**
- *
* Tests the public methods of PrincipalDatabaseAuthenticationManager.
*
*/
-public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBaseCase
+public class PrincipalDatabaseAuthenticationManagerTest extends QpidTestCase
{
+ private static final String MOCK_MECH_NAME = "MOCK-MECH-NAME";
private static final UsernamePrincipal PRINCIPAL = new UsernamePrincipal("guest");
+
private AuthenticationManager _manager = null; // Class under test
- private String TEST_USERNAME = "guest";
- private String TEST_PASSWORD = "guest";
+ private PrincipalDatabase _principalDatabase;
- /**
- * @see org.apache.qpid.server.util.InternalBrokerBaseCase#tearDown()
- */
@Override
public void tearDown() throws Exception
{
- super.tearDown();
if (_manager != null)
{
_manager.close();
}
+ super.tearDown();
}
- /**
- * @see org.apache.qpid.server.util.InternalBrokerBaseCase#setUp()
- */
- @Override
- public void setUp() throws Exception
+ private void setupMocks() throws Exception
{
- super.setUp();
+ _principalDatabase = mock(PrincipalDatabase.class);
- final String passwdFilename = createPasswordFile().getCanonicalPath();
- final ConfigurationPlugin config = getConfig(PlainPasswordFilePrincipalDatabase.class.getName(),
- "passwordFile", passwdFilename);
+ AuthenticationProviderInitialiser _mockMechInitialiser = mock(AuthenticationProviderInitialiser.class);
+ Map<String, AuthenticationProviderInitialiser> _initialisers = Collections.singletonMap(MOCK_MECH_NAME, _mockMechInitialiser);
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(config);
- }
+ when(_principalDatabase.getMechanisms()).thenReturn(_initialisers);
- /**
- * Tests where the case where the config specifies a PD implementation
- * that is not found.
- */
- public void testPrincipalDatabaseImplementationNotFound() throws Exception
- {
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig("not.Found", null, null));
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- }
+ _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase);
+ _manager.initialise();
}
- /**
- * Tests where the case where the config specifies a PD implementation
- * of the wrong type.
- */
- public void testPrincipalDatabaseImplementationWrongType() throws Exception
+ private void setupMocksWithInitialiser() throws Exception
{
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(String.class.getName(), null, null)); // Not a PrincipalDatabase implementation
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- }
- }
+ _principalDatabase = mock(PrincipalDatabase.class);
- /**
- * Tests the case where a setter with the desired name cannot be found.
- */
- public void testPrincipalDatabaseSetterNotFound() throws Exception
- {
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "noMethod", "test"));
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
+ UsernamePasswordInitialiser usernamePasswordInitialiser = new UsernamePasswordInitialiser()
{
- // PASS
- }
- }
+ @Override
+ public Class<? extends SaslServerFactory> getServerFactoryClassForJCARegistration()
+ {
+ return MySaslServerFactory.class;
+ }
- /**
- * QPID-1347. Make sure the exception message and stack trace is reasonable for an absent password file.
- */
- public void testPrincipalDatabaseThrowsSetterFileNotFound() throws Exception
- {
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "passwordFile", "/not/found"));
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertNotNull("Expected an underlying cause", ce.getCause());
- assertEquals(FileNotFoundException.class, ce.getCause().getClass());
- }
+ @Override
+ public String getMechanismName()
+ {
+ return MOCK_MECH_NAME;
+ }
+ };
+
+ Map<String,AuthenticationProviderInitialiser> initialisers = new HashMap<String, AuthenticationProviderInitialiser>();
+ initialisers.put(MOCK_MECH_NAME, usernamePasswordInitialiser);
+
+ when(_principalDatabase.getMechanisms()).thenReturn(initialisers);
+
+ usernamePasswordInitialiser.initialise(_principalDatabase);
+
+ _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase);
+ _manager.initialise();
}
/**
@@ -155,11 +113,16 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
public void testRegisteredMechanisms() throws Exception
{
+ //Ensure we haven't registered anything yet (though this would really indicate a prior test failure!)
+ Provider qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME);
+ assertNull(qpidProvider);
+
+ setupMocksWithInitialiser();
+
assertNotNull(_manager.getMechanisms());
- // relies on those mechanisms attached to PropertiesPrincipalDatabaseManager
- assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
+ assertEquals(MOCK_MECH_NAME, _manager.getMechanisms());
- Provider qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME);
+ qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME);
assertNotNull(qpidProvider);
}
@@ -169,7 +132,9 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
public void testSaslMechanismCreation() throws Exception
{
- SaslServer server = _manager.createSaslServer("CRAM-MD5", "localhost", null);
+ setupMocksWithInitialiser();
+
+ SaslServer server = _manager.createSaslServer(MOCK_MECH_NAME, "localhost", null);
assertNotNull(server);
// Merely tests the creation of the mechanism. Mechanisms themselves are tested
// by their own tests.
@@ -182,6 +147,7 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
public void testSaslAuthenticationSuccess() throws Exception
{
+ setupMocks();
SaslServer testServer = createTestSaslServer(true, false);
@@ -199,6 +165,8 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
public void testSaslAuthenticationNotCompleted() throws Exception
{
+ setupMocks();
+
SaslServer testServer = createTestSaslServer(false, false);
AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes());
@@ -215,6 +183,8 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
public void testSaslAuthenticationError() throws Exception
{
+ setupMocks();
+
SaslServer testServer = createTestSaslServer(false, true);
AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes());
@@ -222,25 +192,23 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
assertEquals(AuthenticationStatus.ERROR, result.getStatus());
}
- /**
- * Tests that the authenticate method correctly interprets an
- * authentication success.
- *
- */
public void testNonSaslAuthenticationSuccess() throws Exception
{
+ setupMocks();
+
+ when(_principalDatabase.verifyPassword("guest", "guest".toCharArray())).thenReturn(true);
+
AuthenticationResult result = _manager.authenticate("guest", "guest");
assertOnlyContainsWrapped(PRINCIPAL, result.getPrincipals());
assertEquals(AuthenticationStatus.SUCCESS, result.getStatus());
}
- /**
- * Tests that the authenticate method correctly interprets an
- * authentication success.
- *
- */
public void testNonSaslAuthenticationNotCompleted() throws Exception
{
+ setupMocks();
+
+ when(_principalDatabase.verifyPassword("guest", "wrongpassword".toCharArray())).thenReturn(false);
+
AuthenticationResult result = _manager.authenticate("guest", "wrongpassword");
assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
assertEquals(AuthenticationStatus.CONTINUE, result.getStatus());
@@ -251,7 +219,9 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
public void testClose() throws Exception
{
- assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
+ setupMocksWithInitialiser();
+
+ assertEquals(MOCK_MECH_NAME, _manager.getMechanisms());
assertNotNull(Security.getProvider(AuthenticationManager.PROVIDER_NAME));
_manager.close();
@@ -267,94 +237,90 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
private SaslServer createTestSaslServer(final boolean complete, final boolean throwSaslException)
{
- return new SaslServer()
- {
- public String getMechanismName()
- {
- return null;
- }
+ return new MySaslServer(throwSaslException, complete);
+ }
- public byte[] evaluateResponse(byte[] response) throws SaslException
- {
- if (throwSaslException)
- {
- throw new SaslException("Mocked exception");
- }
- return null;
- }
+ public static final class MySaslServer implements SaslServer
+ {
+ private final boolean _throwSaslException;
+ private final boolean _complete;
- public boolean isComplete()
- {
- return complete;
- }
+ public MySaslServer()
+ {
+ this(false, true);
+ }
- public String getAuthorizationID()
- {
- return complete ? "guest" : null;
- }
+ private MySaslServer(boolean throwSaslException, boolean complete)
+ {
+ _throwSaslException = throwSaslException;
+ _complete = complete;
+ }
- public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
- {
- return null;
- }
+ public String getMechanismName()
+ {
+ return null;
+ }
- public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
+ public byte[] evaluateResponse(byte[] response) throws SaslException
+ {
+ if (_throwSaslException)
{
- return null;
+ throw new SaslException("Mocked exception");
}
+ return null;
+ }
- public Object getNegotiatedProperty(String propName)
- {
- return null;
- }
+ public boolean isComplete()
+ {
+ return _complete;
+ }
- public void dispose() throws SaslException
- {
- }
- };
- }
+ public String getAuthorizationID()
+ {
+ return _complete ? "guest" : null;
+ }
- private ConfigurationPlugin getConfig(final String clazz, final String argName, final String argValue) throws Exception
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
+ public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
+ {
+ return null;
+ }
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", clazz);
+ public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
+ {
+ return null;
+ }
- if (argName != null)
+ public Object getNegotiatedProperty(String propName)
{
- xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.name", argName);
- xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.value", argValue);
+ return null;
}
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
+ public void dispose() throws SaslException
+ {
+ }
}
- private File createPasswordFile() throws Exception
+ public static class MySaslServerFactory implements SaslServerFactory
{
- BufferedWriter writer = null;
- try
- {
- File testFile = File.createTempFile(this.getClass().getName(),"tmp");
- testFile.deleteOnExit();
-
- writer = new BufferedWriter(new FileWriter(testFile));
- writer.write(TEST_USERNAME + ":" + TEST_PASSWORD);
- writer.newLine();
-
- return testFile;
-
- }
- finally
+ @Override
+ public SaslServer createSaslServer(String mechanism, String protocol,
+ String serverName, Map<String, ?> props, CallbackHandler cbh)
+ throws SaslException
{
- if (writer != null)
+ if (MOCK_MECH_NAME.equals(mechanism))
+ {
+ return new MySaslServer();
+ }
+ else
{
- writer.close();
+ return null;
}
}
+
+ @Override
+ public String[] getMechanismNames(Map<String, ?> props)
+ {
+ return new String[]{MOCK_MECH_NAME};
+ }
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
new file mode 100644
index 0000000000..aab5f80836
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.commons.configuration.XMLConfiguration;
+
+import junit.framework.TestCase;
+
+public class SimpleLDAPAuthenticationManagerFactoryTest extends TestCase
+{
+ private SimpleLDAPAuthenticationManagerFactory _factory = new SimpleLDAPAuthenticationManagerFactory();
+ private Configuration _configuration = new XMLConfiguration();
+
+ public void testInstanceCreated() throws Exception
+ {
+ _configuration.setProperty("simple-ldap-auth-manager.provider-url", "ldaps://example.com:636/");
+ _configuration.setProperty("simple-ldap-auth-manager.search-context", "dc=example");
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java
index 8c7f3ad6ef..f94d8ddfc3 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java
@@ -86,4 +86,10 @@ public class TestPrincipalDatabase implements PrincipalDatabase
// TODO Auto-generated method stub
}
+ @Override
+ public void setPasswordFile(String passwordFile) throws IOException
+ {
+ // TODO Auto-generated method stub
+ }
+
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java
new file mode 100644
index 0000000000..5b04df2fc5
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.XMLConfiguration;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+import junit.framework.TestCase;
+
+public class FileGroupManagerFactoryTest extends TestCase
+{
+
+ private FileGroupManagerFactory _factory = new FileGroupManagerFactory();
+ private Configuration _configuration = new XMLConfiguration();
+ private String _emptyButValidGroupFile = TestFileUtils.createTempFile(this).getAbsolutePath();
+
+ public void testInstanceCreated() throws Exception
+ {
+ _configuration.setProperty("file-group-manager.attributes.attribute.name", "groupFile");
+ _configuration.setProperty("file-group-manager.attributes.attribute.value", _emptyButValidGroupFile);
+
+ GroupManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ assertTrue(manager instanceof FileGroupManager);
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ GroupManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigNotForThisPlugin() throws Exception
+ {
+ _configuration.setProperty("other-group-manager", "config");
+
+ GroupManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testRejectsConfigThatHasUnexpectedAttributeName() throws Exception
+ {
+ _configuration.setProperty("file-group-manager.attributes.attribute.name", "unexpected");
+ _configuration.setProperty("file-group-manager.attributes.attribute.value", _emptyButValidGroupFile);
+
+ try
+ {
+ _factory.createInstance(_configuration);
+ fail("Exception not thrown");
+ }
+ catch (RuntimeException re)
+ {
+ // PASS
+ }
+ }
+
+ public void testRejectsConfigThatIsMissingAttributeValue() throws Exception
+ {
+ _configuration.setProperty("file-group-manager.attributes.attribute.name", "groupFile");
+ _configuration.setProperty("file-group-manager.attributes.attribute.value", null);
+
+ try
+ {
+ _factory.createInstance(_configuration);
+ fail("Exception not thrown");
+ }
+ catch (RuntimeException re)
+ {
+ // PASS
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java
index 165ecb098f..e926d72607 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java
@@ -26,14 +26,11 @@ import java.security.Principal;
import java.util.Properties;
import java.util.Set;
-import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
import org.apache.qpid.server.security.auth.UsernamePrincipal;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class FileGroupManagerTest extends InternalBrokerBaseCase
+public class FileGroupManagerTest extends QpidTestCase
{
private static final String MYGROUP_USERS = "user1";
private static final String MY_GROUP = "myGroup.users";
@@ -45,11 +42,6 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void tearDown() throws Exception
{
super.tearDown();
-//TODO: implement closable
-// if (_manager != null)
-// {
-// _manager.close();
-// }
if (_tmpGroupFile != null)
{
@@ -63,23 +55,18 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void testValidGroupFile() throws Exception
{
final String groupFileName = writeGroupFile();
- final ConfigurationPlugin config = getConfig("groupFile", groupFileName);
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(groupFileName);
assertNotNull(_manager);
}
public void testNonExistentGroupFile() throws Exception
{
final String filePath = "/does.not.exist/";
- final File fileFile = new File(filePath);
-
- assertFalse("File already exists", fileFile.exists());
- final ConfigurationPlugin config = getConfig("groupFile", filePath);
try
{
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(filePath);
fail("expected exception was not thrown");
}
catch(ConfigurationException ce)
@@ -92,8 +79,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void testGetGroupPrincipalsForUser() throws Exception
{
final String groupFileName = writeGroupFile();
- final ConfigurationPlugin config = getConfig("groupFile", groupFileName);
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(groupFileName);
Set<Principal> principals = _manager.getGroupPrincipalsForUser("user1");
assertEquals(1, principals.size());
@@ -103,8 +89,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void testGetUserPrincipalsForGroup() throws Exception
{
final String groupFileName = writeGroupFile();
- final ConfigurationPlugin config = getConfig("groupFile", groupFileName);
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(groupFileName);
Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup");
assertEquals(1, principals.size());
@@ -114,8 +99,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void testGetGroupPrincipals() throws Exception
{
final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS, MY_GROUP2, MYGROUP_USERS);
- final ConfigurationPlugin config = getConfig("groupFile", groupFileName);
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(groupFileName);
Set<Principal> principals = _manager.getGroupPrincipals();
assertEquals(2, principals.size());
@@ -126,8 +110,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void testCreateGroup() throws Exception
{
final String groupFileName = writeGroupFile();
- final ConfigurationPlugin config = getConfig("groupFile", groupFileName);
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(groupFileName);
Set<Principal> principals = _manager.getGroupPrincipals();
assertEquals(1, principals.size());
@@ -142,8 +125,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void testRemoveGroup() throws Exception
{
final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS);
- final ConfigurationPlugin config = getConfig("groupFile", groupFileName);
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(groupFileName);
Set<Principal> principals = _manager.getGroupPrincipals();
assertEquals(1, principals.size());
@@ -157,8 +139,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void testAddUserToGroup() throws Exception
{
final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS);
- final ConfigurationPlugin config = getConfig("groupFile", groupFileName);
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(groupFileName);
Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup");
assertEquals(1, principals.size());
@@ -174,8 +155,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
public void testRemoveUserInGroup() throws Exception
{
final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS);
- final ConfigurationPlugin config = getConfig("groupFile", groupFileName);
- _manager = FileGroupManager.FACTORY.newInstance(config);
+ _manager = new FileGroupManager(groupFileName);
Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup");
assertEquals(1, principals.size());
@@ -187,25 +167,6 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase
assertEquals(0, principals.size());
}
- private ConfigurationPlugin getConfig(final String argName, final String argValue) throws Exception
- {
- final ConfigurationPlugin config = new FileGroupManager.FileGroupManagerConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- if (argName != null)
- {
- xmlconfig.addProperty("file-group-manager.attributes.attribute.name", argName);
- xmlconfig.addProperty("file-group-manager.attributes.attribute.value", argValue);
- }
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
- }
-
private String writeGroupFile() throws Exception
{
return writeGroupFile(MY_GROUP, MYGROUP_USERS);
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java
deleted file mode 100644
index 23ee82eae6..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java
+++ /dev/null
@@ -1,119 +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 org.apache.qpid.test.utils.QpidTestCase;
-
-import java.lang.management.ManagementFactory;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-public class SignalHandlerTaskTest extends QpidTestCase
-{
- private static final Logger LOGGER = Logger.getLogger(SignalHandlerTaskTest.class);
- private static final String SUN_MISC_SIGNAL_CLASS = "sun.misc.Signal";
- private static final String SUN_MISC_SIGNAL_HANDLER_CLASS = "sun.misc.SignalHandler";
-
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void testSignalHandlerTask() throws Exception
- {
- final boolean expectedResult = classifyExpectedRegistrationResult();
- final int pid = getPID();
- final CountDownLatch latch = new CountDownLatch(1);
-
- SignalHandlerTask hupReparseTask = new SignalHandlerTask()
- {
- public void handle()
- {
- latch.countDown();
- LOGGER.info("Signal handled, latch decremented");
- }
- };
-
- assertEquals("Unexpected result trying to register Signal handler",
- expectedResult, hupReparseTask.register("HUP"));
- LOGGER.info("Signal handler was registered");
-
- assertEquals("unexpected count for the latch", 1, latch.getCount());
-
- if(expectedResult)
- {
- //registration succeeded as expected, so now
- //send SIGHUP and verify the handler was run
- String cmd = "/bin/kill -SIGHUP " + pid;
-
- LOGGER.info("Sending SIGHUP");
- Runtime.getRuntime().exec(cmd);
-
- assertTrue("HUP Signal was not handled in the allowed timeframe",
- latch.await(5, TimeUnit.SECONDS));
- }
- }
-
- public void testGetPlatformDescription() throws Exception
- {
- assertNotNull(SignalHandlerTask.getPlatformDescription());
- }
-
- private boolean classifyExpectedRegistrationResult()
- {
- String os = System.getProperty("os.name");
- if(String.valueOf(os).toLowerCase().contains("windows"))
- {
- //Windows does not support SIGHUP so registration will fail
- LOGGER.info("Running on windows, so we expect SIGHUP handler registration to fail");
- return false;
- }
-
- //otherwise, if the signal handler classes are present we would expect
- //registration to succeed
- boolean classesPresent = true;
- try
- {
- Class.forName(SUN_MISC_SIGNAL_CLASS);
- Class.forName(SUN_MISC_SIGNAL_HANDLER_CLASS);
- LOGGER.info("Signal handling classes were present so we expect SIGHUP handler registration to succeed");
- }
- catch (ClassNotFoundException cnfe)
- {
- classesPresent = false;
- }
-
- return classesPresent;
- }
-
- private int getPID()
- {
- String processName = ManagementFactory.getRuntimeMXBean().getName();
-
- int pid = Integer.parseInt(processName.substring(0,processName.indexOf('@')));
- LOGGER.info("PID was determined to be " + pid);
-
- return pid;
- }
-
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
index a1536565ad..e18269241e 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
@@ -35,11 +35,11 @@ import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DirectExchange;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.exchange.ExchangeType;
import org.apache.qpid.server.exchange.TopicExchange;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQPriorityQueue;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
@@ -97,6 +97,8 @@ public class MessageStoreTest extends InternalBrokerBaseCase
public void setUp() throws Exception
{
+ getConfigXml().addProperty("management.enabled", "false");
+
super.setUp();
String storePath = System.getProperty("QPID_WORK") + File.separator + getName();
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
index 411ed81d2a..600f0d591d 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
@@ -26,12 +26,11 @@ import java.util.Map;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
import org.apache.qpid.server.logging.NullRootMessageLogger;
import org.apache.qpid.server.logging.actors.BrokerActor;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.GenericActor;
-import org.apache.qpid.server.plugins.PluginManager;
+import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabase;
@@ -55,12 +54,14 @@ public class TestApplicationRegistry extends ApplicationRegistry
{
CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger()));
GenericActor.setDefaultMessageLogger(new NullRootMessageLogger());
+ LoggingManagementFacade.configure("test-profiles/log4j-test.xml");
+
super.initialise();
}
@Override
protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry(
- ServerConfiguration configuration, PluginManager pluginManager, final GroupPrincipalAccessor groupPrincipalAccessor)
+ ServerConfiguration configuration, final GroupPrincipalAccessor groupPrincipalAccessor)
throws ConfigurationException
{
final Properties users = new Properties();
@@ -69,26 +70,7 @@ public class TestApplicationRegistry extends ApplicationRegistry
final PropertiesPrincipalDatabase ppd = new PropertiesPrincipalDatabase(users);
- final AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager()
- {
-
- /**
- * @see org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager#configure(org.apache.qpid.server.configuration.plugins.ConfigurationPlugin)
- */
- @Override
- public void configure(ConfigurationPlugin config) throws ConfigurationException
- {
- // We don't pass configuration to this test instance.
- }
-
- @Override
- public void initialise()
- {
- setPrincipalDatabase(ppd);
-
- super.initialise();
- }
- };
+ final AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager(ppd);
pdam.initialise();
return new IAuthenticationManagerRegistry()