diff options
| author | Robert Gemmell <robbie@apache.org> | 2012-10-12 11:44:13 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2012-10-12 11:44:13 +0000 |
| commit | 65cba5397294ddd5349bdb9837c4a10d91f2ca0b (patch) | |
| tree | 5ac98649e42a8d48ca46e94cae1120dde99044dc /qpid/java/broker/src/test | |
| parent | a0b7800e8d8554f76dcd8715768b08b6e8b9c507 (diff) | |
| download | qpid-python-65cba5397294ddd5349bdb9837c4a10d91f2ca0b.tar.gz | |
QPID-4335, QPID-4353: Refactored broker plugins to use simplified ServiceLoader-based model rather than embedding Felix to use OSGi.
Removed the ability to reload security configuration because this feature is not very useful in
its current form and was making our code hard to refactor.
Modified all tests to use jars rather than classes. This makes them closer to real-world deployments, e.g. the META-INF/services
file is read from within the jar.
Also moved various system tests from their respective modules into "systests". This removes the need for most modules to depend
on systests, thus simplifying our dependency graph.
Applied patch from myself, Keith Wall and Phil Harvey <phil@philharveyonline.com>
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1397519 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
20 files changed, 1024 insertions, 775 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java index 00b0ad7e39..c77732e356 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java @@ -27,7 +27,6 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.protocol.AmqpProtocolVersion; import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; import org.apache.qpid.server.util.TestApplicationRegistry; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; @@ -116,32 +115,6 @@ public class ServerConfigurationTest extends QpidTestCase assertEquals(false, _serverConfig.getPlatformMbeanserver()); } - public void testGetPluginDirectory() throws ConfigurationException - { - // Check default - _serverConfig.initialise(); - assertEquals(null, _serverConfig.getPluginDirectory()); - - // Check value we set - _config.setProperty("plugin-directory", "/path/to/plugins"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("/path/to/plugins", _serverConfig.getPluginDirectory()); - } - - public void testGetCacheDirectory() throws ConfigurationException - { - // Check default - _serverConfig.initialise(); - assertEquals(null, _serverConfig.getCacheDirectory()); - - // Check value we set - _config.setProperty("cache-directory", "/path/to/cache"); - _serverConfig = new ServerConfiguration(_config); - _serverConfig.initialise(); - assertEquals("/path/to/cache", _serverConfig.getCacheDirectory()); - } - public void testGetFrameSize() throws ConfigurationException { // Check default @@ -926,7 +899,7 @@ public class ServerConfigurationTest extends QpidTestCase // Load config ApplicationRegistry.remove(); - ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); + ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile)); ApplicationRegistry.initialise(reg); // Test config @@ -959,7 +932,7 @@ public class ServerConfigurationTest extends QpidTestCase // Load config ApplicationRegistry.remove(); - ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); + ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile)); ApplicationRegistry.initialise(reg); // Test config @@ -994,7 +967,7 @@ public class ServerConfigurationTest extends QpidTestCase // Load config ApplicationRegistry.remove(); - ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); + ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile)); ApplicationRegistry.initialise(reg); // Test config @@ -1039,7 +1012,7 @@ public class ServerConfigurationTest extends QpidTestCase try { ApplicationRegistry.remove(); - ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); + ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile)); ApplicationRegistry.initialise(reg); fail("Different virtualhost XML configurations not allowed"); } @@ -1074,7 +1047,7 @@ public class ServerConfigurationTest extends QpidTestCase try { ApplicationRegistry.remove(); - ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); + ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile)); ApplicationRegistry.initialise(reg); fail("Multiple virtualhost XML configurations not allowed"); } @@ -1557,7 +1530,7 @@ public class ServerConfigurationTest extends QpidTestCase // Load config ApplicationRegistry.remove(); - ApplicationRegistry registry = new ConfigurationFileApplicationRegistry(xml); + ApplicationRegistry registry = new ApplicationRegistry(new ServerConfiguration(xml)); ApplicationRegistry.initialise(registry); ServerConfiguration serverConfiguration = ApplicationRegistry.getInstance().getConfiguration(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java index 14c7b8cb20..164e54ac3e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java @@ -32,14 +32,14 @@ import java.util.List; * Test that verifies that given a Configuration a ConfigurationPlugin can * process and validate that data. */ -public class ConfigurationPluginTest extends InternalBrokerBaseCase +public class AbstractConfigurationTest extends InternalBrokerBaseCase { private static final double DOUBLE = 3.14; private static final long POSITIVE_LONG = 1000; private static final long NEGATIVE_LONG = -1000; private static final int LIST_SIZE = 3; - class ConfigPlugin extends ConfigurationPlugin + class TestConfigPlugin extends AbstractConfiguration { @Override public String[] getElementsProcessed() @@ -68,7 +68,7 @@ public class ConfigurationPluginTest extends InternalBrokerBaseCase } - private ConfigPlugin _plugin; + private TestConfigPlugin _plugin; @Override public void setUp() throws Exception @@ -93,7 +93,7 @@ public class ConfigurationPluginTest extends InternalBrokerBaseCase CompositeConfiguration composite = new CompositeConfiguration(); composite.addConfiguration(xmlconfig); - _plugin = new ConfigPlugin(); + _plugin = new TestConfigPlugin(); try { @@ -110,7 +110,7 @@ public class ConfigurationPluginTest extends InternalBrokerBaseCase public void testHasConfiguration() { assertTrue("Plugin has no configuration ", _plugin.hasConfiguration()); - _plugin = new ConfigPlugin(); + _plugin = new TestConfigPlugin(); assertFalse("Plugins has configuration", _plugin.hasConfiguration()); } @@ -142,7 +142,7 @@ public class ConfigurationPluginTest extends InternalBrokerBaseCase catch (ConfigurationException e) { assertEquals("negativeLong should not be reported as positive", - "ConfigPlugin: unable to configure invalid negativeLong:" + NEGATIVE_LONG, e.getMessage()); + "TestConfigPlugin: unable to configure invalid negativeLong:" + NEGATIVE_LONG, e.getMessage()); } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java new file mode 100644 index 0000000000..341ab1b372 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java @@ -0,0 +1,226 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.exchange; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.UUID; + +import org.apache.qpid.AMQException; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.plugin.ExchangeType; +import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.qpid.test.utils.QpidTestCase; + +@SuppressWarnings("rawtypes") +public class DefaultExchangeFactoryTest extends QpidTestCase +{ + private DirectExchangeType _directExchangeType; + private TopicExchangeType _topicExchangeType; + private FanoutExchangeType _fanoutExchangeType; + private HeadersExchangeType _headersExchangeType; + + private List<ExchangeType> _stubbedExchangeTypes; + + protected void setUp() throws Exception + { + super.setUp(); + + _directExchangeType = new DirectExchangeType(); + _topicExchangeType = new TopicExchangeType(); + _fanoutExchangeType = new FanoutExchangeType(); + _headersExchangeType = new HeadersExchangeType(); + _stubbedExchangeTypes = new ArrayList<ExchangeType>(); + } + + public void testCreateDefaultExchangeFactory() + { + _stubbedExchangeTypes.add(_directExchangeType); + _stubbedExchangeTypes.add(_topicExchangeType); + _stubbedExchangeTypes.add(_fanoutExchangeType); + _stubbedExchangeTypes.add(_headersExchangeType); + + DefaultExchangeFactory factory = new TestExchangeFactory(); + + Collection<ExchangeType<? extends Exchange>> registeredTypes = factory.getRegisteredTypes(); + assertEquals("Unexpected number of exchange types", _stubbedExchangeTypes.size(), registeredTypes.size()); + assertTrue("Direct exchange type is not found", registeredTypes.contains(_directExchangeType)); + assertTrue("Fanout exchange type is not found", registeredTypes.contains(_fanoutExchangeType)); + assertTrue("Topic exchange type is not found", registeredTypes.contains(_topicExchangeType)); + assertTrue("Headers exchange type is not found", registeredTypes.contains(_headersExchangeType)); + } + + public void testCreateDefaultExchangeFactoryWithoutAllBaseExchangeTypes() + { + try + { + new TestExchangeFactory(); + fail("Cannot create factory without all base classes"); + } + catch (IllegalStateException e) + { + // pass + } + } + + public void testCreateDefaultExchangeFactoryWithoutDireactExchangeType() + { + _stubbedExchangeTypes.add(_topicExchangeType); + _stubbedExchangeTypes.add(_fanoutExchangeType); + _stubbedExchangeTypes.add(_headersExchangeType); + + try + { + new TestExchangeFactory(); + fail("Cannot create factory without all base classes"); + } + catch (IllegalStateException e) + { + assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _directExchangeType.getName(), e.getMessage()); + } + } + + public void testCreateDefaultExchangeFactoryWithoutTopicExchangeType() + { + _stubbedExchangeTypes.add(_directExchangeType); + _stubbedExchangeTypes.add(_fanoutExchangeType); + _stubbedExchangeTypes.add(_headersExchangeType); + + try + { + new TestExchangeFactory(); + fail("Cannot create factory without all base classes"); + } + catch (IllegalStateException e) + { + assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _topicExchangeType.getName(), e.getMessage()); + } + } + + public void testCreateDefaultExchangeFactoryWithoutFanoutExchangeType() + { + _stubbedExchangeTypes.add(_directExchangeType); + _stubbedExchangeTypes.add(_topicExchangeType); + _stubbedExchangeTypes.add(_headersExchangeType); + + try + { + new TestExchangeFactory(); + fail("Cannot create factory without all base classes"); + } + catch (IllegalStateException e) + { + assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _fanoutExchangeType.getName(), e.getMessage()); + } + } + + public void testCreateDefaultExchangeFactoryWithoutHeadersExchangeType() + { + _stubbedExchangeTypes.add(_directExchangeType); + _stubbedExchangeTypes.add(_topicExchangeType); + _stubbedExchangeTypes.add(_fanoutExchangeType); + + try + { + new TestExchangeFactory(); + fail("Cannot create factory without all base classes"); + } + catch (IllegalStateException e) + { + assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _headersExchangeType.getName(), e.getMessage()); + } + } + + public void testCreateDefaultExchangeFactoryWithDuplicateExchangeTypeName() + { + _stubbedExchangeTypes.add(_directExchangeType); + _stubbedExchangeTypes.add(_directExchangeType); + + try + { + new TestExchangeFactory(); + fail("Cannot create factory with duplicate exchange type names"); + } + catch (IllegalStateException e) + { + assertTrue( "Unexpected exception message", e.getMessage().contains("ExchangeType with type name '" + + _directExchangeType.getName() + "' is already registered using class '" + + DirectExchangeType.class.getName())); + } + } + + public void testCreateDefaultExchangeFactoryWithCustomExchangeType() + { + ExchangeType<?> customeExchangeType = new ExchangeType<Exchange>() + { + @Override + public AMQShortString getName() + { + return new AMQShortString("my-custom-exchange"); + } + + @Override + public Exchange newInstance(UUID id, VirtualHost host, AMQShortString name, boolean durable, int ticket, + boolean autoDelete) throws AMQException + { + return null; + } + + @Override + public AMQShortString getDefaultExchangeName() + { + return null; + } + }; + + _stubbedExchangeTypes.add(customeExchangeType); + _stubbedExchangeTypes.add(_directExchangeType); + _stubbedExchangeTypes.add(_topicExchangeType); + _stubbedExchangeTypes.add(_fanoutExchangeType); + _stubbedExchangeTypes.add(_headersExchangeType); + + DefaultExchangeFactory factory = new TestExchangeFactory(); + + Collection<ExchangeType<? extends Exchange>> registeredTypes = factory.getRegisteredTypes(); + assertEquals("Unexpected number of exchange types", _stubbedExchangeTypes.size(), registeredTypes.size()); + assertTrue("Direct exchange type is not found", registeredTypes.contains(_directExchangeType)); + assertTrue("Fanout exchange type is not found", registeredTypes.contains(_fanoutExchangeType)); + assertTrue("Topic exchange type is not found", registeredTypes.contains(_topicExchangeType)); + assertTrue("Headers exchange type is not found", registeredTypes.contains(_headersExchangeType)); + assertTrue("Custom exchange type is not found", registeredTypes.contains(customeExchangeType)); + } + + private final class TestExchangeFactory extends DefaultExchangeFactory + { + private TestExchangeFactory() + { + super(null); + } + + @Override + protected Iterable<ExchangeType> loadExchangeTypes() + { + return _stubbedExchangeTypes; + } + } + +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java index 6cb9d9b2e6..72b34868ba 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java @@ -20,10 +20,12 @@ package org.apache.qpid.server.logging.log4j; import java.io.File; +import java.io.InputStream; import java.util.List; import java.util.Map; import org.apache.log4j.Level; +import org.apache.qpid.test.utils.TestFileUtils; import org.apache.qpid.util.FileUtils; import junit.framework.TestCase; @@ -236,10 +238,6 @@ public class LoggingManagementFacadeTest extends TestCase private String createTestLog4jXml() throws Exception { - File dst = File.createTempFile("log4j." + getName(), "xml"); - File filename = new File(getClass().getResource("LoggingFacadeTest.log4j.xml").toURI()); - FileUtils.copy(filename, dst); - dst.deleteOnExit(); - return dst.getAbsolutePath(); + return TestFileUtils.createTempFileFromResource(this, "LoggingFacadeTest.log4j.xml").getAbsolutePath(); } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java deleted file mode 100644 index 20abdd48cd..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.plugins; - -import org.osgi.framework.Version; - -import org.apache.qpid.test.utils.QpidTestCase; - -import java.util.Map; -import java.util.TreeMap; - -/** - * - */ -public class OsgiSystemPackageUtilTest extends QpidTestCase -{ - private OsgiSystemPackageUtil _util = null; // Object under test - - private Map<String, String> _map = new TreeMap<String, String>(); // Use a TreeMap for unit test in order for determinstic results. - - public void testWithOnePackage() throws Exception - { - _map.put("org.xyz", "1.0.0"); - - _util = new OsgiSystemPackageUtil(null, _map); - - final String systemPackageString = _util.getFormattedSystemPackageString(); - - assertEquals("org.xyz; version=1.0.0", systemPackageString); - } - - public void testWithTwoPackages() throws Exception - { - _map.put("org.xyz", "1.0.0"); - _map.put("org.abc", "1.2.3"); - - _util = new OsgiSystemPackageUtil(null, _map); - - final String systemPackageString = _util.getFormattedSystemPackageString(); - - assertEquals("org.abc; version=1.2.3, org.xyz; version=1.0.0", systemPackageString); - } - - public void testWithNoPackages() throws Exception - { - _util = new OsgiSystemPackageUtil(null, _map); - - final String systemPackageString = _util.getFormattedSystemPackageString(); - - assertNull(systemPackageString); - } - - public void testWithQpidPackageWithQpidReleaseNumberSet() throws Exception - { - _map.put("org.apache.qpid.xyz", "1.0.0"); - _map.put("org.abc", "1.2.3"); - - _util = new OsgiSystemPackageUtil(new Version("0.19"), _map); - - final String systemPackageString = _util.getFormattedSystemPackageString(); - - assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=0.19.0", systemPackageString); - } - - public void testWithQpidPackageWithoutQpidReleaseNumberSet() throws Exception - { - _map.put("org.apache.qpid.xyz", "1.0.0"); - _map.put("org.abc", "1.2.3"); - - _util = new OsgiSystemPackageUtil(null, _map); - - final String systemPackageString = _util.getFormattedSystemPackageString(); - - assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=1.0.0", systemPackageString); - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java deleted file mode 100644 index b4bda9a032..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.qpid.server.plugins; - -import org.apache.qpid.server.exchange.ExchangeType; -import org.apache.qpid.server.util.InternalBrokerBaseCase; - -import java.util.Map; - -public class PluginTest extends InternalBrokerBaseCase -{ - private static final String TEST_EXCHANGE_CLASS = "org.apache.qpid.extras.exchanges.example.TestExchangeType"; - - private static final String PLUGIN_DIRECTORY = System.getProperty("example.plugin.target"); - private static final String CACHE_DIRECTORY = System.getProperty("example.cache.target"); - - @Override - public void configure() - { - getConfiguration().getConfig().addProperty("plugin-directory", PLUGIN_DIRECTORY); - getConfiguration().getConfig().addProperty("cache-directory", CACHE_DIRECTORY); - } - - public void disabled_testLoadExchanges() throws Exception - { - PluginManager manager = getRegistry().getPluginManager(); - Map<String, ExchangeType<?>> exchanges = manager.getExchanges(); - assertNotNull("No exchanges found in " + PLUGIN_DIRECTORY, exchanges); - assertEquals("Wrong number of exchanges found in " + PLUGIN_DIRECTORY, 2, exchanges.size()); - assertNotNull("Wrong exchange found in " + PLUGIN_DIRECTORY, exchanges.get(TEST_EXCHANGE_CLASS)); - } - - public void testNoExchanges() throws Exception - { - PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp", null); - Map<String, ExchangeType<?>> exchanges = manager.getExchanges(); - assertTrue("Exchanges found", exchanges.isEmpty()); - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java index 63d4d196e1..358246330a 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java @@ -24,7 +24,7 @@ import org.apache.qpid.AMQException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.configuration.QueueConfiguration; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; +import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.logging.LogSubject; import org.apache.qpid.server.message.ServerMessage; diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java new file mode 100644 index 0000000000..f670d80ae8 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + * + */ +package org.apache.qpid.server.security.auth.database; + +import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser; +import org.apache.qpid.server.security.auth.UsernamePrincipal; +import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5Initialiser; +import org.apache.qpid.server.security.auth.sasl.plain.PlainInitialiser; + +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.login.AccountNotFoundException; +import java.io.IOException; +import java.security.Principal; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +public class PropertiesPrincipalDatabase implements PrincipalDatabase +{ + private Properties _users; + + private Map<String, AuthenticationProviderInitialiser> _saslServers; + + public PropertiesPrincipalDatabase(Properties users) + { + _users = users; + + _saslServers = new HashMap<String, AuthenticationProviderInitialiser>(); + + /** + * Create Authenticators for Properties Principal Database. + */ + + // Accept MD5 incomming and use plain comparison with the file + PlainInitialiser cram = new PlainInitialiser(); + cram.initialise(this); + // Accept Plain incomming and hash it for comparison to the file. + CRAMMD5Initialiser plain = new CRAMMD5Initialiser(); + plain.initialise(this, CRAMMD5Initialiser.HashDirection.INCOMMING); + + _saslServers.put(plain.getMechanismName(), cram); + _saslServers.put(cram.getMechanismName(), plain); + } + + public void setPassword(Principal principal, PasswordCallback callback) throws IOException, AccountNotFoundException + { + if (principal == null) + { + throw new IllegalArgumentException("principal must not be null"); + } + + + + final String pwd = _users.getProperty(principal.getName()); + + if (pwd != null) + { + callback.setPassword(pwd.toCharArray()); + } + else + { + throw new AccountNotFoundException("No account found for principal " + principal); + } + } + + public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException + { + //fixme this is not correct as toCharArray is not safe based on the type of string. + char[] pwd = _users.getProperty(principal).toCharArray(); + + return compareCharArray(pwd, password); + } + + public boolean updatePassword(Principal principal, char[] password) throws AccountNotFoundException + { + return false; // updates denied + } + + public boolean createPrincipal(Principal principal, char[] password) + { + return false; // updates denied + } + + public boolean deletePrincipal(Principal principal) throws AccountNotFoundException + { + return false; // updates denied + } + + private boolean compareCharArray(char[] a, char[] b) + { + boolean equal = false; + if (a.length == b.length) + { + equal = true; + int index = 0; + while (equal && index < a.length) + { + equal = a[index] == b[index]; + index++; + } + } + return equal; + } + + + public Map<String, AuthenticationProviderInitialiser> getMechanisms() + { + return _saslServers; + } + + public List<Principal> getUsers() + { + return new LinkedList<Principal>(); //todo + } + + public Principal getUser(String username) + { + if (_users.getProperty(username) != null) + { + return new UsernamePrincipal(username); + } + else + { + return null; + } + } + + public void reload() throws IOException + { + //No file to update from, so do nothing. + } + + @Override + public void setPasswordFile(String passwordFile) + { + throw new UnsupportedOperationException(); + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java index a36e97199f..cfeb7c525b 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java @@ -24,24 +24,13 @@ import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHel import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.XMLConfiguration; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; + import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; -import org.apache.qpid.server.util.InternalBrokerBaseCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase +public class AnonymousAuthenticationManagerTest extends QpidTestCase { - - private AuthenticationManager _manager = null; - - public void setUp() throws Exception - { - _manager = AnonymousAuthenticationManager.INSTANCE; - } - + private AuthenticationManager _manager = new AnonymousAuthenticationManager(); public void tearDown() throws Exception { @@ -51,29 +40,6 @@ public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase } } - private ConfigurationPlugin getPlainDatabaseConfig() throws ConfigurationException - { - final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration(); - - XMLConfiguration xmlconfig = new XMLConfiguration(); - xmlconfig.addProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName()); - - // Create a CompositeConfiguration as this is what the broker uses - CompositeConfiguration composite = new CompositeConfiguration(); - composite.addConfiguration(xmlconfig); - config.setConfiguration("security", xmlconfig); - return config; - } - - - public void testConfiguration() throws Exception - { - AuthenticationManager authenticationManager = - AnonymousAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig()); - - assertNull("AnonymousAuthenticationManager unexpectedly created when not in config", authenticationManager); - } - public void testGetMechanisms() throws Exception { assertEquals("ANONYMOUS", _manager.getMechanisms()); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java index 9b7131c71a..aeab1e4343 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java @@ -19,112 +19,101 @@ */ package org.apache.qpid.server.security.auth.manager; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.util.ArrayList; +import java.security.Principal; +import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; -import java.util.Map; +import javax.security.sasl.SaslException; +import javax.security.sasl.SaslServer; + +import junit.framework.TestCase; + +import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.configuration.ServerConfiguration; -import org.apache.qpid.server.plugins.Plugin; -import org.apache.qpid.server.plugins.PluginManager; -import org.apache.qpid.server.security.SecurityManager.SecurityConfiguration; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; +import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.security.SubjectCreator; +import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.group.GroupPrincipalAccessor; -import org.mockito.Mockito; - -import junit.framework.TestCase; public class AuthenticationManagerRegistryTest extends TestCase { - private static final Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> EMPTY_PLUGINMAP = Collections.emptyMap(); + @SuppressWarnings("unchecked") + private QpidServiceLoader<AuthenticationManagerFactory> _authManagerServiceLoader = mock(QpidServiceLoader.class); - private PluginManager _pluginManager = Mockito.mock(PluginManager.class); - private ServerConfiguration _serverConfiguration = Mockito.mock(ServerConfiguration.class); - private SecurityConfiguration _securityConfiguration = Mockito.mock(SecurityConfiguration.class); + private ServerConfiguration _serverConfiguration = mock(ServerConfiguration.class); + private Configuration _serverCommonsConfig = mock(Configuration.class); + private Configuration _securityCommonsConfig = mock(Configuration.class); - private List<AuthenticationManager> _allCreatedAuthManagers = new ArrayList<AuthenticationManager>(); + private GroupPrincipalAccessor _groupPrincipalAccessor = mock(GroupPrincipalAccessor.class); - private GroupPrincipalAccessor _groupPrincipalAccessor = mock(GroupPrincipalAccessor.class);; + private TestAuthenticationManager1 _testAuthManager1 = new TestAuthenticationManager1(); + private TestAuthenticationManager2 _testAuthManager2 = new TestAuthenticationManager2(); + + private AuthenticationManagerFactory _testAuthManager1Factory = newMockFactoryProducing(_testAuthManager1); + private AuthenticationManagerFactory _testAuthManager2Factory = newMockFactoryProducing(_testAuthManager2); @Override protected void setUp() throws Exception { super.setUp(); - - // Setup server configuration to return mock security config. - when(_serverConfiguration.getConfiguration(SecurityConfiguration.class.getName())).thenReturn(_securityConfiguration); - } - - @Override - protected void tearDown() throws Exception - { - try - { - verifyAllCreatedAuthManagersClosed(); - } - finally - { - super.tearDown(); - } + when(_serverConfiguration.getConfig()).thenReturn(_serverCommonsConfig); + when(_serverCommonsConfig.subset("security")).thenReturn(_securityCommonsConfig); } public void testNoAuthenticationManagerFactoryPluginsFound() throws Exception { - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(EMPTY_PLUGINMAP); + String noServicesMessage = "mock exception - no services found"; + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenThrow(new RuntimeException(noServicesMessage)); try { - new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); fail("Exception not thrown"); } - catch (ConfigurationException ce) + catch (RuntimeException ce) { // PASS - assertEquals("No authentication manager factory plugins found. Check the desired authentication manager plugin has been placed in the plugins directory.", - ce.getMessage()); + assertEquals(noServicesMessage, ce.getMessage()); } } public void testSameAuthenticationManagerSpecifiedTwice() throws Exception { - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); + List<AuthenticationManagerFactory> duplicateFactories = Arrays.asList(_testAuthManager1Factory, _testAuthManager1Factory); - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory, myAuthManagerFactory); - - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(duplicateFactories); try { - new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); fail("Exception not thrown"); } - catch (ConfigurationException ce) + catch (RuntimeException e) { - // PASS - assertEquals("Cannot configure more than one authentication manager of type " + myAuthManagerFactory.getPluginClass().getSimpleName() + ". Remove configuration for one of the authentication managers.", - ce.getMessage()); + assertTrue(e.getMessage().contains("Cannot configure more than one authentication manager with name")); + assertTrue(e.getMessage().contains(TestAuthenticationManager1.class.getSimpleName())); } } public void testMultipleAuthenticationManagersSpecifiedButNoDefaultSpecified() throws Exception { - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class); - - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2); + List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory); - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList); when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(null); try { - new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); fail("Exception not thrown"); } catch (ConfigurationException ce) @@ -139,17 +128,14 @@ public class AuthenticationManagerRegistryTest extends TestCase { String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager"; - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class); + List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory); - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2); - - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList); when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(myDefaultAuthManagerSimpleClassName); try { - new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); fail("Exception not thrown"); } catch (ConfigurationException ce) @@ -165,16 +151,14 @@ public class AuthenticationManagerRegistryTest extends TestCase String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager"; int portNumber = 1234; - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); - - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1); + List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory); - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList); when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(portNumber, myDefaultAuthManagerSimpleClassName)); try { - new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); fail("Exception not thrown"); } catch (ConfigurationException ce) @@ -186,123 +170,186 @@ public class AuthenticationManagerRegistryTest extends TestCase public void testGetAuthenticationManagerForInetSocketAddress() throws Exception { - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1); + List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory); - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList); - AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); SubjectCreator subjectCreator = registry.getSubjectCreator(new InetSocketAddress(1234)); - assertEquals("TestAuthenticationManager1", subjectCreator.getMechanisms()); - - registry.close(); + assertSubjectCreatorUsingExpectedAuthManager(_testAuthManager1, subjectCreator); } public void testGetAuthenticationManagerForNonInetSocketAddress() throws Exception { - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1); + List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory); - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList); - AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); SubjectCreator subjectCreator = registry.getSubjectCreator(mock(SocketAddress.class)); - assertEquals("TestAuthenticationManager1", subjectCreator.getMechanisms()); - - registry.close(); + assertSubjectCreatorUsingExpectedAuthManager(_testAuthManager1, subjectCreator); } public void testGetAuthenticationManagerWithMultipleAuthenticationManager() throws Exception { - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class); - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2); + List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory); + + AuthenticationManager defaultAuthManger = _testAuthManager1; + AuthenticationManager unmappedAuthManager = _testAuthManager2; + + String defaultAuthMangerName = defaultAuthManger.getClass().getSimpleName(); + String mappedAuthManagerName = unmappedAuthManager.getClass().getSimpleName(); - String defaultAuthManger = myAuthManagerFactory1.getPluginName(); int unmappedPortNumber = 1234; int mappedPortNumber = 1235; - String mappedAuthManager = myAuthManagerFactory2.getPluginName(); - - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); - when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthManger); - when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(mappedPortNumber, mappedAuthManager)); - AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList); + when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthMangerName); + when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(mappedPortNumber, mappedAuthManagerName)); - SubjectCreator subjectCreator = registry.getSubjectCreator(new InetSocketAddress(unmappedPortNumber)); - assertEquals("TestAuthenticationManager1", subjectCreator.getMechanisms()); + AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); - SubjectCreator subjectCreator2 = registry.getSubjectCreator(new InetSocketAddress(mappedPortNumber)); - assertEquals("TestAuthenticationManager2", subjectCreator2.getMechanisms()); + SubjectCreator subjectCreatorForDefaultAuthManager = registry.getSubjectCreator(new InetSocketAddress(unmappedPortNumber)); + assertSubjectCreatorUsingExpectedAuthManager(defaultAuthManger, subjectCreatorForDefaultAuthManager); - registry.close(); + SubjectCreator subjectCreatorForUnmappedAuthManager = registry.getSubjectCreator(new InetSocketAddress(mappedPortNumber)); + assertSubjectCreatorUsingExpectedAuthManager(unmappedAuthManager, subjectCreatorForUnmappedAuthManager); } public void testAuthenticationManagersAreClosed() throws Exception { - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class); - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class); - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2); + AuthenticationManager defaultAuthManager = mock(MockAuthenticationManager1.class); + AuthenticationManagerFactory defaultAuthManagerFactory = newMockFactoryProducing(defaultAuthManager); + + AuthenticationManager authManager2 = mock(MockAuthenticationManager2.class); + AuthenticationManagerFactory authManagerFactory2 = newMockFactoryProducing(authManager2); - String defaultAuthManger = myAuthManagerFactory1.getPluginName(); - when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap); - when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthManger); + List<AuthenticationManagerFactory> factoryList = Arrays.asList(defaultAuthManagerFactory, authManagerFactory2); - AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager, _groupPrincipalAccessor); + String defaultAuthMangerName = defaultAuthManager.getClass().getSimpleName(); + when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthMangerName); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList); + + AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); registry.close(); + + verify(defaultAuthManager).close(); + verify(authManager2).close(); } - private AuthenticationManagerPluginFactory<? extends Plugin> newMockFactoryProducingMockAuthManagerImplementing(Class<? extends AuthenticationManager> authManagerClazz) - throws ConfigurationException + public void testAlreadyInitialisedAuthManagersAreClosedWhenAnotherAuthManagerInitFails() throws Exception { - AuthenticationManager myAuthManager = mock(authManagerClazz); - when(myAuthManager.getMechanisms()).thenReturn(authManagerClazz.getSimpleName()); // used to verify the getAuthenticationManagerFor returns expected impl. + AuthenticationManager authManger1 = mock(MockAuthenticationManager1.class); + AuthenticationManagerFactory authManager1Factory = newMockFactoryProducing(authManger1); - AuthenticationManagerPluginFactory myAuthManagerFactory = mock(AuthenticationManagerPluginFactory.class); - when(myAuthManagerFactory.getPluginClass()).thenReturn(myAuthManager.getClass()); - when(myAuthManagerFactory.getPluginName()).thenReturn(myAuthManager.getClass().getSimpleName()); - when(myAuthManagerFactory.newInstance(_securityConfiguration)).thenReturn(myAuthManager); + AuthenticationManager authManager2 = mock(MockAuthenticationManager2.class); + AuthenticationManagerFactory authManagerFactory2 = newMockFactoryProducing(authManager2); - _allCreatedAuthManagers.add(myAuthManager); + List<AuthenticationManagerFactory> factoryList = Arrays.asList(authManager1Factory, authManagerFactory2); + when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList); + + doThrow(new RuntimeException("mock auth manager 2 init exception")).when(authManager2).initialise(); + + try + { + new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader); + fail("Exception not thrown"); + } + catch (RuntimeException e) + { + // PASS + } + + verify(authManger1).close(); + } + + + private AuthenticationManagerFactory newMockFactoryProducing(AuthenticationManager myAuthManager) + { + AuthenticationManagerFactory myAuthManagerFactory = mock(AuthenticationManagerFactory.class); + when(myAuthManagerFactory.createInstance(_securityCommonsConfig)).thenReturn(myAuthManager); return myAuthManagerFactory; } - private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> createPluginMap( - AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory) + private void assertSubjectCreatorUsingExpectedAuthManager(AuthenticationManager expectedAuthenticationManager, SubjectCreator subjectCreator) { - return createPluginMap(myAuthManagerFactory, null); + assertEquals( + "The subject creator should be using " + expectedAuthenticationManager + " so its mechanisms should match", + expectedAuthenticationManager.getMechanisms(), + subjectCreator.getMechanisms()); } - private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> createPluginMap( - AuthenticationManagerPluginFactory<? extends Plugin> authManagerFactory1, - AuthenticationManagerPluginFactory<? extends Plugin> authManagerFactory2) + /** @see MockAuthenticationManager2 */ + private interface MockAuthenticationManager1 extends AuthenticationManager { - Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = new HashMap<String, AuthenticationManagerPluginFactory<? extends Plugin>>(); - pluginMap.put("config.path.unused1", authManagerFactory1); - if (authManagerFactory2 != null) - { - pluginMap.put("config.path.unused2", authManagerFactory2); - } - return pluginMap; } - private void verifyAllCreatedAuthManagersClosed() + /** + * I only exist so that mock implementations of me have a different class to {@link MockAuthenticationManager1}, + * as mandated by {@link AuthenticationManagerRegistry} + */ + private interface MockAuthenticationManager2 extends AuthenticationManager { - for (Iterator<AuthenticationManager> iterator = _allCreatedAuthManagers.iterator(); iterator.hasNext();) + } + + /** + * We use a stub rather than a mock because {@link AuthenticationManagerRegistry} relies on {@link AuthenticationManager} class names, + * which are hard to predict for mocks. + */ + private abstract class TestAuthenticationManager implements AuthenticationManager + { + @Override + public void close() { - AuthenticationManager authenticationManager = (AuthenticationManager) iterator.next(); - verify(authenticationManager).close(); + // no-op + } + + @Override + public void initialise() + { + // no-op + } + + @Override + public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException + { + throw new UnsupportedOperationException(); + } + + @Override + public AuthenticationResult authenticate(SaslServer server, byte[] response) + { + throw new UnsupportedOperationException(); + } + + @Override + public AuthenticationResult authenticate(String username, String password) + { + throw new UnsupportedOperationException(); } } - private interface TestAuthenticationManager1 extends AuthenticationManager + private class TestAuthenticationManager1 extends TestAuthenticationManager { + @Override + public String getMechanisms() + { + return "MECHANISMS1"; + } } - private interface TestAuthenticationManager2 extends AuthenticationManager + private class TestAuthenticationManager2 extends TestAuthenticationManager { + /** + * Needs to different from {@link TestAuthenticationManager1#getMechanisms()} to aid our test assertions. + */ + @Override + public String getMechanisms() + { + return "MECHANISMS2"; + } } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java index 4e0643e229..a66d73c47d 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java @@ -23,56 +23,13 @@ import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHel import javax.security.auth.x500.X500Principal; import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.XMLConfiguration; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; import org.apache.qpid.server.security.auth.AuthenticationResult; -import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; -import org.apache.qpid.server.util.InternalBrokerBaseCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class ExternalAuthenticationManagerTest extends InternalBrokerBaseCase +public class ExternalAuthenticationManagerTest extends QpidTestCase { - - private AuthenticationManager _manager = null; - - public void setUp() throws Exception - { - _manager = ExternalAuthenticationManager.INSTANCE; - } - - - public void tearDown() throws Exception - { - if(_manager != null) - { - _manager = null; - } - } - - private ConfigurationPlugin getPlainDatabaseConfig() throws ConfigurationException - { - final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration(); - - XMLConfiguration xmlconfig = new XMLConfiguration(); - xmlconfig.addProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName()); - - // Create a CompositeConfiguration as this is what the broker uses - CompositeConfiguration composite = new CompositeConfiguration(); - composite.addConfiguration(xmlconfig); - config.setConfiguration("security", xmlconfig); - return config; - } - - - public void testConfiguration() throws Exception - { - AuthenticationManager authenticationManager = - ExternalAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig()); - - assertNull("ExternalAuthenticationManager unexpectedly created when not in config", authenticationManager); - } + private AuthenticationManager _manager = new ExternalAuthenticationManager(); public void testGetMechanisms() throws Exception { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java new file mode 100644 index 0000000000..d76ea2674c --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.manager; + +import java.io.File; +import java.io.FileNotFoundException; + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.XMLConfiguration; +import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase; +import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; + +import junit.framework.TestCase; + +public class PrincipalDatabaseAuthManagerFactoryTest extends TestCase +{ + PrincipalDatabaseAuthManagerFactory _factory = new PrincipalDatabaseAuthManagerFactory(); + private Configuration _configuration = new XMLConfiguration(); + private File _emptyPasswordFile; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + _emptyPasswordFile = File.createTempFile(getName(), "passwd"); + _emptyPasswordFile.deleteOnExit(); + } + + public void testPlainInstanceCreated() throws Exception + { + _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName()); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile"); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath()); + + AuthenticationManager manager = _factory.createInstance(_configuration); + assertNotNull(manager); + assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager); + assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof PlainPasswordFilePrincipalDatabase); + } + + public void testBase64MD5nstanceCreated() throws Exception + { + _configuration.setProperty("pd-auth-manager.principal-database.class", Base64MD5PasswordFilePrincipalDatabase.class.getName()); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile"); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath()); + + AuthenticationManager manager = _factory.createInstance(_configuration); + assertNotNull(manager); + assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager); + assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof Base64MD5PasswordFilePrincipalDatabase); + } + + public void testPasswordFileNotFound() throws Exception + { + _emptyPasswordFile.delete(); + + _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName()); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile"); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath()); + + try + { + _factory.createInstance(_configuration); + } + catch (RuntimeException re) + { + assertTrue(re.getCause() instanceof FileNotFoundException); + } + } + + public void testReturnsNullWhenNoConfig() throws Exception + { + AuthenticationManager manager = _factory.createInstance(_configuration); + assertNull(manager); + } + + public void testReturnsNullWhenConfigForOtherPDImplementation() throws Exception + { + _configuration.setProperty("pd-auth-manager.principal-database.class", "mypdimpl"); + + AuthenticationManager manager = _factory.createInstance(_configuration); + assertNull(manager); + } + + public void testReturnsNullWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified() throws Exception + { + _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName()); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile"); + // no pd-auth-manager.attributes.attribute.value + + AuthenticationManager manager = _factory.createInstance(_configuration); + assertNull(manager); + } + + public void testReturnsNullWhenConfigForPlainPDImplementationWrongArgumentName() throws Exception + { + _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName()); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "wrong"); + _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", "/does/not/matter"); + + AuthenticationManager manager = _factory.createInstance(_configuration); + assertNull(manager); + } + + + + @Override + protected void tearDown() throws Exception + { + try + { + if (_emptyPasswordFile == null && _emptyPasswordFile.exists()) + { + _emptyPasswordFile.delete(); + } + } + finally + { + super.tearDown(); + } + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java index 391eb4e665..1ae667804a 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java @@ -21,133 +21,91 @@ package org.apache.qpid.server.security.auth.manager; import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.XMLConfiguration; +import java.security.Provider; +import java.security.Security; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import javax.security.auth.callback.CallbackHandler; +import javax.security.sasl.SaslException; +import javax.security.sasl.SaslServer; +import javax.security.sasl.SaslServerFactory; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; -import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.util.InternalBrokerBaseCase; - -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.security.Provider; -import java.security.Security; +import org.apache.qpid.server.security.auth.database.PrincipalDatabase; +import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser; +import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser; +import org.apache.qpid.test.utils.QpidTestCase; /** - * * Tests the public methods of PrincipalDatabaseAuthenticationManager. * */ -public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBaseCase +public class PrincipalDatabaseAuthenticationManagerTest extends QpidTestCase { + private static final String MOCK_MECH_NAME = "MOCK-MECH-NAME"; private static final UsernamePrincipal PRINCIPAL = new UsernamePrincipal("guest"); + private AuthenticationManager _manager = null; // Class under test - private String TEST_USERNAME = "guest"; - private String TEST_PASSWORD = "guest"; + private PrincipalDatabase _principalDatabase; - /** - * @see org.apache.qpid.server.util.InternalBrokerBaseCase#tearDown() - */ @Override public void tearDown() throws Exception { - super.tearDown(); if (_manager != null) { _manager.close(); } + super.tearDown(); } - /** - * @see org.apache.qpid.server.util.InternalBrokerBaseCase#setUp() - */ - @Override - public void setUp() throws Exception + private void setupMocks() throws Exception { - super.setUp(); + _principalDatabase = mock(PrincipalDatabase.class); - final String passwdFilename = createPasswordFile().getCanonicalPath(); - final ConfigurationPlugin config = getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), - "passwordFile", passwdFilename); + AuthenticationProviderInitialiser _mockMechInitialiser = mock(AuthenticationProviderInitialiser.class); + Map<String, AuthenticationProviderInitialiser> _initialisers = Collections.singletonMap(MOCK_MECH_NAME, _mockMechInitialiser); - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(config); - } + when(_principalDatabase.getMechanisms()).thenReturn(_initialisers); - /** - * Tests where the case where the config specifies a PD implementation - * that is not found. - */ - public void testPrincipalDatabaseImplementationNotFound() throws Exception - { - try - { - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig("not.Found", null, null)); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - // PASS - } + _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase); + _manager.initialise(); } - /** - * Tests where the case where the config specifies a PD implementation - * of the wrong type. - */ - public void testPrincipalDatabaseImplementationWrongType() throws Exception + private void setupMocksWithInitialiser() throws Exception { - try - { - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(String.class.getName(), null, null)); // Not a PrincipalDatabase implementation - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - // PASS - } - } + _principalDatabase = mock(PrincipalDatabase.class); - /** - * Tests the case where a setter with the desired name cannot be found. - */ - public void testPrincipalDatabaseSetterNotFound() throws Exception - { - try - { - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "noMethod", "test")); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) + UsernamePasswordInitialiser usernamePasswordInitialiser = new UsernamePasswordInitialiser() { - // PASS - } - } + @Override + public Class<? extends SaslServerFactory> getServerFactoryClassForJCARegistration() + { + return MySaslServerFactory.class; + } - /** - * QPID-1347. Make sure the exception message and stack trace is reasonable for an absent password file. - */ - public void testPrincipalDatabaseThrowsSetterFileNotFound() throws Exception - { - try - { - _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "passwordFile", "/not/found")); - fail("Exception not thrown"); - } - catch (ConfigurationException ce) - { - // PASS - assertNotNull("Expected an underlying cause", ce.getCause()); - assertEquals(FileNotFoundException.class, ce.getCause().getClass()); - } + @Override + public String getMechanismName() + { + return MOCK_MECH_NAME; + } + }; + + Map<String,AuthenticationProviderInitialiser> initialisers = new HashMap<String, AuthenticationProviderInitialiser>(); + initialisers.put(MOCK_MECH_NAME, usernamePasswordInitialiser); + + when(_principalDatabase.getMechanisms()).thenReturn(initialisers); + + usernamePasswordInitialiser.initialise(_principalDatabase); + + _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase); + _manager.initialise(); } /** @@ -155,11 +113,16 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa */ public void testRegisteredMechanisms() throws Exception { + //Ensure we haven't registered anything yet (though this would really indicate a prior test failure!) + Provider qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME); + assertNull(qpidProvider); + + setupMocksWithInitialiser(); + assertNotNull(_manager.getMechanisms()); - // relies on those mechanisms attached to PropertiesPrincipalDatabaseManager - assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms()); + assertEquals(MOCK_MECH_NAME, _manager.getMechanisms()); - Provider qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME); + qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME); assertNotNull(qpidProvider); } @@ -169,7 +132,9 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa */ public void testSaslMechanismCreation() throws Exception { - SaslServer server = _manager.createSaslServer("CRAM-MD5", "localhost", null); + setupMocksWithInitialiser(); + + SaslServer server = _manager.createSaslServer(MOCK_MECH_NAME, "localhost", null); assertNotNull(server); // Merely tests the creation of the mechanism. Mechanisms themselves are tested // by their own tests. @@ -182,6 +147,7 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa */ public void testSaslAuthenticationSuccess() throws Exception { + setupMocks(); SaslServer testServer = createTestSaslServer(true, false); @@ -199,6 +165,8 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa */ public void testSaslAuthenticationNotCompleted() throws Exception { + setupMocks(); + SaslServer testServer = createTestSaslServer(false, false); AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes()); @@ -215,6 +183,8 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa */ public void testSaslAuthenticationError() throws Exception { + setupMocks(); + SaslServer testServer = createTestSaslServer(false, true); AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes()); @@ -222,25 +192,23 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa assertEquals(AuthenticationStatus.ERROR, result.getStatus()); } - /** - * Tests that the authenticate method correctly interprets an - * authentication success. - * - */ public void testNonSaslAuthenticationSuccess() throws Exception { + setupMocks(); + + when(_principalDatabase.verifyPassword("guest", "guest".toCharArray())).thenReturn(true); + AuthenticationResult result = _manager.authenticate("guest", "guest"); assertOnlyContainsWrapped(PRINCIPAL, result.getPrincipals()); assertEquals(AuthenticationStatus.SUCCESS, result.getStatus()); } - /** - * Tests that the authenticate method correctly interprets an - * authentication success. - * - */ public void testNonSaslAuthenticationNotCompleted() throws Exception { + setupMocks(); + + when(_principalDatabase.verifyPassword("guest", "wrongpassword".toCharArray())).thenReturn(false); + AuthenticationResult result = _manager.authenticate("guest", "wrongpassword"); assertEquals("Principals was not expected size", 0, result.getPrincipals().size()); assertEquals(AuthenticationStatus.CONTINUE, result.getStatus()); @@ -251,7 +219,9 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa */ public void testClose() throws Exception { - assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms()); + setupMocksWithInitialiser(); + + assertEquals(MOCK_MECH_NAME, _manager.getMechanisms()); assertNotNull(Security.getProvider(AuthenticationManager.PROVIDER_NAME)); _manager.close(); @@ -267,94 +237,90 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa */ private SaslServer createTestSaslServer(final boolean complete, final boolean throwSaslException) { - return new SaslServer() - { - public String getMechanismName() - { - return null; - } + return new MySaslServer(throwSaslException, complete); + } - public byte[] evaluateResponse(byte[] response) throws SaslException - { - if (throwSaslException) - { - throw new SaslException("Mocked exception"); - } - return null; - } + public static final class MySaslServer implements SaslServer + { + private final boolean _throwSaslException; + private final boolean _complete; - public boolean isComplete() - { - return complete; - } + public MySaslServer() + { + this(false, true); + } - public String getAuthorizationID() - { - return complete ? "guest" : null; - } + private MySaslServer(boolean throwSaslException, boolean complete) + { + _throwSaslException = throwSaslException; + _complete = complete; + } - public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException - { - return null; - } + public String getMechanismName() + { + return null; + } - public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException + public byte[] evaluateResponse(byte[] response) throws SaslException + { + if (_throwSaslException) { - return null; + throw new SaslException("Mocked exception"); } + return null; + } - public Object getNegotiatedProperty(String propName) - { - return null; - } + public boolean isComplete() + { + return _complete; + } - public void dispose() throws SaslException - { - } - }; - } + public String getAuthorizationID() + { + return _complete ? "guest" : null; + } - private ConfigurationPlugin getConfig(final String clazz, final String argName, final String argValue) throws Exception - { - final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration(); + public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException + { + return null; + } - XMLConfiguration xmlconfig = new XMLConfiguration(); - xmlconfig.addProperty("pd-auth-manager.principal-database.class", clazz); + public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException + { + return null; + } - if (argName != null) + public Object getNegotiatedProperty(String propName) { - xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.name", argName); - xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.value", argValue); + return null; } - // Create a CompositeConfiguration as this is what the broker uses - CompositeConfiguration composite = new CompositeConfiguration(); - composite.addConfiguration(xmlconfig); - config.setConfiguration("security", xmlconfig); - return config; + public void dispose() throws SaslException + { + } } - private File createPasswordFile() throws Exception + public static class MySaslServerFactory implements SaslServerFactory { - BufferedWriter writer = null; - try - { - File testFile = File.createTempFile(this.getClass().getName(),"tmp"); - testFile.deleteOnExit(); - - writer = new BufferedWriter(new FileWriter(testFile)); - writer.write(TEST_USERNAME + ":" + TEST_PASSWORD); - writer.newLine(); - - return testFile; - - } - finally + @Override + public SaslServer createSaslServer(String mechanism, String protocol, + String serverName, Map<String, ?> props, CallbackHandler cbh) + throws SaslException { - if (writer != null) + if (MOCK_MECH_NAME.equals(mechanism)) + { + return new MySaslServer(); + } + else { - writer.close(); + return null; } } + + @Override + public String[] getMechanismNames(Map<String, ?> props) + { + return new String[]{MOCK_MECH_NAME}; + } } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java new file mode 100644 index 0000000000..aab5f80836 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.security.auth.manager; + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.XMLConfiguration; + +import junit.framework.TestCase; + +public class SimpleLDAPAuthenticationManagerFactoryTest extends TestCase +{ + private SimpleLDAPAuthenticationManagerFactory _factory = new SimpleLDAPAuthenticationManagerFactory(); + private Configuration _configuration = new XMLConfiguration(); + + public void testInstanceCreated() throws Exception + { + _configuration.setProperty("simple-ldap-auth-manager.provider-url", "ldaps://example.com:636/"); + _configuration.setProperty("simple-ldap-auth-manager.search-context", "dc=example"); + + AuthenticationManager manager = _factory.createInstance(_configuration); + assertNotNull(manager); + } + + public void testReturnsNullWhenNoConfig() throws Exception + { + AuthenticationManager manager = _factory.createInstance(_configuration); + assertNull(manager); + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java index 8c7f3ad6ef..f94d8ddfc3 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java @@ -86,4 +86,10 @@ public class TestPrincipalDatabase implements PrincipalDatabase // TODO Auto-generated method stub } + @Override + public void setPasswordFile(String passwordFile) throws IOException + { + // TODO Auto-generated method stub + } + } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java new file mode 100644 index 0000000000..5b04df2fc5 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.security.group; + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.XMLConfiguration; +import org.apache.qpid.test.utils.TestFileUtils; + +import junit.framework.TestCase; + +public class FileGroupManagerFactoryTest extends TestCase +{ + + private FileGroupManagerFactory _factory = new FileGroupManagerFactory(); + private Configuration _configuration = new XMLConfiguration(); + private String _emptyButValidGroupFile = TestFileUtils.createTempFile(this).getAbsolutePath(); + + public void testInstanceCreated() throws Exception + { + _configuration.setProperty("file-group-manager.attributes.attribute.name", "groupFile"); + _configuration.setProperty("file-group-manager.attributes.attribute.value", _emptyButValidGroupFile); + + GroupManager manager = _factory.createInstance(_configuration); + assertNotNull(manager); + assertTrue(manager instanceof FileGroupManager); + } + + public void testReturnsNullWhenNoConfig() throws Exception + { + GroupManager manager = _factory.createInstance(_configuration); + assertNull(manager); + } + + public void testReturnsNullWhenConfigNotForThisPlugin() throws Exception + { + _configuration.setProperty("other-group-manager", "config"); + + GroupManager manager = _factory.createInstance(_configuration); + assertNull(manager); + } + + public void testRejectsConfigThatHasUnexpectedAttributeName() throws Exception + { + _configuration.setProperty("file-group-manager.attributes.attribute.name", "unexpected"); + _configuration.setProperty("file-group-manager.attributes.attribute.value", _emptyButValidGroupFile); + + try + { + _factory.createInstance(_configuration); + fail("Exception not thrown"); + } + catch (RuntimeException re) + { + // PASS + } + } + + public void testRejectsConfigThatIsMissingAttributeValue() throws Exception + { + _configuration.setProperty("file-group-manager.attributes.attribute.name", "groupFile"); + _configuration.setProperty("file-group-manager.attributes.attribute.value", null); + + try + { + _factory.createInstance(_configuration); + fail("Exception not thrown"); + } + catch (RuntimeException re) + { + // PASS + } + } + +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java index 165ecb098f..e926d72607 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java @@ -26,14 +26,11 @@ import java.security.Principal; import java.util.Properties; import java.util.Set; -import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.XMLConfiguration; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; import org.apache.qpid.server.security.auth.UsernamePrincipal; -import org.apache.qpid.server.util.InternalBrokerBaseCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class FileGroupManagerTest extends InternalBrokerBaseCase +public class FileGroupManagerTest extends QpidTestCase { private static final String MYGROUP_USERS = "user1"; private static final String MY_GROUP = "myGroup.users"; @@ -45,11 +42,6 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void tearDown() throws Exception { super.tearDown(); -//TODO: implement closable -// if (_manager != null) -// { -// _manager.close(); -// } if (_tmpGroupFile != null) { @@ -63,23 +55,18 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void testValidGroupFile() throws Exception { final String groupFileName = writeGroupFile(); - final ConfigurationPlugin config = getConfig("groupFile", groupFileName); - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(groupFileName); assertNotNull(_manager); } public void testNonExistentGroupFile() throws Exception { final String filePath = "/does.not.exist/"; - final File fileFile = new File(filePath); - - assertFalse("File already exists", fileFile.exists()); - final ConfigurationPlugin config = getConfig("groupFile", filePath); try { - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(filePath); fail("expected exception was not thrown"); } catch(ConfigurationException ce) @@ -92,8 +79,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void testGetGroupPrincipalsForUser() throws Exception { final String groupFileName = writeGroupFile(); - final ConfigurationPlugin config = getConfig("groupFile", groupFileName); - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(groupFileName); Set<Principal> principals = _manager.getGroupPrincipalsForUser("user1"); assertEquals(1, principals.size()); @@ -103,8 +89,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void testGetUserPrincipalsForGroup() throws Exception { final String groupFileName = writeGroupFile(); - final ConfigurationPlugin config = getConfig("groupFile", groupFileName); - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(groupFileName); Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup"); assertEquals(1, principals.size()); @@ -114,8 +99,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void testGetGroupPrincipals() throws Exception { final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS, MY_GROUP2, MYGROUP_USERS); - final ConfigurationPlugin config = getConfig("groupFile", groupFileName); - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(groupFileName); Set<Principal> principals = _manager.getGroupPrincipals(); assertEquals(2, principals.size()); @@ -126,8 +110,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void testCreateGroup() throws Exception { final String groupFileName = writeGroupFile(); - final ConfigurationPlugin config = getConfig("groupFile", groupFileName); - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(groupFileName); Set<Principal> principals = _manager.getGroupPrincipals(); assertEquals(1, principals.size()); @@ -142,8 +125,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void testRemoveGroup() throws Exception { final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS); - final ConfigurationPlugin config = getConfig("groupFile", groupFileName); - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(groupFileName); Set<Principal> principals = _manager.getGroupPrincipals(); assertEquals(1, principals.size()); @@ -157,8 +139,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void testAddUserToGroup() throws Exception { final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS); - final ConfigurationPlugin config = getConfig("groupFile", groupFileName); - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(groupFileName); Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup"); assertEquals(1, principals.size()); @@ -174,8 +155,7 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase public void testRemoveUserInGroup() throws Exception { final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS); - final ConfigurationPlugin config = getConfig("groupFile", groupFileName); - _manager = FileGroupManager.FACTORY.newInstance(config); + _manager = new FileGroupManager(groupFileName); Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup"); assertEquals(1, principals.size()); @@ -187,25 +167,6 @@ public class FileGroupManagerTest extends InternalBrokerBaseCase assertEquals(0, principals.size()); } - private ConfigurationPlugin getConfig(final String argName, final String argValue) throws Exception - { - final ConfigurationPlugin config = new FileGroupManager.FileGroupManagerConfiguration(); - - XMLConfiguration xmlconfig = new XMLConfiguration(); - - if (argName != null) - { - xmlconfig.addProperty("file-group-manager.attributes.attribute.name", argName); - xmlconfig.addProperty("file-group-manager.attributes.attribute.value", argValue); - } - - // Create a CompositeConfiguration as this is what the broker uses - CompositeConfiguration composite = new CompositeConfiguration(); - composite.addConfiguration(xmlconfig); - config.setConfiguration("security", xmlconfig); - return config; - } - private String writeGroupFile() throws Exception { return writeGroupFile(MY_GROUP, MYGROUP_USERS); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java deleted file mode 100644 index 23ee82eae6..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.signal; - -import org.apache.log4j.Logger; - -import org.apache.qpid.test.utils.QpidTestCase; - -import java.lang.management.ManagementFactory; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -public class SignalHandlerTaskTest extends QpidTestCase -{ - private static final Logger LOGGER = Logger.getLogger(SignalHandlerTaskTest.class); - private static final String SUN_MISC_SIGNAL_CLASS = "sun.misc.Signal"; - private static final String SUN_MISC_SIGNAL_HANDLER_CLASS = "sun.misc.SignalHandler"; - - protected void setUp() throws Exception - { - super.setUp(); - } - - public void testSignalHandlerTask() throws Exception - { - final boolean expectedResult = classifyExpectedRegistrationResult(); - final int pid = getPID(); - final CountDownLatch latch = new CountDownLatch(1); - - SignalHandlerTask hupReparseTask = new SignalHandlerTask() - { - public void handle() - { - latch.countDown(); - LOGGER.info("Signal handled, latch decremented"); - } - }; - - assertEquals("Unexpected result trying to register Signal handler", - expectedResult, hupReparseTask.register("HUP")); - LOGGER.info("Signal handler was registered"); - - assertEquals("unexpected count for the latch", 1, latch.getCount()); - - if(expectedResult) - { - //registration succeeded as expected, so now - //send SIGHUP and verify the handler was run - String cmd = "/bin/kill -SIGHUP " + pid; - - LOGGER.info("Sending SIGHUP"); - Runtime.getRuntime().exec(cmd); - - assertTrue("HUP Signal was not handled in the allowed timeframe", - latch.await(5, TimeUnit.SECONDS)); - } - } - - public void testGetPlatformDescription() throws Exception - { - assertNotNull(SignalHandlerTask.getPlatformDescription()); - } - - private boolean classifyExpectedRegistrationResult() - { - String os = System.getProperty("os.name"); - if(String.valueOf(os).toLowerCase().contains("windows")) - { - //Windows does not support SIGHUP so registration will fail - LOGGER.info("Running on windows, so we expect SIGHUP handler registration to fail"); - return false; - } - - //otherwise, if the signal handler classes are present we would expect - //registration to succeed - boolean classesPresent = true; - try - { - Class.forName(SUN_MISC_SIGNAL_CLASS); - Class.forName(SUN_MISC_SIGNAL_HANDLER_CLASS); - LOGGER.info("Signal handling classes were present so we expect SIGHUP handler registration to succeed"); - } - catch (ClassNotFoundException cnfe) - { - classesPresent = false; - } - - return classesPresent; - } - - private int getPID() - { - String processName = ManagementFactory.getRuntimeMXBean().getName(); - - int pid = Integer.parseInt(processName.substring(0,processName.indexOf('@'))); - LOGGER.info("PID was determined to be " + pid); - - return pid; - } - -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java index a1536565ad..e18269241e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java @@ -35,11 +35,11 @@ import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.exchange.DirectExchange; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.exchange.ExchangeRegistry; -import org.apache.qpid.server.exchange.ExchangeType; import org.apache.qpid.server.exchange.TopicExchange; import org.apache.qpid.server.message.AMQMessage; import org.apache.qpid.server.message.MessageMetaData; import org.apache.qpid.server.model.UUIDGenerator; +import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQPriorityQueue; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.AMQQueueFactory; @@ -97,6 +97,8 @@ public class MessageStoreTest extends InternalBrokerBaseCase public void setUp() throws Exception { + getConfigXml().addProperty("management.enabled", "false"); + super.setUp(); String storePath = System.getProperty("QPID_WORK") + File.separator + getName(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java index 411ed81d2a..600f0d591d 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java @@ -26,12 +26,11 @@ import java.util.Map; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.configuration.ServerConfiguration; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; import org.apache.qpid.server.logging.NullRootMessageLogger; import org.apache.qpid.server.logging.actors.BrokerActor; import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.logging.actors.GenericActor; -import org.apache.qpid.server.plugins.PluginManager; +import org.apache.qpid.server.logging.log4j.LoggingManagementFacade; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.security.SubjectCreator; import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabase; @@ -55,12 +54,14 @@ public class TestApplicationRegistry extends ApplicationRegistry { CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger())); GenericActor.setDefaultMessageLogger(new NullRootMessageLogger()); + LoggingManagementFacade.configure("test-profiles/log4j-test.xml"); + super.initialise(); } @Override protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry( - ServerConfiguration configuration, PluginManager pluginManager, final GroupPrincipalAccessor groupPrincipalAccessor) + ServerConfiguration configuration, final GroupPrincipalAccessor groupPrincipalAccessor) throws ConfigurationException { final Properties users = new Properties(); @@ -69,26 +70,7 @@ public class TestApplicationRegistry extends ApplicationRegistry final PropertiesPrincipalDatabase ppd = new PropertiesPrincipalDatabase(users); - final AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager() - { - - /** - * @see org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager#configure(org.apache.qpid.server.configuration.plugins.ConfigurationPlugin) - */ - @Override - public void configure(ConfigurationPlugin config) throws ConfigurationException - { - // We don't pass configuration to this test instance. - } - - @Override - public void initialise() - { - setPrincipalDatabase(ppd); - - super.initialise(); - } - }; + final AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager(ppd); pdam.initialise(); return new IAuthenticationManagerRegistry() |
