diff options
| author | Robert Gemmell <robbie@apache.org> | 2010-05-31 16:03:41 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2010-05-31 16:03:41 +0000 |
| commit | 48e49bef0775e91625ba7b5c03823dbaca943bf7 (patch) | |
| tree | f987246a0d61c3a23e5c52b9a233778d57e3fca4 /java/broker/src/test | |
| parent | a2d26b71f141f3166bdd0342b481723d98b0bb99 (diff) | |
| download | qpid-python-48e49bef0775e91625ba7b5c03823dbaca943bf7.tar.gz | |
QPID-2606: Access Control Modifications
Applied patch from Andrew Kennedy <andrew.international@gmail.com>
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@949781 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker/src/test')
| -rw-r--r-- | java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java (renamed from java/broker/src/test/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBeanTest.java) | 10 | ||||
| -rw-r--r-- | java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java | 74 | ||||
| -rw-r--r-- | java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java | 4 | ||||
| -rw-r--r-- | java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java | 3 | ||||
| -rw-r--r-- | java/broker/src/test/java/org/apache/qpid/server/security/access/ACLManagerTest.java | 112 | ||||
| -rw-r--r-- | java/broker/src/test/java/org/apache/qpid/server/security/access/ExchangeDenier.java | 49 | ||||
| -rw-r--r-- | java/broker/src/test/java/org/apache/qpid/server/security/access/QueueDenier.java | 67 |
7 files changed, 81 insertions, 238 deletions
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBeanTest.java b/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java index fe35cfa3aa..8bced58b7b 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBeanTest.java +++ b/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java @@ -19,24 +19,20 @@ * */ -package org.apache.qpid.server.security.access.management; +package org.apache.qpid.server.management; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; +import junit.framework.TestCase; import org.apache.commons.configuration.ConfigurationException; -import org.apache.qpid.server.management.MBeanInvocationHandlerImpl; import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; - -import junit.framework.TestCase; +import org.apache.qpid.server.security.auth.management.AMQUserManagementMBean; /* Note: The main purpose is to test the jmx access rights file manipulation * within AMQUserManagementMBean. The Principal Databases are tested by their own tests, diff --git a/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java b/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java new file mode 100644 index 0000000000..325a4e6464 --- /dev/null +++ b/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java @@ -0,0 +1,74 @@ +/* + * 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 junit.framework.TestCase; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.exchange.ExchangeType; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.registry.IApplicationRegistry; +import org.apache.qpid.server.util.TestApplicationRegistry; + +import java.util.Map; + +public class PluginTest extends TestCase +{ + 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"); + + IApplicationRegistry _registry; + + @Override + public void setUp() throws Exception + { + PropertiesConfiguration properties = new PropertiesConfiguration(); + properties.addProperty("plugin-directory", PLUGIN_DIRECTORY); + properties.addProperty("cache-directory", CACHE_DIRECTORY); + ServerConfiguration config = new ServerConfiguration(properties); + + // This Test requries an application Registry + ApplicationRegistry.initialise(new TestApplicationRegistry(config)); + _registry = ApplicationRegistry.getInstance(); + } + + @Override + public void tearDown() throws Exception + { + ApplicationRegistry.remove(); + } + + public void disabled_testLoadExchanges() throws Exception + { + PluginManager manager = _registry.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"); + Map<String, ExchangeType<?>> exchanges = manager.getExchanges(); + assertTrue("Exchanges found", exchanges.isEmpty()); + } +} diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java index 3d3d8f93a8..393ffdeaac 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java +++ b/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java @@ -49,7 +49,7 @@ public class AMQQueueFactoryTest extends TestCase } - public void testPriorityQueueRegistration() + public void testPriorityQueueRegistration() throws Exception { FieldTable fieldTable = new FieldTable(); fieldTable.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 5); @@ -62,7 +62,7 @@ public class AMQQueueFactoryTest extends TestCase } - public void testSimpleQueueRegistration() + public void testSimpleQueueRegistration() throws Exception { AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue"), false, new AMQShortString("owner"), false, false, _virtualHost, null); diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java index fe45be3f0e..e1852a0a22 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java +++ b/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java @@ -25,6 +25,7 @@ import junit.framework.TestCase; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.qpid.AMQException; +import org.apache.qpid.AMQSecurityException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.BasicContentHeaderProperties; import org.apache.qpid.framing.ContentHeaderBody; @@ -144,7 +145,7 @@ public class SimpleAMQQueueTest extends TestCase assertEquals("Virtual host was wrong", _virtualHost, _queue.getVirtualHost()); } - public void testBinding() + public void testBinding() throws AMQSecurityException { _virtualHost.getBindingFactory().addBinding(String.valueOf(_routingKey), _queue, _exchange, Collections.EMPTY_MAP); diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/access/ACLManagerTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/access/ACLManagerTest.java deleted file mode 100644 index 44f9861e8d..0000000000 --- a/java/broker/src/test/java/org/apache/qpid/server/security/access/ACLManagerTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * - */ -package org.apache.qpid.server.security.access; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; - -import junit.framework.TestCase; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.commons.configuration.XMLConfiguration; -import org.apache.qpid.server.configuration.SecurityConfiguration; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.plugins.MockPluginManager; -import org.apache.qpid.server.plugins.PluginManager; -import org.apache.qpid.server.protocol.AMQProtocolSession; -import org.apache.qpid.server.protocol.InternalTestProtocolSession; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.queue.MockAMQQueue; -import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.server.registry.ApplicationRegistry; - -public class ACLManagerTest extends TestCase -{ - - private ACLManager _authzManager; - private AMQProtocolSession _session; - private SecurityConfiguration _conf; - private PluginManager _pluginManager; - - @Override - public void setUp() throws Exception - { - File tmpFile = File.createTempFile(getClass().getName(), "testconfig"); - tmpFile.deleteOnExit(); - BufferedWriter out = new BufferedWriter(new FileWriter(tmpFile)); - out.write("<security><queueDenier>notyet</queueDenier><exchangeDenier>yes</exchangeDenier></security>"); - out.close(); - - _conf = new SecurityConfiguration(new XMLConfiguration(tmpFile)); - - // Create ACLManager - - _pluginManager = new MockPluginManager(""); - _authzManager = new ACLManager(_conf, _pluginManager); - - - VirtualHost virtualHost = ApplicationRegistry.getInstance(). - getVirtualHostRegistry().getVirtualHosts().iterator().next(); - - // Create a single session for this test. - _session = new InternalTestProtocolSession(virtualHost); - } - - @Override - public void tearDown() throws Exception - { - // Correctly Close the AR we created - ApplicationRegistry.remove(); - super.tearDown(); - } - - public void testACLManagerConfigurationPluginManager() throws Exception - { - AMQQueue queue = new MockAMQQueue("notyet"); - AMQQueue otherQueue = new MockAMQQueue("other"); - - assertFalse(_authzManager.authoriseDelete(_session, queue)); - - // This should only be denied if the config hasn't been correctly passed in - assertTrue(_authzManager.authoriseDelete(_session, otherQueue)); - assertTrue(_authzManager.authorisePurge(_session, queue)); - } - - public void testACLManagerConfigurationPluginManagerACLPlugin() throws ConfigurationException - { - _authzManager = new ACLManager(_conf, _pluginManager, ExchangeDenier.FACTORY); - - Exchange exchange = null; - assertFalse(_authzManager.authoriseDelete(_session, exchange)); - } - - public void testConfigurePlugins() throws ConfigurationException - { - Configuration hostConfig = new PropertiesConfiguration(); - hostConfig.setProperty("queueDenier", "thisoneneither"); - _authzManager.configureHostPlugins(new SecurityConfiguration(hostConfig)); - AMQQueue queue = new MockAMQQueue("thisoneneither"); - assertFalse(_authzManager.authoriseDelete(_session, queue)); - } -} diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/access/ExchangeDenier.java b/java/broker/src/test/java/org/apache/qpid/server/security/access/ExchangeDenier.java deleted file mode 100644 index 37a0fd7fc3..0000000000 --- a/java/broker/src/test/java/org/apache/qpid/server/security/access/ExchangeDenier.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * - */ -package org.apache.qpid.server.security.access; - -import org.apache.commons.configuration.Configuration; -import org.apache.qpid.server.exchange.Exchange; -import org.apache.qpid.server.security.access.plugins.AllowAll; -import org.apache.qpid.server.security.PrincipalHolder; - -public class ExchangeDenier extends AllowAll -{ - - public static final ACLPluginFactory FACTORY = new ACLPluginFactory() - { - public boolean supportsTag(String name) - { - return name.startsWith("exchangeDenier"); - } - - public ACLPlugin newInstance(Configuration config) - { - return new ExchangeDenier(); - } - }; - - @Override - public AuthzResult authoriseDelete(PrincipalHolder session, Exchange exchange) - { - return AuthzResult.DENIED; - } -} diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/access/QueueDenier.java b/java/broker/src/test/java/org/apache/qpid/server/security/access/QueueDenier.java deleted file mode 100644 index 3f9c776aa2..0000000000 --- a/java/broker/src/test/java/org/apache/qpid/server/security/access/QueueDenier.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * - */ -package org.apache.qpid.server.security.access; - -import org.apache.commons.configuration.Configuration; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.security.access.plugins.AllowAll; -import org.apache.qpid.server.security.PrincipalHolder; - -public class QueueDenier extends AllowAll -{ - - public static final ACLPluginFactory FACTORY = new ACLPluginFactory() - { - public boolean supportsTag(String name) - { - return name.equals("queueDenier"); - } - - public ACLPlugin newInstance(Configuration config) - { - QueueDenier plugin = new QueueDenier(); - plugin.setConfiguration(config); - return plugin; - } - }; - - private String _queueName = ""; - - - @Override - public AuthzResult authoriseDelete(PrincipalHolder session, AMQQueue queue) - { - if (!(queue.getNameShortString().toString().equals(_queueName))) - { - return AuthzResult.ALLOWED; - } - else - { - return AuthzResult.DENIED; - } - } - - @Override - public void setConfiguration(Configuration config) - { - _queueName = config.getString("queueDenier"); - } -} |
