summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/java/broker/src/test')
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/AMQBrokerManagerMBeanTest.java1
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryAuthenticationManagerTest.java184
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/registry/TestableApplicationRegistry.java48
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java109
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java5
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java10
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java8
7 files changed, 356 insertions, 9 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/AMQBrokerManagerMBeanTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/AMQBrokerManagerMBeanTest.java
index 5c500771c2..d26e286c90 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/AMQBrokerManagerMBeanTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/AMQBrokerManagerMBeanTest.java
@@ -36,7 +36,6 @@ import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.store.TestableMemoryMessageStore;
import org.apache.qpid.server.store.TestableMemoryMessageStoreFactory;
import org.apache.qpid.server.util.TestApplicationRegistry;
import org.apache.qpid.server.virtualhost.VirtualHost;
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryAuthenticationManagerTest.java
new file mode 100644
index 0000000000..7fd608450a
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryAuthenticationManagerTest.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.qpid.server.registry;
+
+import java.net.InetSocketAddress;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
+import org.apache.qpid.server.util.InternalBrokerBaseCase;
+
+public class ApplicationRegistryAuthenticationManagerTest extends InternalBrokerBaseCase
+{
+ private Runnable _configureTask;
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ _configureTask = null;
+ super.tearDown();
+ }
+
+ @Override
+ protected void createBroker() throws Exception
+ {
+ // Do nothing - we don't want create broker called in setUp
+ }
+
+ @Override
+ protected void configure()
+ {
+ if(_configureTask != null)
+ {
+ _configureTask.run();
+ }
+ }
+
+ @Override
+ protected IApplicationRegistry createApplicationRegistry() throws ConfigurationException
+ {
+ return new TestableApplicationRegistry(getConfiguration());
+ }
+
+ private void reallyCreateBroker() throws Exception
+ {
+ super.createBroker();
+ }
+
+ public void testNoAuthenticationManagers() throws Exception
+ {
+ try
+ {
+ reallyCreateBroker();
+ fail("Expected a ConfigurationException when no AuthenticationManagers are defined");
+ }
+ catch(ConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+ public void testSingleAuthenticationManager() throws Exception
+ {
+ _configureTask =
+ new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ getConfiguration().getConfig().addProperty("security.anonymous-auth-manager", "");
+ }
+ };
+
+ try
+ {
+ reallyCreateBroker();
+ }
+ catch(ConfigurationException e)
+ {
+ fail("Unexpected ConfigurationException when creating the registry with a single AuthenticationManager");
+ }
+ }
+
+ public void testMultipleAuthenticationManagersNoDefault() throws Exception
+ {
+ _configureTask =
+ new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ getConfiguration().getConfig().addProperty("security.anonymous-auth-manager", "");
+ getConfiguration().getConfig().addProperty("security.pd-auth-manager.principal-database.class","org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase");
+ }
+ };
+ try
+ {
+ reallyCreateBroker();
+ fail("Expected ConfigurationException as two AuthenticationManagers are defined, but there is no default specified");
+ }
+ catch (ConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+ public void testDefaultAuthenticationManager() throws Exception
+ {
+ _configureTask =
+ new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ getConfiguration().getConfig().addProperty("security.anonymous-auth-manager", "");
+ getConfiguration().getConfig().addProperty("security.pd-auth-manager.principal-database.class","org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase");
+ getConfiguration().getConfig().addProperty("security.default-auth-manager", "AnonymousAuthenticationManager");
+ }
+ };
+ try
+ {
+ reallyCreateBroker();
+ }
+ catch (ConfigurationException e)
+ {
+ fail("Unexpected ConfigurationException when two AuthenticationManagers are defined, but there is a default specified");
+ }
+
+ AuthenticationManager authMgr =
+ ApplicationRegistry.getInstance().getAuthenticationManager(new InetSocketAddress(1));
+
+ assertNotNull("AuthenticationManager should not be null for any socket", authMgr);
+ assertEquals("AuthenticationManager not of expected class", AnonymousAuthenticationManager.class, authMgr.getClass());
+
+
+ }
+
+ public void testMappedAuthenticationManager() throws Exception
+ {
+ _configureTask =
+ new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ getConfiguration().getConfig().addProperty("security.anonymous-auth-manager", "");
+ getConfiguration().getConfig().addProperty("security.pd-auth-manager.principal-database.class","org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase");
+ getConfiguration().getConfig().addProperty("security.default-auth-manager", "PrincipalDatabaseAuthenticationManager");
+ getConfiguration().getConfig().addProperty("security.port-mappings.port-mapping.port", "200");
+ getConfiguration().getConfig().addProperty("security.port-mappings.port-mapping.auth-manager", "AnonymousAuthenticationManager");
+ }
+ };
+ reallyCreateBroker();
+
+ AuthenticationManager authMgr =
+ ApplicationRegistry.getInstance().getAuthenticationManager(new InetSocketAddress(200));
+
+ assertNotNull("AuthenticationManager should not be null for any socket", authMgr);
+ assertEquals("AuthenticationManager not of expected class", AnonymousAuthenticationManager.class, authMgr.getClass());
+
+ // test the default is still in effect for other ports
+ authMgr = ApplicationRegistry.getInstance().getAuthenticationManager(new InetSocketAddress(1));
+ assertEquals("AuthenticationManager not of expected class", PrincipalDatabaseAuthenticationManager.class, authMgr.getClass());
+
+
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/TestableApplicationRegistry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/TestableApplicationRegistry.java
new file mode 100644
index 0000000000..db7a7f7950
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/TestableApplicationRegistry.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.server.registry;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.logging.NullRootMessageLogger;
+import org.apache.qpid.server.logging.actors.BrokerActor;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.GenericActor;
+
+class TestableApplicationRegistry extends ApplicationRegistry
+{
+
+ public TestableApplicationRegistry(ServerConfiguration config) throws ConfigurationException
+ {
+ super(config);
+ }
+
+ @Override
+ public void initialise() throws Exception
+ {
+ CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger()));
+ GenericActor.setDefaultMessageLogger(new NullRootMessageLogger());
+ super.initialise();
+ }
+
+
+
+}
+
+
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
new file mode 100644
index 0000000000..eecde964a3
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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 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;
+
+public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase
+{
+
+ private AuthenticationManager _manager = null;
+
+ public void setUp() throws Exception
+ {
+ _manager = AnonymousAuthenticationManager.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 =
+ AnonymousAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig());
+
+ assertNull("AnonymousAuthenticationManager unexpectedly created when not in config", authenticationManager);
+ }
+
+ public void testGetMechanisms() throws Exception
+ {
+ assertEquals("ANONYMOUS", _manager.getMechanisms());
+ }
+
+ public void testCreateSaslServer() throws Exception
+ {
+ SaslServer server = _manager.createSaslServer("ANONYMOUS", "example.example.com");
+
+ assertEquals("Sasl Server mechanism name is not as expected", "ANONYMOUS", server.getMechanismName());
+
+ try
+ {
+ server = _manager.createSaslServer("PLAIN", "example.example.com");
+ fail("Expected creating SaslServer with incorrect mechanism to throw an exception");
+ }
+ catch (SaslException e)
+ {
+ // pass
+ }
+ }
+
+ public void testAuthenticate() throws Exception
+ {
+ SaslServer saslServer = _manager.createSaslServer("ANONYMOUS", "example.example.com");
+ AuthenticationResult result = _manager.authenticate(saslServer, new byte[0]);
+ assertNotNull(result);
+ assertEquals("Expected authentication to be successful",
+ AuthenticationResult.AuthenticationStatus.SUCCESS,
+ result.getStatus());
+ assertNotNull("Subject should not be null", result.getSubject());
+ }
+
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
index bef03057ec..584f3d1358 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.server.security.auth.rmi;
+import java.util.Map;
import junit.framework.TestCase;
import org.apache.commons.configuration.ConfigurationException;
@@ -126,9 +127,9 @@ public class RMIPasswordAuthenticatorTest extends TestCase
TestApplicationRegistry reg = new TestApplicationRegistry(serverConfig)
{
@Override
- protected AuthenticationManager createAuthenticationManager() throws ConfigurationException
+ protected Map<Integer, AuthenticationManager> createAuthenticationManagers() throws ConfigurationException
{
- return null;
+ return Collections.emptyMap();
}
};
ApplicationRegistry.initialise(reg);
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
index 8a34e92985..f8200bf1cd 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
@@ -20,8 +20,7 @@
*/
package org.apache.qpid.server.util;
-import java.util.UUID;
-
+import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.qpid.AMQException;
@@ -85,7 +84,7 @@ public class InternalBrokerBaseCase extends QpidTestCase
configure();
- _registry = new TestApplicationRegistry(_configuration);
+ _registry = createApplicationRegistry();
ApplicationRegistry.initialise(_registry);
_registry.getVirtualHostRegistry().setDefaultVirtualHostName(getName());
_virtualHost = _registry.getVirtualHostRegistry().getVirtualHost(getName());
@@ -119,6 +118,11 @@ public class InternalBrokerBaseCase extends QpidTestCase
_session.addChannel(_channel);
}
+ protected IApplicationRegistry createApplicationRegistry() throws ConfigurationException
+ {
+ return new TestApplicationRegistry(_configuration);
+ }
+
protected void configure()
{
// Allow other tests to override configuration
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 7aa5ed23fe..6e18718478 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
@@ -20,6 +20,8 @@
*/
package org.apache.qpid.server.util;
+import java.util.Collections;
+import java.util.Map;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.server.configuration.ServerConfiguration;
@@ -52,10 +54,10 @@ public class TestApplicationRegistry extends ApplicationRegistry
}
/**
- * @see org.apache.qpid.server.registry.ApplicationRegistry#createAuthenticationManager()
+ * @see org.apache.qpid.server.registry.ApplicationRegistry#createAuthenticationManagers()
*/
@Override
- protected AuthenticationManager createAuthenticationManager() throws ConfigurationException
+ protected Map<Integer, AuthenticationManager> createAuthenticationManagers() throws ConfigurationException
{
final Properties users = new Properties();
users.put("guest","guest");
@@ -86,7 +88,7 @@ public class TestApplicationRegistry extends ApplicationRegistry
pdam.initialise();
- return pdam;
+ return Collections.singletonMap(null,pdam);
}
}