qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1397519 [4/6] - in /qpid/trunk/qpid/java: ./ bdbstore/ bdbstore/jmx/ broker-plugins/access-control/ broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ broker-plugins/access-control/src/main/resource...
Date Fri, 12 Oct 2012 11:44:20 GMT
Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java?rev=1397519&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java (added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java Fri Oct 12 11:44:13 2012
@@ -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);
+    }
+
+}

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java Fri Oct 12 11:44:13 2012
@@ -139,6 +139,12 @@ public class CRAMMD5HexInitialiser exten
         {
             _realPricipalDatabase.reload();
         }
+
+        @Override
+        public void setPasswordFile(String passwordFile) throws IOException
+        {
+            throw new UnsupportedOperationException();
+        }
     }
 
 }

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java Fri Oct 12 11:44:13 2012
@@ -21,19 +21,11 @@ package org.apache.qpid.server.security.
 
 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.a
  */
 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
         {

Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java?rev=1397519&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java (added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java Fri Oct 12 11:44:13 2012
@@ -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);
+        }
+    }
+
+}

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java Fri Oct 12 11:44:13 2012
@@ -22,9 +22,7 @@ package org.apache.qpid.server.security.
 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);
 

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java Fri Oct 12 11:44:13 2012
@@ -31,7 +31,6 @@ import org.apache.qpid.server.exchange.E
 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.me
 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;

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java Fri Oct 12 11:44:13 2012
@@ -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.HAMe
 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 
 
         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 
         _queueRegistry = new DefaultQueueRegistry(this);
 
         _exchangeFactory = new DefaultExchangeFactory(this);
-        _exchangeFactory.initialise(_vhostConfig);
 
         _exchangeRegistry = new DefaultExchangeRegistry(this);
 
@@ -187,38 +182,9 @@ public class VirtualHostImpl implements 
      */
     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);
-                    }
-                }
-            }
         }
     }
 

Added: qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory?rev=1397519&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory (added)
+++ qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory Fri Oct 12 11:44:13 2012
@@ -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

Added: qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType?rev=1397519&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType (added)
+++ qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType Fri Oct 12 11:44:13 2012
@@ -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

Added: qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory?rev=1397519&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory (added)
+++ qpid/trunk/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory Fri Oct 12 11:44:13 2012
@@ -0,0 +1 @@
+org.apache.qpid.server.security.group.FileGroupManagerFactory
\ No newline at end of file

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java Fri Oct 12 11:44:13 2012
@@ -27,7 +27,6 @@ import org.apache.qpid.framing.AMQShortS
 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 ext
         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 ext
 
         // 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 ext
 
         // 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 ext
 
         // 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 ext
         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 ext
         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 ext
 
         // Load config
         ApplicationRegistry.remove();
-        ApplicationRegistry registry = new ConfigurationFileApplicationRegistry(xml);
+        ApplicationRegistry registry = new ApplicationRegistry(new ServerConfiguration(xml));
         ApplicationRegistry.initialise(registry);
         ServerConfiguration serverConfiguration = ApplicationRegistry.getInstance().getConfiguration();
 

Copied: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java (from r1397507, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java?p2=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java&p1=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java&r1=1397507&r2=1397519&rev=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java Fri Oct 12 11:44:13 2012
@@ -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 ext
 
     }
 
-    private ConfigPlugin _plugin;
+    private TestConfigPlugin _plugin;
 
     @Override
     public void setUp() throws Exception
@@ -93,7 +93,7 @@ public class ConfigurationPluginTest ext
         CompositeConfiguration composite = new CompositeConfiguration();
         composite.addConfiguration(xmlconfig);
 
-        _plugin = new ConfigPlugin();
+        _plugin = new TestConfigPlugin();
 
         try
         {
@@ -110,7 +110,7 @@ public class ConfigurationPluginTest ext
     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 ext
         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());
         }
 
     }

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java?rev=1397519&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java Fri Oct 12 11:44:13 2012
@@ -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;
+        }
+    }
+
+}

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java Fri Oct 12 11:44:13 2012
@@ -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
 
     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();
     }
 }

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java Fri Oct 12 11:44:13 2012
@@ -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;

Copied: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java (from r1397507, qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java?p2=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java&p1=qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java&r1=1397507&r2=1397519&rev=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java Fri Oct 12 11:44:13 2012
@@ -28,7 +28,6 @@ import org.apache.qpid.server.security.a
 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
         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
     {
         //No file to update from, so do nothing.
     }
+
+    @Override
+    public void setPasswordFile(String passwordFile)
+    {
+        throw new UnsupportedOperationException();
+    }
 }

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java Fri Oct 12 11:44:13 2012
@@ -24,24 +24,13 @@ import static org.apache.qpid.server.sec
 
 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 AnonymousAuthenticationMana
         }
     }
 
-    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());

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java Fri Oct 12 11:44:13 2012
@@ -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 AuthenticationManagerRegist
     {
         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 AuthenticationManagerRegist
         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 AuthenticationManagerRegist
 
     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);
-
-        String defaultAuthManger = myAuthManagerFactory1.getPluginName();
-        when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
-        when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthManger);
+        AuthenticationManager defaultAuthManager = mock(MockAuthenticationManager1.class);
+        AuthenticationManagerFactory defaultAuthManagerFactory = newMockFactoryProducing(defaultAuthManager);
+
+        AuthenticationManager authManager2 = mock(MockAuthenticationManager2.class);
+        AuthenticationManagerFactory authManagerFactory2 = newMockFactoryProducing(authManager2);
+
+        List<AuthenticationManagerFactory> factoryList = Arrays.asList(defaultAuthManagerFactory, authManagerFactory2);
+
+        String defaultAuthMangerName = defaultAuthManager.getClass().getSimpleName();
+        when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthMangerName);
+        when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
 
-        AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor);
+        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);
+
+        AuthenticationManager authManager2 = mock(MockAuthenticationManager2.class);
+        AuthenticationManagerFactory authManagerFactory2 = newMockFactoryProducing(authManager2);
+
+        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();
+    }
 
-        AuthenticationManagerPluginFactory myAuthManagerFactory = mock(AuthenticationManagerPluginFactory.class);
-        when(myAuthManagerFactory.getPluginClass()).thenReturn(myAuthManager.getClass());
-        when(myAuthManagerFactory.getPluginName()).thenReturn(myAuthManager.getClass().getSimpleName());
-        when(myAuthManagerFactory.newInstance(_securityConfiguration)).thenReturn(myAuthManager);
 
-        _allCreatedAuthManagers.add(myAuthManager);
+    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
+    {
+    }
+
+    /**
+     * 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
     {
-        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()
+    /**
+     * 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
     {
-        for (Iterator<AuthenticationManager> iterator = _allCreatedAuthManagers.iterator(); iterator.hasNext();)
+        @Override
+        public void 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)
         {
-            AuthenticationManager authenticationManager = (AuthenticationManager) iterator.next();
-            verify(authenticationManager).close();
+            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";
+        }
     }
 }

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java?rev=1397519&r1=1397518&r2=1397519&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java Fri Oct 12 11:44:13 2012
@@ -23,56 +23,13 @@ import static org.apache.qpid.server.sec
 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
     {

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java?rev=1397519&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java Fri Oct 12 11:44:13 2012
@@ -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();
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message