diff options
| author | Keith Wall <kwall@apache.org> | 2012-06-03 00:00:46 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2012-06-03 00:00:46 +0000 |
| commit | 2898a8a557a064a0244eabf6e14fbf2ad08fac88 (patch) | |
| tree | 9c2434389da9e9af40555629d2c429810bb38655 /qpid/java/broker/src/test | |
| parent | cd6d9a681b291136ec50f468d00ba3acd576b8cb (diff) | |
| download | qpid-python-2898a8a557a064a0244eabf6e14fbf2ad08fac88.tar.gz | |
QPID-3997: Fix test failure under JDK 1.7 when AuthenticationManagers would not always be properly closed
ApplicationRegistry refactored: Resposibilities for lifecycle of AuthenticationManager objects transfered to
AuthicationManagerRegistry (better separation of concerns). Implemented new pure unit test to expose
the failing test and then changed algorithm so that AuthenticationManagers are closed on all paths.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1345607 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
6 files changed, 328 insertions, 264 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryAuthenticationManagerTest.java deleted file mode 100644 index 7fd608450a..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryAuthenticationManagerTest.java +++ /dev/null @@ -1,184 +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 java.net.InetSocketAddress; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager; -import org.apache.qpid.server.security.auth.manager.AuthenticationManager; -import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager; -import org.apache.qpid.server.util.InternalBrokerBaseCase; - -public class ApplicationRegistryAuthenticationManagerTest extends InternalBrokerBaseCase -{ - private Runnable _configureTask; - - @Override - public void tearDown() throws Exception - { - _configureTask = null; - super.tearDown(); - } - - @Override - protected void createBroker() throws Exception - { - // Do nothing - we don't want create broker called in setUp - } - - @Override - protected void configure() - { - if(_configureTask != null) - { - _configureTask.run(); - } - } - - @Override - protected IApplicationRegistry createApplicationRegistry() throws ConfigurationException - { - return new TestableApplicationRegistry(getConfiguration()); - } - - private void reallyCreateBroker() throws Exception - { - super.createBroker(); - } - - public void testNoAuthenticationManagers() throws Exception - { - try - { - reallyCreateBroker(); - fail("Expected a ConfigurationException when no AuthenticationManagers are defined"); - } - catch(ConfigurationException e) - { - // pass - } - } - - public void testSingleAuthenticationManager() throws Exception - { - _configureTask = - new Runnable() - { - @Override - public void run() - { - getConfiguration().getConfig().addProperty("security.anonymous-auth-manager", ""); - } - }; - - try - { - reallyCreateBroker(); - } - catch(ConfigurationException e) - { - fail("Unexpected ConfigurationException when creating the registry with a single AuthenticationManager"); - } - } - - public void testMultipleAuthenticationManagersNoDefault() throws Exception - { - _configureTask = - new Runnable() - { - @Override - public void run() - { - getConfiguration().getConfig().addProperty("security.anonymous-auth-manager", ""); - getConfiguration().getConfig().addProperty("security.pd-auth-manager.principal-database.class","org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase"); - } - }; - try - { - reallyCreateBroker(); - fail("Expected ConfigurationException as two AuthenticationManagers are defined, but there is no default specified"); - } - catch (ConfigurationException e) - { - // pass - } - } - - public void testDefaultAuthenticationManager() throws Exception - { - _configureTask = - new Runnable() - { - @Override - public void run() - { - getConfiguration().getConfig().addProperty("security.anonymous-auth-manager", ""); - getConfiguration().getConfig().addProperty("security.pd-auth-manager.principal-database.class","org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase"); - getConfiguration().getConfig().addProperty("security.default-auth-manager", "AnonymousAuthenticationManager"); - } - }; - try - { - reallyCreateBroker(); - } - catch (ConfigurationException e) - { - fail("Unexpected ConfigurationException when two AuthenticationManagers are defined, but there is a default specified"); - } - - AuthenticationManager authMgr = - ApplicationRegistry.getInstance().getAuthenticationManager(new InetSocketAddress(1)); - - assertNotNull("AuthenticationManager should not be null for any socket", authMgr); - assertEquals("AuthenticationManager not of expected class", AnonymousAuthenticationManager.class, authMgr.getClass()); - - - } - - public void testMappedAuthenticationManager() throws Exception - { - _configureTask = - new Runnable() - { - @Override - public void run() - { - getConfiguration().getConfig().addProperty("security.anonymous-auth-manager", ""); - getConfiguration().getConfig().addProperty("security.pd-auth-manager.principal-database.class","org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase"); - getConfiguration().getConfig().addProperty("security.default-auth-manager", "PrincipalDatabaseAuthenticationManager"); - getConfiguration().getConfig().addProperty("security.port-mappings.port-mapping.port", "200"); - getConfiguration().getConfig().addProperty("security.port-mappings.port-mapping.auth-manager", "AnonymousAuthenticationManager"); - } - }; - reallyCreateBroker(); - - AuthenticationManager authMgr = - ApplicationRegistry.getInstance().getAuthenticationManager(new InetSocketAddress(200)); - - assertNotNull("AuthenticationManager should not be null for any socket", authMgr); - assertEquals("AuthenticationManager not of expected class", AnonymousAuthenticationManager.class, authMgr.getClass()); - - // test the default is still in effect for other ports - authMgr = ApplicationRegistry.getInstance().getAuthenticationManager(new InetSocketAddress(1)); - assertEquals("AuthenticationManager not of expected class", PrincipalDatabaseAuthenticationManager.class, authMgr.getClass()); - - - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java index 9ff8f0a531..9af950d385 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java @@ -49,7 +49,7 @@ public class ApplicationRegistryShutdownTest extends InternalBrokerBaseCase /** - * QPID-1399 : Ensure that the Authentiction manager unregisters any SASL providers created during + * QPID-1399 : Ensure that the Authentication manager unregisters any SASL providers created during * ApplicationRegistry initialisation. * */ diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/TestableApplicationRegistry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/TestableApplicationRegistry.java deleted file mode 100644 index db7a7f7950..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/TestableApplicationRegistry.java +++ /dev/null @@ -1,48 +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.apache.qpid.server.configuration.ServerConfiguration; -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; - -class TestableApplicationRegistry extends ApplicationRegistry -{ - - public TestableApplicationRegistry(ServerConfiguration config) throws ConfigurationException - { - super(config); - } - - @Override - public void initialise() throws Exception - { - CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger())); - GenericActor.setDefaultMessageLogger(new NullRootMessageLogger()); - super.initialise(); - } - - - -} - - 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 new file mode 100644 index 0000000000..213039a7fb --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java @@ -0,0 +1,304 @@ +/* + * 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 static org.mockito.Mockito.*; + +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +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.mockito.Mockito; + +import junit.framework.TestCase; + +public class AuthenticationManagerRegistryTest extends TestCase +{ + private static final Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> EMPTY_PLUGINMAP = Collections.emptyMap(); + + private PluginManager _pluginManager = Mockito.mock(PluginManager.class); + private ServerConfiguration _serverConfiguration = Mockito.mock(ServerConfiguration.class); + private SecurityConfiguration _securityConfiguration = Mockito.mock(SecurityConfiguration.class); + + private List<AuthenticationManager> _allCreatedAuthManagers = new ArrayList<AuthenticationManager>(); + + @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(); + } + } + + public void testNoAuthenticationManagerFactoryPluginsFound() throws Exception + { + when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(EMPTY_PLUGINMAP); + try + { + new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager); + fail("Exception not thrown"); + } + catch (ConfigurationException ce) + { + // PASS + assertEquals("No authentication manager factory plugins found. Check the desired authentication manager plugin has been placed in the plugins directory.", + ce.getMessage()); + } + } + + public void testSameAuthenticationManagerSpecifiedTwice() throws Exception + { + AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); + + Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory, myAuthManagerFactory); + + when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + + try + { + new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager); + fail("Exception not thrown"); + } + catch (ConfigurationException ce) + { + // PASS + assertEquals("Cannot configure more than one authentication manager of type " + myAuthManagerFactory.getPluginClass().getSimpleName() + ". Remove configuration for one of the authentication managers.", + ce.getMessage()); + } + } + + 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); + + when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(null); + + try + { + new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager); + fail("Exception not thrown"); + } + catch (ConfigurationException ce) + { + // PASS + assertEquals("If more than one authentication manager is configured a default MUST be specified.", + ce.getMessage()); + } + } + + public void testDefaultAuthenticationManagerNotKnown() throws Exception + { + String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager"; + + AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); + AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class); + + Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2); + + when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(myDefaultAuthManagerSimpleClassName); + + try + { + new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager); + fail("Exception not thrown"); + } + catch (ConfigurationException ce) + { + // PASS + assertTrue("Unexpected message " + ce.getMessage(), + ce.getMessage().startsWith("No authentication managers configured of type " + myDefaultAuthManagerSimpleClassName + " which is specified as the default")); + } + } + + public void testPortMappedToUnknownAuthenticationManager() throws Exception + { + String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager"; + int portNumber = 1234; + + AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); + + Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1); + + when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(portNumber, myDefaultAuthManagerSimpleClassName)); + + try + { + new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager); + fail("Exception not thrown"); + } + catch (ConfigurationException ce) + { + // PASS + assertEquals("Unknown authentication manager class " + myDefaultAuthManagerSimpleClassName + " configured for port " + portNumber, ce.getMessage()); + } + } + + public void testGetAuthenticationManagerForInetSocketAddress() throws Exception + { + AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); + Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1); + + when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + + AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager); + + AuthenticationManager authenticationManager = registry.getAuthenticationManagerFor(new InetSocketAddress(1234)); + assertEquals("TestAuthenticationManager1", authenticationManager.getMechanisms()); + + registry.close(); + } + + public void testGetAuthenticationManagerForNonInetSocketAddress() throws Exception + { + AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); + Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1); + + when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + + AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager); + + AuthenticationManager authenticationManager = registry.getAuthenticationManagerFor(mock(SocketAddress.class)); + assertEquals("TestAuthenticationManager1", authenticationManager.getMechanisms()); + + registry.close(); + } + + 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); + + 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); + + AuthenticationManager authenticationManager1 = registry.getAuthenticationManagerFor(new InetSocketAddress(unmappedPortNumber)); + assertEquals("TestAuthenticationManager1", authenticationManager1.getMechanisms()); + + AuthenticationManager authenticationManager2 = registry.getAuthenticationManagerFor(new InetSocketAddress(mappedPortNumber)); + assertEquals("TestAuthenticationManager2", authenticationManager2.getMechanisms()); + + registry.close(); + } + + 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); + + AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager); + + registry.close(); + } + + private AuthenticationManagerPluginFactory<? extends Plugin> newMockFactoryProducingMockAuthManagerImplementing(Class<? extends AuthenticationManager> authManagerClazz) + throws ConfigurationException + { + AuthenticationManager myAuthManager = mock(authManagerClazz); + when(myAuthManager.getMechanisms()).thenReturn(authManagerClazz.getSimpleName()); // used to verify the getAuthenticationManagerFor returns expected impl. + + 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); + return myAuthManagerFactory; + } + + private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> createPluginMap( + AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory) + { + return createPluginMap(myAuthManagerFactory, null); + } + + private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> createPluginMap( + AuthenticationManagerPluginFactory<? extends Plugin> authManagerFactory1, + AuthenticationManagerPluginFactory<? extends Plugin> authManagerFactory2) + { + 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() + { + for (Iterator<AuthenticationManager> iterator = _allCreatedAuthManagers.iterator(); iterator.hasNext();) + { + AuthenticationManager authenticationManager = (AuthenticationManager) iterator.next(); + verify(authenticationManager).close(); + } + } + + private interface TestAuthenticationManager1 extends AuthenticationManager + { + } + + private interface TestAuthenticationManager2 extends AuthenticationManager + { + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java index 584f3d1358..df3bbb3e8b 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java @@ -20,18 +20,12 @@ */ package org.apache.qpid.server.security.auth.rmi; -import java.util.Map; import junit.framework.TestCase; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.XMLConfiguration; -import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; import org.apache.qpid.server.security.auth.manager.AuthenticationManager; -import org.apache.qpid.server.util.TestApplicationRegistry; import javax.management.remote.JMXPrincipal; import javax.security.auth.Subject; @@ -123,17 +117,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase */ public void testNullAuthenticationManager() throws Exception { - ServerConfiguration serverConfig = new ServerConfiguration(new XMLConfiguration()); - TestApplicationRegistry reg = new TestApplicationRegistry(serverConfig) - { - @Override - protected Map<Integer, AuthenticationManager> createAuthenticationManagers() throws ConfigurationException - { - return Collections.emptyMap(); - } - }; - ApplicationRegistry.initialise(reg); - + _rmipa.setAuthenticationManager(null); try { _rmipa.authenticate(_credentials); @@ -144,10 +128,6 @@ public class RMIPasswordAuthenticatorTest extends TestCase assertEquals("Unexpected exception message", RMIPasswordAuthenticator.UNABLE_TO_LOOKUP, se.getMessage()); } - finally - { - ApplicationRegistry.remove(); - } } /** 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 6e18718478..4bb468e823 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 @@ -20,8 +20,7 @@ */ package org.apache.qpid.server.util; -import java.util.Collections; -import java.util.Map; +import java.net.SocketAddress; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.configuration.ServerConfiguration; @@ -30,9 +29,11 @@ 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.registry.ApplicationRegistry; import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabase; import org.apache.qpid.server.security.auth.manager.AuthenticationManager; +import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry; import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager; import java.util.Properties; @@ -53,11 +54,10 @@ public class TestApplicationRegistry extends ApplicationRegistry super.initialise(); } - /** - * @see org.apache.qpid.server.registry.ApplicationRegistry#createAuthenticationManagers() - */ @Override - protected Map<Integer, AuthenticationManager> createAuthenticationManagers() throws ConfigurationException + protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry( + ServerConfiguration _configuration, PluginManager _pluginManager) + throws ConfigurationException { final Properties users = new Properties(); users.put("guest","guest"); @@ -65,7 +65,7 @@ public class TestApplicationRegistry extends ApplicationRegistry final PropertiesPrincipalDatabase ppd = new PropertiesPrincipalDatabase(users); - AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager() + final AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager() { /** @@ -85,12 +85,24 @@ public class TestApplicationRegistry extends ApplicationRegistry super.initialise(); } }; - pdam.initialise(); - return Collections.singletonMap(null,pdam); - } + return new IAuthenticationManagerRegistry() + { + @Override + public void close() + { + pdam.close(); + } + @Override + public AuthenticationManager getAuthenticationManagerFor( + SocketAddress address) + { + return pdam; + } + }; + } } |
