You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2015/03/12 15:13:29 UTC
svn commit: r1666200 [3/4] - in
/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java: ./
amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/
bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/
bdbstore/src/test/java/org/...
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/SecurityManagerTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/SecurityManagerTest.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/SecurityManagerTest.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/SecurityManagerTest.java Thu Mar 12 14:13:28 2015
@@ -32,16 +32,31 @@ import static org.mockito.Mockito.when;
import java.security.AccessControlException;
import java.util.Collections;
-import org.apache.qpid.server.binding.BindingImpl;
-import org.apache.qpid.server.consumer.ConsumerImpl;
-import org.apache.qpid.server.exchange.ExchangeImpl;
import org.apache.qpid.server.model.AccessControlProvider;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Binding;
import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.BrokerModel;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Consumer;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.ExclusivityPolicy;
+import org.apache.qpid.server.model.Group;
+import org.apache.qpid.server.model.GroupMember;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.Session;
import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.User;
import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.queue.QueueConsumer;
import org.apache.qpid.server.security.access.ObjectProperties;
import org.apache.qpid.server.security.access.ObjectProperties.Property;
import org.apache.qpid.server.security.access.ObjectType;
@@ -59,6 +74,8 @@ public class SecurityManagerTest extends
private AccessControl _accessControl;
private SecurityManager _securityManager;
private VirtualHost<?,?,?> _virtualHost;
+ private Broker _broker;
+ private VirtualHostNode<?> _virtualHostNode;
@Override
public void setUp() throws Exception
@@ -72,28 +89,38 @@ public class SecurityManagerTest extends
when(aclProvider.getState()).thenReturn(State.ACTIVE);
when(_virtualHost.getName()).thenReturn(TEST_VIRTUAL_HOST);
+ when(_virtualHost.getAttribute(VirtualHost.NAME)).thenReturn(TEST_VIRTUAL_HOST);
- Broker broker = mock(Broker.class);
- when(broker.getAccessControlProviders()).thenReturn(Collections.singleton(aclProvider));
- _securityManager = new SecurityManager(broker, false);
+ _broker = mock(Broker.class);
+ when(_broker.getAccessControlProviders()).thenReturn(Collections.singleton(aclProvider));
+ when(_broker.getChildren(AccessControlProvider.class)).thenReturn(Collections.singleton(aclProvider));
+ when(_broker.getCategoryClass()).thenReturn(Broker.class);
+ when(_broker.getName()).thenReturn("My Broker");
+ when(_broker.getAttribute(Broker.NAME)).thenReturn("My Broker");
+ when(_broker.getModel()).thenReturn(BrokerModel.getInstance());
+
+ _virtualHostNode = getMockVirtualHostNode();
+ _securityManager = new SecurityManager(_broker, false);
}
public void testAuthoriseCreateBinding()
{
- ExchangeImpl exchange = mock(ExchangeImpl.class);
+ VirtualHost vh = getMockVirtualHost();
+
+ Exchange exchange = mock(Exchange.class);
when(exchange.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(exchange.getName()).thenReturn(TEST_EXCHANGE);
+ when(exchange.getAttribute(Exchange.NAME)).thenReturn(TEST_EXCHANGE);
+ when(exchange.getCategoryClass()).thenReturn(Exchange.class);
+ when(exchange.getParent(VirtualHost.class)).thenReturn(vh);
+ when(exchange.getModel()).thenReturn(BrokerModel.getInstance());
- AMQQueue<?> queue = mock(AMQQueue.class);
+ Queue queue = mock(Queue.class);
when(queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(queue.getName()).thenReturn(TEST_QUEUE);
- when(queue.isDurable()).thenReturn(true);
- when(queue.getLifetimePolicy()).thenReturn(LifetimePolicy.PERMANENT);
-
- BindingImpl binding = mock(BindingImpl.class);
- when(binding.getExchange()).thenReturn(exchange);
- when(binding.getAMQQueue()).thenReturn(queue);
- when(binding.getBindingKey()).thenReturn("bindingKey");
+ when(queue.getAttribute(Queue.NAME)).thenReturn(TEST_QUEUE);
+ when(queue.getAttribute(Queue.DURABLE)).thenReturn(true);
+ when(queue.getAttribute(Queue.LIFETIME_POLICY)).thenReturn(LifetimePolicy.PERMANENT);
+ when(queue.getCategoryClass()).thenReturn(Queue.class);
+ when(queue.getParent(VirtualHost.class)).thenReturn(vh);
ObjectProperties properties = new ObjectProperties();
properties.put(Property.NAME, TEST_EXCHANGE);
@@ -103,22 +130,13 @@ public class SecurityManagerTest extends
properties.put(Property.TEMPORARY, false);
properties.put(Property.DURABLE, true);
+ Binding binding = mock(Binding.class);
+ when(binding.getParent(Exchange.class)).thenReturn(exchange);
+ when(binding.getParent(Queue.class)).thenReturn(queue);
+ when(binding.getAttribute(Binding.NAME)).thenReturn("bindingKey");
+ when(binding.getCategoryClass()).thenReturn(Binding.class);
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseCreateBinding(binding);
- verify(_accessControl).authorise(eq(Operation.BIND), eq(ObjectType.EXCHANGE), eq(properties));
-
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseCreateBinding(binding);
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.BIND), eq(ObjectType.EXCHANGE), eq(properties));
+ assertCreateAuthorization(binding, Operation.BIND, ObjectType.EXCHANGE, properties, exchange, queue);
}
@@ -192,14 +210,23 @@ public class SecurityManagerTest extends
public void testAuthoriseCreateConsumer()
{
- AMQQueue<?> queue = mock(AMQQueue.class);
+ Queue queue = mock(Queue.class);
when(queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(queue.getName()).thenReturn(TEST_QUEUE);
- when(queue.isDurable()).thenReturn(true);
- when(queue.getLifetimePolicy()).thenReturn(LifetimePolicy.PERMANENT);
-
- ConsumerImpl consumer = mock(ConsumerImpl.class);
- when(consumer.getMessageSource()).thenReturn(queue);
+ when(queue.getAttribute(Queue.NAME)).thenReturn(TEST_QUEUE);
+ when(queue.getAttribute(Queue.DURABLE)).thenReturn(true);
+ when(queue.getAttribute(Queue.LIFETIME_POLICY)).thenReturn(LifetimePolicy.PERMANENT);
+ when(queue.getAttribute(Queue.EXCLUSIVE)).thenReturn(ExclusivityPolicy.NONE);
+ when(queue.getCategoryClass()).thenReturn(Queue.class);
+
+ Session session = mock(Session.class);
+ when(session.getCategoryClass()).thenReturn(Session.class);
+ when(session.getAttribute(Session.NAME)).thenReturn("1");
+
+ QueueConsumer consumer = mock(QueueConsumer.class);
+ when(consumer.getAttribute(QueueConsumer.NAME)).thenReturn("1");
+ when(consumer.getParent(Queue.class)).thenReturn(queue);
+ when(consumer.getParent(Session.class)).thenReturn(session);
+ when(consumer.getCategoryClass()).thenReturn(Consumer.class);
ObjectProperties properties = new ObjectProperties();
properties.put(Property.NAME, TEST_QUEUE);
@@ -209,216 +236,128 @@ public class SecurityManagerTest extends
properties.put(Property.DURABLE, true);
properties.put(Property.EXCLUSIVE, false);
+ assertAuthorization(Operation.CREATE, consumer, Operation.CONSUME, ObjectType.QUEUE, properties, queue, session);
+ }
+
+ public void testAuthoriseUserOperation()
+ {
+ ObjectProperties properties = new ObjectProperties("testUser");
+
configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseCreateConsumer(consumer);
- verify(_accessControl).authorise(eq(Operation.CONSUME), eq(ObjectType.QUEUE), eq(properties));
+ _securityManager.authoriseUserUpdate("testUser");
+ verify(_accessControl).authorise(eq(Operation.UPDATE), eq(ObjectType.USER), eq(properties));
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseCreateConsumer(consumer);
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.CONSUME), eq(ObjectType.QUEUE), eq(properties));
+ configureAccessPlugin(Result.DENIED);
+ try
+ {
+ _securityManager.authoriseUserUpdate("testUser");
+ fail("AccessControlException is expected");
+ }
+ catch(AccessControlException e)
+ {
+ // pass
+ }
+ verify(_accessControl, times(2)).authorise(eq(Operation.UPDATE), eq(ObjectType.USER), eq(properties));
}
public void testAuthoriseCreateExchange()
{
- ExchangeImpl<?> exchange = mock(ExchangeImpl.class);
- when(exchange.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(exchange.getName()).thenReturn(TEST_EXCHANGE);
- when(exchange.getType()).thenReturn(TEST_EXCHANGE_TYPE);
+ VirtualHost vh = getMockVirtualHost();
+ ObjectProperties expectedProperties = createExpectedExchangeObjectProperties();
- ObjectProperties properties = createExpectedExchangeObjectProperties();
+ Exchange exchange = mock(Exchange.class);
+ when(exchange.getAttribute(ConfiguredObject.NAME)).thenReturn(TEST_EXCHANGE);
+ when(exchange.getAttribute(ConfiguredObject.LIFETIME_POLICY)).thenReturn(LifetimePolicy.DELETE_ON_CONNECTION_CLOSE);
+ when(exchange.getAttribute(Exchange.DURABLE)).thenReturn(false);
+ when(exchange.getAttribute(Exchange.TYPE)).thenReturn(TEST_EXCHANGE_TYPE);
+ when(exchange.getCategoryClass()).thenReturn(Exchange.class);
+ when(exchange.getParent(VirtualHost.class)).thenReturn(vh);
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseCreateExchange(exchange);
- verify(_accessControl).authorise(eq(Operation.CREATE), eq(ObjectType.EXCHANGE), eq(properties));
-
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseCreateExchange(exchange);
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.CREATE), eq(ObjectType.EXCHANGE), eq(properties));
+ assertCreateAuthorization( exchange, Operation.CREATE, ObjectType.EXCHANGE, expectedProperties, vh);
}
public void testAuthoriseCreateQueue()
{
- AMQQueue<?> queue = mock(AMQQueue.class);
- when(queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(queue.getName()).thenReturn(TEST_QUEUE);
+ VirtualHost vh = getMockVirtualHost();
+ ObjectProperties expectedProperties = createExpectedQueueObjectProperties();
- ObjectProperties properties = createExpectedQueueObjectProperties();
-
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseCreateQueue(queue);
- verify(_accessControl).authorise(eq(Operation.CREATE), eq(ObjectType.QUEUE), eq(properties));
+ Queue queue = mock(Queue.class);
+ when(queue.getAttribute(ConfiguredObject.NAME)).thenReturn(TEST_QUEUE);
+ when(queue.getAttribute(ConfiguredObject.LIFETIME_POLICY)).thenReturn(LifetimePolicy.DELETE_ON_CONNECTION_CLOSE);
+ when(queue.getAttribute(Queue.OWNER)).thenReturn(null);
+ when(queue.getAttribute(Queue.EXCLUSIVE)).thenReturn(ExclusivityPolicy.NONE);
+ when(queue.getAttribute(Queue.DURABLE)).thenReturn(false);
+ when(queue.getAttribute(Queue.ALTERNATE_EXCHANGE)).thenReturn(null);
+ when(queue.getCategoryClass()).thenReturn(Queue.class);
+ when(queue.getParent(VirtualHost.class)).thenReturn(vh);
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseCreateQueue(queue);
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.CREATE), eq(ObjectType.QUEUE), eq(properties));
+ assertCreateAuthorization(queue, Operation.CREATE, ObjectType.QUEUE, expectedProperties, vh);
}
public void testAuthoriseDeleteQueue()
{
- AMQQueue<?> queue = mock(AMQQueue.class);
- when(queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(queue.getName()).thenReturn(TEST_QUEUE);
+ VirtualHost vh = getMockVirtualHost();
+ ObjectProperties expectedProperties = createExpectedQueueObjectProperties();
- ObjectProperties properties = createExpectedQueueObjectProperties();
-
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseDelete(queue);
- verify(_accessControl).authorise(eq(Operation.DELETE), eq(ObjectType.QUEUE), eq(properties));
+ Queue queueObject = mock(Queue.class);
+ when(queueObject.getAttribute(Queue.NAME)).thenReturn(TEST_QUEUE);
+ when(queueObject.getAttribute(ConfiguredObject.LIFETIME_POLICY)).thenReturn(LifetimePolicy.DELETE_ON_CONNECTION_CLOSE);
+ when(queueObject.getAttribute(Queue.OWNER)).thenReturn(null);
+ when(queueObject.getAttribute(Queue.EXCLUSIVE)).thenReturn(ExclusivityPolicy.NONE);
+ when(queueObject.getAttribute(Queue.DURABLE)).thenReturn(false);
+ when(queueObject.getParent(VirtualHost.class)).thenReturn(vh);
+ when(queueObject.getCategoryClass()).thenReturn(Queue.class);
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseDelete(queue);
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.DELETE), eq(ObjectType.QUEUE), eq(properties));
+ assertDeleteAuthorization(queueObject, Operation.DELETE, ObjectType.QUEUE, expectedProperties, vh);
}
public void testAuthoriseUpdateQueue()
{
- AMQQueue<?> queue = mock(AMQQueue.class);
- when(queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(queue.getName()).thenReturn(TEST_QUEUE);
-
- ObjectProperties properties = createExpectedQueueObjectProperties();
+ VirtualHost vh = getMockVirtualHost();
+ ObjectProperties expectedProperties = createExpectedQueueObjectProperties();
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseUpdate(queue);
- verify(_accessControl).authorise(eq(Operation.UPDATE), eq(ObjectType.QUEUE), eq(properties));
+ Queue queueObject = mock(Queue.class);
+ when(queueObject.getAttribute(Queue.NAME)).thenReturn(TEST_QUEUE);
+ when(queueObject.getAttribute(ConfiguredObject.LIFETIME_POLICY)).thenReturn(LifetimePolicy.DELETE_ON_CONNECTION_CLOSE);
+ when(queueObject.getAttribute(Queue.OWNER)).thenReturn(null);
+ when(queueObject.getAttribute(Queue.EXCLUSIVE)).thenReturn(ExclusivityPolicy.NONE);
+ when(queueObject.getAttribute(Queue.DURABLE)).thenReturn(false);
+ when(queueObject.getParent(VirtualHost.class)).thenReturn(vh);
+ when(queueObject.getCategoryClass()).thenReturn(Queue.class);
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseUpdate(queue);
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.UPDATE), eq(ObjectType.QUEUE), eq(properties));
+ assertUpdateAuthorization(queueObject, Operation.UPDATE, ObjectType.QUEUE, expectedProperties, vh);
}
public void testAuthoriseUpdateExchange()
{
- ExchangeImpl<?> exchange = mock(ExchangeImpl.class);
- when(exchange.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(exchange.getName()).thenReturn(TEST_EXCHANGE);
- when(exchange.getType()).thenReturn(TEST_EXCHANGE_TYPE);
+ VirtualHost vh = getMockVirtualHost();
+ ObjectProperties expectedProperties = createExpectedExchangeObjectProperties();
- ObjectProperties properties = createExpectedExchangeObjectProperties();
+ Exchange exchange = mock(Exchange.class);
+ when(exchange.getAttribute(Exchange.NAME)).thenReturn(TEST_EXCHANGE);
+ when(exchange.getAttribute(Exchange.LIFETIME_POLICY)).thenReturn(LifetimePolicy.DELETE_ON_CONNECTION_CLOSE);
+ when(exchange.getAttribute(Exchange.DURABLE)).thenReturn(false);
+ when(exchange.getAttribute(Exchange.TYPE)).thenReturn(TEST_EXCHANGE_TYPE);
+ when(exchange.getParent(VirtualHost.class)).thenReturn(vh);
+ when(exchange.getCategoryClass()).thenReturn(Exchange.class);
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseUpdate(exchange);
- verify(_accessControl).authorise(eq(Operation.UPDATE), eq(ObjectType.EXCHANGE), eq(properties));
-
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseUpdate(exchange);
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.UPDATE), eq(ObjectType.EXCHANGE), eq(properties));
+ assertUpdateAuthorization(exchange, Operation.UPDATE, ObjectType.EXCHANGE, expectedProperties, vh);
}
public void testAuthoriseDeleteExchange()
{
- ExchangeImpl<?> exchange = mock(ExchangeImpl.class);
- when(exchange.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(exchange.getName()).thenReturn(TEST_EXCHANGE);
- when(exchange.getType()).thenReturn(TEST_EXCHANGE_TYPE);
-
- ObjectProperties properties = createExpectedExchangeObjectProperties();
-
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseDelete(exchange);
- verify(_accessControl).authorise(eq(Operation.DELETE), eq(ObjectType.EXCHANGE), eq(properties));
-
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseDelete(exchange);
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.DELETE), eq(ObjectType.EXCHANGE), eq(properties));
- }
-
- public void testAuthoriseGroupOperation()
- {
- ObjectProperties properties = new ObjectProperties("testGroup");
+ VirtualHost vh = getMockVirtualHost();
+ ObjectProperties expectedProperties = createExpectedExchangeObjectProperties();
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseGroupOperation(Operation.CREATE, "testGroup");
- verify(_accessControl).authorise(eq(Operation.CREATE), eq(ObjectType.GROUP), eq(properties));
+ Exchange exchange = mock(Exchange.class);
+ when(exchange.getAttribute(Exchange.NAME)).thenReturn(TEST_EXCHANGE);
+ when(exchange.getAttribute(Exchange.LIFETIME_POLICY)).thenReturn(LifetimePolicy.DELETE_ON_CONNECTION_CLOSE);
+ when(exchange.getAttribute(Exchange.DURABLE)).thenReturn(false);
+ when(exchange.getAttribute(Exchange.TYPE)).thenReturn(TEST_EXCHANGE_TYPE);
+ when(exchange.getParent(VirtualHost.class)).thenReturn(vh);
+ when(exchange.getCategoryClass()).thenReturn(Exchange.class);
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseGroupOperation(Operation.CREATE, "testGroup");
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.CREATE), eq(ObjectType.GROUP), eq(properties));
- }
-
- public void testAuthoriseUserOperation()
- {
- ObjectProperties properties = new ObjectProperties("testUser");
-
- configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseUserOperation(Operation.CREATE, "testUser");
- verify(_accessControl).authorise(eq(Operation.CREATE), eq(ObjectType.USER), eq(properties));
-
- configureAccessPlugin(Result.DENIED);
- try
- {
- _securityManager.authoriseUserOperation(Operation.CREATE, "testUser");
- fail("AccessControlException is expected");
- }
- catch(AccessControlException e)
- {
- // pass
- }
- verify(_accessControl, times(2)).authorise(eq(Operation.CREATE), eq(ObjectType.USER), eq(properties));
+ assertDeleteAuthorization(exchange, Operation.DELETE, ObjectType.EXCHANGE, expectedProperties, vh);
}
public void testAuthorisePublish()
@@ -447,9 +386,13 @@ public class SecurityManagerTest extends
public void testAuthorisePurge()
{
- AMQQueue<?> queue = mock(AMQQueue.class);
+ Queue queue = mock(Queue.class);
when(queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(queue.getName()).thenReturn(TEST_QUEUE);
+ when(queue.getAttribute(Queue.NAME)).thenReturn(TEST_QUEUE);
+ when(queue.getCategoryClass()).thenReturn(Queue.class);
+ when(queue.getAttribute(Queue.DURABLE)).thenReturn(false);
+ when(queue.getAttribute(Queue.EXCLUSIVE)).thenReturn(ExclusivityPolicy.NONE);
+ when(queue.getAttribute(Queue.LIFETIME_POLICY)).thenReturn(LifetimePolicy.DELETE_ON_CONNECTION_CLOSE);
ObjectProperties properties = createExpectedQueueObjectProperties();
@@ -470,23 +413,25 @@ public class SecurityManagerTest extends
verify(_accessControl, times(2)).authorise(eq(Operation.PURGE), eq(ObjectType.QUEUE), eq(properties));
}
-
public void testAuthoriseUnbind()
{
- ExchangeImpl exchange = mock(ExchangeImpl.class);
+ Exchange exchange = mock(Exchange.class);
when(exchange.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(exchange.getName()).thenReturn(TEST_EXCHANGE);
+ when(exchange.getAttribute(Exchange.NAME)).thenReturn(TEST_EXCHANGE);
+ when(exchange.getCategoryClass()).thenReturn(Exchange.class);
- AMQQueue<?> queue = mock(AMQQueue.class);
+ Queue queue = mock(Queue.class);
when(queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(queue.getName()).thenReturn(TEST_QUEUE);
- when(queue.isDurable()).thenReturn(true);
- when(queue.getLifetimePolicy()).thenReturn(LifetimePolicy.PERMANENT);
-
- BindingImpl binding = mock(BindingImpl.class);
- when(binding.getExchange()).thenReturn(exchange);
- when(binding.getAMQQueue()).thenReturn(queue);
- when(binding.getBindingKey()).thenReturn("bindingKey");
+ when(queue.getAttribute(Queue.NAME)).thenReturn(TEST_QUEUE);
+ when(queue.getAttribute(Queue.DURABLE)).thenReturn(true);
+ when(queue.getAttribute(Queue.LIFETIME_POLICY)).thenReturn(LifetimePolicy.PERMANENT);
+ when(queue.getCategoryClass()).thenReturn(Queue.class);
+
+ Binding binding = mock(Binding.class);
+ when(binding.getParent(Exchange.class)).thenReturn(exchange);
+ when(binding.getParent(Queue.class)).thenReturn(queue);
+ when(binding.getAttribute(Binding.NAME)).thenReturn("bindingKey");
+ when(binding.getCategoryClass()).thenReturn(Binding.class);
ObjectProperties properties = new ObjectProperties();
properties.put(Property.NAME, TEST_EXCHANGE);
@@ -496,35 +441,512 @@ public class SecurityManagerTest extends
properties.put(Property.TEMPORARY, false);
properties.put(Property.DURABLE, true);
+ assertDeleteAuthorization(binding, Operation.UNBIND, ObjectType.EXCHANGE, properties, exchange, queue);
+ }
+
+ public void testAuthoriseCreateVirtualHostNode()
+ {
+ VirtualHostNode vhn = getMockVirtualHostNode();
+ assertCreateAuthorization(vhn, Operation.CREATE, ObjectType.VIRTUALHOSTNODE, new ObjectProperties("testVHN"), _broker);
+ }
+
+ public void testAuthoriseCreatePort()
+ {
+ Port port = mock(Port.class);
+ when(port.getParent(Broker.class)).thenReturn(_broker);
+ when(port.getAttribute(ConfiguredObject.NAME)).thenReturn("TEST");
+ when(port.getCategoryClass()).thenReturn(Port.class);
+
+ assertBrokerChildCreateAuthorization(port);
+ }
+
+ public void testAuthoriseCreateAuthenticationProvider()
+ {
+ AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
+ when(authenticationProvider.getParent(Broker.class)).thenReturn(_broker);
+ when(authenticationProvider.getAttribute(ConfiguredObject.NAME)).thenReturn("TEST");
+ when(authenticationProvider.getCategoryClass()).thenReturn(AuthenticationProvider.class);
+ assertBrokerChildCreateAuthorization(authenticationProvider);
+ }
+
+ public void testAuthoriseCreateGroupProvider()
+ {
+ GroupProvider groupProvider = mock(GroupProvider.class);
+ when(groupProvider.getParent(Broker.class)).thenReturn(_broker);
+ when(groupProvider.getAttribute(ConfiguredObject.NAME)).thenReturn("TEST");
+ when(groupProvider.getCategoryClass()).thenReturn(GroupProvider.class);
+
+ assertBrokerChildCreateAuthorization(groupProvider);
+ }
+
+ public void testAuthoriseCreateAccessControlProvider()
+ {
+ AccessControlProvider accessControlProvider = mock(AccessControlProvider.class);
+ when(accessControlProvider.getParent(Broker.class)).thenReturn(_broker);
+ when(accessControlProvider.getAttribute(ConfiguredObject.NAME)).thenReturn("TEST");
+ when(accessControlProvider.getCategoryClass()).thenReturn(AccessControlProvider.class);
+
+ assertBrokerChildCreateAuthorization(accessControlProvider);
+ }
+
+ public void testAuthoriseCreateKeyStore()
+ {
+ KeyStore keyStore = mock(KeyStore.class);
+ when(keyStore.getParent(Broker.class)).thenReturn(_broker);
+ when(keyStore.getAttribute(ConfiguredObject.NAME)).thenReturn("TEST");
+ when(keyStore.getCategoryClass()).thenReturn(KeyStore.class);
+
+ assertBrokerChildCreateAuthorization(keyStore);
+ }
+
+ public void testAuthoriseCreateTrustStore()
+ {
+ TrustStore trustStore = mock(TrustStore.class);
+ when(trustStore.getParent(Broker.class)).thenReturn(_broker);
+ when(trustStore.getAttribute(ConfiguredObject.NAME)).thenReturn("TEST");
+ when(trustStore.getCategoryClass()).thenReturn(TrustStore.class);
+
+ assertBrokerChildCreateAuthorization(trustStore);
+ }
+
+ public void testAuthoriseCreateGroup()
+ {
+ GroupProvider groupProvider = mock(GroupProvider.class);
+ when(groupProvider.getCategoryClass()).thenReturn(GroupProvider.class);
+ when(groupProvider.getAttribute(GroupProvider.NAME)).thenReturn("testGroupProvider");
+ when(groupProvider.getModel()).thenReturn(BrokerModel.getInstance());
+
+ Group group = mock(Group.class);
+ when(group.getCategoryClass()).thenReturn(Group.class);
+ when(group.getParent(GroupProvider.class)).thenReturn(groupProvider);
+ when(group.getAttribute(Group.NAME)).thenReturn("test");
+
+ assertCreateAuthorization(group, Operation.CREATE, ObjectType.GROUP, new ObjectProperties("test"), groupProvider);
+ }
+
+ public void testAuthoriseCreateGroupMember()
+ {
+ Group group = mock(Group.class);
+ when(group.getCategoryClass()).thenReturn(Group.class);
+ when(group.getAttribute(Group.NAME)).thenReturn("testGroup");
+ when(group.getModel()).thenReturn(BrokerModel.getInstance());
+
+ GroupMember groupMember = mock(GroupMember.class);
+ when(groupMember.getCategoryClass()).thenReturn(GroupMember.class);
+ when(groupMember.getParent(Group.class)).thenReturn(group);
+ when(groupMember.getAttribute(Group.NAME)).thenReturn("test");
+
+ assertCreateAuthorization(groupMember, Operation.UPDATE, ObjectType.GROUP, new ObjectProperties("test"), group);
+ }
+
+ public void testAuthoriseCreateUser()
+ {
+ AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
+ when(authenticationProvider.getCategoryClass()).thenReturn(AuthenticationProvider.class);
+ when(authenticationProvider.getAttribute(AuthenticationProvider.NAME)).thenReturn("testAuthenticationProvider");
+ when(authenticationProvider.getModel()).thenReturn(BrokerModel.getInstance());
+
+ User user = mock(User.class);
+ when(user.getCategoryClass()).thenReturn(User.class);
+ when(user.getAttribute(User.NAME)).thenReturn("test");
+ when(user.getParent(AuthenticationProvider.class)).thenReturn(authenticationProvider);
+ when(user.getModel()).thenReturn(BrokerModel.getInstance());
+
+ assertCreateAuthorization(user, Operation.CREATE, ObjectType.USER, new ObjectProperties("test"), authenticationProvider);
+ }
+
+ public void testAuthoriseCreateVirtualHost()
+ {
+ VirtualHost vh = getMockVirtualHost();
+ assertCreateAuthorization(vh, Operation.CREATE, ObjectType.VIRTUALHOST, new ObjectProperties(TEST_VIRTUAL_HOST), _virtualHostNode);
+ }
+
+ public void testAuthoriseUpdateVirtualHostNode()
+ {
+ VirtualHostNode vhn = getMockVirtualHostNode();
+ assertUpdateAuthorization(vhn, Operation.UPDATE, ObjectType.VIRTUALHOSTNODE, new ObjectProperties(vhn.getName()), vhn);
+ }
+
+ public void testAuthoriseUpdatePort()
+ {
+ Port mock = mock(Port.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(Port.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildUpdateAuthorization(mock);
+ }
+
+ public void testAuthoriseUpdateAuthenticationProvider()
+ {
+ AuthenticationProvider mock = mock(AuthenticationProvider.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(AuthenticationProvider.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildUpdateAuthorization(mock);
+ }
+
+ public void testAuthoriseUpdateGroupProvider()
+ {
+ GroupProvider mock = mock(GroupProvider.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(GroupProvider.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildUpdateAuthorization(mock);
+ }
+
+ public void testAuthoriseUpdateAccessControlProvider()
+ {
+ AccessControlProvider mock = mock(AccessControlProvider.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(AccessControlProvider.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildUpdateAuthorization(mock);
+ }
+
+ public void testAuthoriseUpdateKeyStore()
+ {
+ KeyStore mock = mock(KeyStore.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(KeyStore.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildUpdateAuthorization(mock);
+ }
+
+ public void testAuthoriseUpdateTrustStore()
+ {
+ TrustStore mock = mock(TrustStore.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(TrustStore.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildUpdateAuthorization(mock);
+ }
+
+ public void testAuthoriseUpdateGroup()
+ {
+ GroupProvider groupProvider = mock(GroupProvider.class);
+ when(groupProvider.getCategoryClass()).thenReturn(GroupProvider.class);
+ when(groupProvider.getName()).thenReturn("testGroupProvider");
+ Group mock = mock(Group.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(Group.class);
+ when(mock.getParent(GroupProvider.class)).thenReturn(groupProvider);
+ ObjectProperties properties = new ObjectProperties((String)mock.getAttribute(ConfiguredObject.NAME));
+ assertUpdateAuthorization(mock, Operation.UPDATE, ObjectType.GROUP, properties, groupProvider);
+ }
+
+ public void testAuthoriseUpdateGroupMember()
+ {
+ Group group = mock(Group.class);
+ when(group.getCategoryClass()).thenReturn(Group.class);
+ when(group.getName()).thenReturn("testGroup");
+ GroupMember mock = mock(GroupMember.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(GroupMember.class);
+ when(mock.getParent(Group.class)).thenReturn(group);
+ ObjectProperties properties = new ObjectProperties((String)mock.getAttribute(ConfiguredObject.NAME));
+ assertUpdateAuthorization(mock, Operation.UPDATE, ObjectType.GROUP, properties, group);
+ }
+
+ public void testAuthoriseUpdateUser()
+ {
+ AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
+ when(authenticationProvider.getCategoryClass()).thenReturn(AuthenticationProvider.class);
+ when(authenticationProvider.getName()).thenReturn("testAuthenticationProvider");
+ User mock = mock(User.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(User.class);
+ when(mock.getParent(AuthenticationProvider.class)).thenReturn(authenticationProvider);
+ ObjectProperties properties = new ObjectProperties((String)mock.getAttribute(ConfiguredObject.NAME));
+ assertUpdateAuthorization(mock, Operation.UPDATE, ObjectType.USER, properties, authenticationProvider);
+ }
+
+ public void testAuthoriseUpdateVirtualHost()
+ {
+ VirtualHostNode vhn = getMockVirtualHostNode();
+
+ VirtualHost mock = mock(VirtualHost.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(VirtualHost.class);
+ when(mock.getParent(VirtualHostNode.class)).thenReturn(vhn);
+ ObjectProperties properties = new ObjectProperties((String)mock.getAttribute(ConfiguredObject.NAME));
+ assertUpdateAuthorization(mock, Operation.UPDATE, ObjectType.VIRTUALHOST, properties, vhn);
+ }
+
+ public void testAuthoriseDeleteVirtualHostNode()
+ {
+ VirtualHostNode vhn = getMockVirtualHostNode();
+ assertDeleteAuthorization(vhn, Operation.DELETE, ObjectType.VIRTUALHOSTNODE, new ObjectProperties(vhn.getName()), vhn);
+ }
+
+ public void testAuthoriseDeletePort()
+ {
+ Port mock = mock(Port.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(Port.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildDeleteAuthorization(mock);
+ }
+
+ public void testAuthoriseDeleteAuthenticationProvider()
+ {
+ AuthenticationProvider mock = mock(AuthenticationProvider.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(AuthenticationProvider.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildDeleteAuthorization(mock);
+ }
+
+ public void testAuthoriseDeleteGroupProvider()
+ {
+ GroupProvider mock = mock(GroupProvider.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(GroupProvider.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildDeleteAuthorization(mock);
+ }
+
+ public void testAuthoriseDeleteAccessControlProvider()
+ {
+ AccessControlProvider mock = mock(AccessControlProvider.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(AccessControlProvider.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildDeleteAuthorization(mock);
+ }
+
+ public void testAuthoriseDeleteKeyStore()
+ {
+ KeyStore mock = mock(KeyStore.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(KeyStore.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildDeleteAuthorization(mock);
+ }
+
+ public void testAuthoriseDeleteTrustStore()
+ {
+ TrustStore mock = mock(TrustStore.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(TrustStore.class);
+ when(mock.getParent(Broker.class)).thenReturn(_broker);
+ assertBrokerChildDeleteAuthorization(mock);
+ }
+
+ public void testAuthoriseDeleteGroup()
+ {
+ GroupProvider groupProvider = mock(GroupProvider.class);
+ when(groupProvider.getCategoryClass()).thenReturn(GroupProvider.class);
+ when(groupProvider.getName()).thenReturn("testGroupProvider");
+ Group mock = mock(Group.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(Group.class);
+ when(mock.getParent(GroupProvider.class)).thenReturn(groupProvider);
+ ObjectProperties properties = new ObjectProperties((String)mock.getAttribute(ConfiguredObject.NAME));
+ assertDeleteAuthorization(mock, Operation.DELETE, ObjectType.GROUP, properties, groupProvider);
+ }
+
+ public void testAuthoriseDeleteGroupMember()
+ {
+ Group group = mock(Group.class);
+ when(group.getCategoryClass()).thenReturn(Group.class);
+ when(group.getName()).thenReturn("testGroup");
+ GroupMember mock = mock(GroupMember.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(GroupMember.class);
+ when(mock.getParent(Group.class)).thenReturn(group);
+ ObjectProperties properties = new ObjectProperties((String)mock.getAttribute(ConfiguredObject.NAME));
+ assertDeleteAuthorization(mock, Operation.UPDATE, ObjectType.GROUP, properties, group);
+ }
+
+ public void testAuthoriseDeleteUser()
+ {
+ AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
+ when(authenticationProvider.getCategoryClass()).thenReturn(AuthenticationProvider.class);
+ when(authenticationProvider.getName()).thenReturn("testAuthenticationProvider");
+ User mock = mock(User.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(User.class);
+ when(mock.getParent(AuthenticationProvider.class)).thenReturn(authenticationProvider);
+ ObjectProperties properties = new ObjectProperties((String)mock.getAttribute(ConfiguredObject.NAME));
+ assertDeleteAuthorization(mock, Operation.DELETE, ObjectType.USER, properties, authenticationProvider);
+ }
+
+ public void testAuthoriseDeleteVirtualHost()
+ {
+ VirtualHostNode vhn = getMockVirtualHostNode();
+
+ VirtualHost mock = mock(VirtualHost.class);
+ when(mock.getAttribute(ConfiguredObject.NAME)).thenReturn("test");
+ when(mock.getCategoryClass()).thenReturn(VirtualHost.class);
+ when(mock.getParent(VirtualHostNode.class)).thenReturn(vhn);
+ ObjectProperties properties = new ObjectProperties((String)mock.getAttribute(ConfiguredObject.NAME));
+ assertDeleteAuthorization(mock, Operation.DELETE, ObjectType.VIRTUALHOST, properties, vhn);
+ }
+
+ public void testAuthoriseDeleteBinding()
+ {
+ Exchange exchange = mock(Exchange.class);
+ when(exchange.getParent(VirtualHost.class)).thenReturn(_virtualHost);
+ when(exchange.getAttribute(Exchange.NAME)).thenReturn(TEST_EXCHANGE);
+ when(exchange.getCategoryClass()).thenReturn(Exchange.class);
+
+ Queue queue = mock(Queue.class);
+ when(queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
+ when(queue.getAttribute(Queue.NAME)).thenReturn(TEST_QUEUE);
+ when(queue.getAttribute(Queue.DURABLE)).thenReturn(true);
+ when(queue.getAttribute(Queue.LIFETIME_POLICY)).thenReturn(LifetimePolicy.PERMANENT);
+ when(queue.getCategoryClass()).thenReturn(Queue.class);
+
+ Binding binding = mock(Binding.class);
+ when(binding.getParent(Exchange.class)).thenReturn(exchange);
+ when(binding.getParent(Queue.class)).thenReturn(queue);
+ when(binding.getAttribute(Binding.NAME)).thenReturn("bindingKey");
+ when(binding.getCategoryClass()).thenReturn(Binding.class);
+
+ ObjectProperties properties = new ObjectProperties();
+ properties.put(Property.NAME, TEST_EXCHANGE);
+ properties.put(Property.VIRTUALHOST_NAME, TEST_VIRTUAL_HOST);
+ properties.put(Property.QUEUE_NAME, TEST_QUEUE);
+ properties.put(Property.ROUTING_KEY, "bindingKey");
+ properties.put(Property.TEMPORARY, false);
+ properties.put(Property.DURABLE, true);
+
+ assertDeleteAuthorization(binding, Operation.UNBIND, ObjectType.EXCHANGE, properties, exchange, queue);
+ }
+
+ private VirtualHost getMockVirtualHost()
+ {
+ VirtualHost vh = mock(VirtualHost.class);
+ when(vh.getCategoryClass()).thenReturn(VirtualHost.class);
+ when(vh.getName()).thenReturn(TEST_VIRTUAL_HOST);
+ when(vh.getAttribute(VirtualHost.NAME)).thenReturn(TEST_VIRTUAL_HOST);
+ when(vh.getParent(VirtualHostNode.class)).thenReturn(_virtualHostNode);
+ when(vh.getModel()).thenReturn(BrokerModel.getInstance());
+ return vh;
+ }
+
+ private VirtualHostNode getMockVirtualHostNode()
+ {
+ VirtualHostNode vhn = mock(VirtualHostNode.class);
+ when(vhn.getCategoryClass()).thenReturn(VirtualHostNode.class);
+ when(vhn.getName()).thenReturn("testVHN");
+ when(vhn.getAttribute(ConfiguredObject.NAME)).thenReturn("testVHN");
+ when(vhn.getParent(Broker.class)).thenReturn(_broker);
+ when(vhn.getModel()).thenReturn(BrokerModel.getInstance());
+ return vhn;
+ }
+
+ private void assertBrokerChildCreateAuthorization(ConfiguredObject object)
+ {
+ String description = String.format("%s %s '%s'",
+ Operation.CREATE.name().toLowerCase(),
+ object.getCategoryClass().getSimpleName().toLowerCase(),
+ "TEST");
+ ObjectProperties properties = new OperationLoggingDetails(description);
+ assertCreateAuthorization(object, Operation.CONFIGURE, ObjectType.BROKER, properties, _broker );
+ }
+
+ private void assertBrokerChildUpdateAuthorization(ConfiguredObject configuredObject)
+ {
+ String description = String.format("%s %s '%s'",
+ Operation.UPDATE.name().toLowerCase(),
+ configuredObject.getCategoryClass().getSimpleName().toLowerCase(),
+ configuredObject.getAttribute(ConfiguredObject.NAME));
+ ObjectProperties properties = new OperationLoggingDetails(description);
+
+ assertUpdateAuthorization(configuredObject, Operation.CONFIGURE, ObjectType.BROKER,
+ properties, _broker );
+ }
+
+ private void assertBrokerChildDeleteAuthorization(ConfiguredObject configuredObject)
+ {
+ String description = String.format("%s %s '%s'",
+ Operation.DELETE.name().toLowerCase(),
+ configuredObject.getCategoryClass().getSimpleName().toLowerCase(),
+ configuredObject.getAttribute(ConfiguredObject.NAME));
+ ObjectProperties properties = new OperationLoggingDetails(description);
+
+ assertDeleteAuthorization(configuredObject, Operation.CONFIGURE, ObjectType.BROKER,
+ properties, _broker );
+ }
+
+ private void assertAuthorization(Operation operation, ConfiguredObject<?> configuredObject, Operation aclOperation, ObjectType aclObjectType, ObjectProperties expectedProperties, ConfiguredObject... objects)
+ {
configureAccessPlugin(Result.ALLOWED);
- _securityManager.authoriseUnbind(binding);
- verify(_accessControl).authorise(eq(Operation.UNBIND), eq(ObjectType.EXCHANGE), eq(properties));
+ _securityManager.authorise(operation, configuredObject);
+ verify(_accessControl).authorise(eq(aclOperation), eq(aclObjectType), eq(expectedProperties));
configureAccessPlugin(Result.DENIED);
try
{
- _securityManager.authoriseUnbind(binding);
+ _securityManager.authorise(operation, configuredObject);
fail("AccessControlException is expected");
}
catch(AccessControlException e)
{
- // pass
+ String expectedMessage = "Permission " + aclOperation.name() + " "
+ + aclObjectType.name() +" is denied for : " + operation.name() + " "
+ + configuredObject.getCategoryClass().getSimpleName() + " '"
+ + configuredObject.getAttribute(ConfiguredObject.NAME) + "' on";
+
+ assertTrue("Unexpected exception message: " + e.getMessage() + " vs " + expectedMessage,
+ e.getMessage().startsWith(expectedMessage));
+ for (ConfiguredObject object: objects)
+ {
+ String parentInfo = object.getCategoryClass().getSimpleName() + " '"
+ + object.getAttribute(ConfiguredObject.NAME) + "'";
+ assertTrue("Exception message does not contain information about parent object "
+ + object.getCategoryClass() + " " + object.getAttribute(ConfiguredObject.NAME) + ":"
+ + e.getMessage(),
+ e.getMessage().contains(parentInfo));
+ }
}
- verify(_accessControl, times(2)).authorise(eq(Operation.UNBIND), eq(ObjectType.EXCHANGE), eq(properties));
+
+ verify(_accessControl, times(2)).authorise(eq(aclOperation), eq(aclObjectType), eq(expectedProperties));
+ }
+
+ private void assertDeleteAuthorization(ConfiguredObject<?> configuredObject, Operation aclOperation, ObjectType aclObjectType, ObjectProperties expectedProperties, ConfiguredObject... objects)
+ {
+ assertAuthorization(Operation.DELETE, configuredObject, aclOperation, aclObjectType, expectedProperties, objects);
}
- public void testAuthoriseConfiguringBroker()
+ private void assertUpdateAuthorization(ConfiguredObject<?> configuredObject, Operation aclOperation, ObjectType aclObjectType, ObjectProperties expectedProperties, ConfiguredObject... objects)
{
- OperationLoggingDetails properties = new OperationLoggingDetails("create virtualhost 'test'");
+ assertAuthorization(Operation.UPDATE, configuredObject, aclOperation, aclObjectType, expectedProperties, objects);
+ }
+ private void assertCreateAuthorization(ConfiguredObject<?> configuredObject, Operation aclOperation, ObjectType aclObjectType, ObjectProperties expectedProperties, ConfiguredObject<?>... parents)
+ {
configureAccessPlugin(Result.ALLOWED);
- assertTrue(_securityManager.authoriseConfiguringBroker("test", VirtualHost.class, Operation.CREATE));
- verify(_accessControl).authorise(eq(Operation.CONFIGURE), eq(ObjectType.BROKER), eq(properties));
+ _securityManager.authorise(Operation.CREATE, configuredObject);
+ verify(_accessControl).authorise(eq(aclOperation), eq(aclObjectType), eq(expectedProperties));
configureAccessPlugin(Result.DENIED);
- assertFalse(_securityManager.authoriseConfiguringBroker("test", VirtualHost.class, Operation.CREATE));
- verify(_accessControl, times(2)).authorise(eq(Operation.CONFIGURE), eq(ObjectType.BROKER), eq(properties));
+ try
+ {
+ _securityManager.authorise(Operation.CREATE, configuredObject);
+ fail("AccessControlException is expected");
+ }
+ catch(AccessControlException e)
+ {
+ String expectedMessage = "Permission " + aclOperation.name() + " "
+ + aclObjectType.name() +" is denied for : CREATE " + configuredObject.getCategoryClass().getSimpleName() + " '"
+ + configuredObject.getAttribute(ConfiguredObject.NAME) + "' on";
+
+ assertTrue("Unexpected exception message", e.getMessage().startsWith(expectedMessage));
+ for (ConfiguredObject object: parents)
+ {
+ String parentInfo = object.getCategoryClass().getSimpleName() + " '"
+ + object.getAttribute(ConfiguredObject.NAME) + "'";
+ assertTrue("Exception message does not contain information about parent configuredObject "
+ + parentInfo + ": "
+ + e.getMessage(),
+ e.getMessage().contains(parentInfo));
+ }
+ }
+
+ verify(_accessControl, times(2)).authorise(eq(aclOperation), eq(aclObjectType), eq(expectedProperties));
}
public void testAuthoriseLogsAccess()
@@ -548,7 +970,7 @@ public class SecurityManagerTest extends
ObjectProperties properties = new ObjectProperties();
properties.put(Property.NAME, TEST_EXCHANGE);
properties.put(Property.VIRTUALHOST_NAME, TEST_VIRTUAL_HOST);
- properties.put(Property.AUTO_DELETE, false);
+ properties.put(Property.AUTO_DELETE, true);
properties.put(Property.TEMPORARY, true);
properties.put(Property.DURABLE, false);
properties.put(Property.TYPE, TEST_EXCHANGE_TYPE);
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java Thu Mar 12 14:13:28 2015
@@ -196,7 +196,10 @@ public class BrokerTestHelper
public static ExchangeImpl<?> createExchange(String hostName, final boolean durable, final EventLogger eventLogger) throws Exception
{
- SecurityManager securityManager = new SecurityManager(mock(Broker.class), false);
+ Broker broker = mock(Broker.class);
+ when(broker.getModel()).thenReturn(BrokerModel.getInstance());
+ when(broker.getCategoryClass()).thenReturn(Broker.class);
+ SecurityManager securityManager = new SecurityManager(broker, false);
final VirtualHostImpl<?,?,?> virtualHost = mock(VirtualHostImpl.class);
when(virtualHost.getName()).thenReturn(hostName);
when(virtualHost.getSecurityManager()).thenReturn(securityManager);
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/AbstractVirtualHostTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/AbstractVirtualHostTest.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/AbstractVirtualHostTest.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/AbstractVirtualHostTest.java Thu Mar 12 14:13:28 2015
@@ -50,7 +50,7 @@ import org.apache.qpid.test.utils.QpidTe
public class AbstractVirtualHostTest extends QpidTestCase
{
private TaskExecutor _taskExecutor;
- private VirtualHostNode<?> _node;
+ private VirtualHostNode _node;
private MessageStore _failingStore;
@Override
@@ -73,6 +73,7 @@ public class AbstractVirtualHostTest ext
when(_node.getModel()).thenReturn(BrokerModel.getInstance());
when(_node.getTaskExecutor()).thenReturn(_taskExecutor);
when(_node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
+ when(_node.getCategoryClass()).thenReturn(VirtualHostNode.class);
_failingStore = mock(MessageStore.class);
doThrow(new RuntimeException("Cannot open store")).when(_failingStore).openMessageStore(any(ConfiguredObject.class));
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostQueueCreationTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostQueueCreationTest.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostQueueCreationTest.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostQueueCreationTest.java Thu Mar 12 14:13:28 2015
@@ -68,7 +68,6 @@ public class VirtualHostQueueCreationTes
EventLogger eventLogger = mock(EventLogger.class);
SecurityManager securityManager = mock(SecurityManager.class);
- when(securityManager.authoriseConfiguringBroker(anyString(),any(Class.class),any(Operation.class))).thenReturn(true);
ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
_taskExecutor = new CurrentThreadTaskExecutor();
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java Thu Mar 12 14:13:28 2015
@@ -52,7 +52,6 @@ import org.apache.qpid.server.model.Syst
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.store.ConfiguredObjectRecord;
import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.store.NullMessageStore;
@@ -278,9 +277,7 @@ public class AbstractStandardVirtualHost
node.open();
node.start();
- doThrow(new AccessControlException("mocked ACL exception")).when(_mockSecurityManager).authoriseVirtualHostNode(
- TEST_VIRTUAL_HOST_NODE_NAME,
- Operation.UPDATE);
+ doThrow(new AccessControlException("mocked ACL exception")).when(_mockSecurityManager).authoriseUpdate(node);
assertNull(node.getDescription());
try
@@ -310,9 +307,7 @@ public class AbstractStandardVirtualHost
node.open();
node.start();
- doThrow(new AccessControlException("mocked ACL exception")).when(mockSecurityManager).authoriseVirtualHostNode(
- TEST_VIRTUAL_HOST_NODE_NAME,
- Operation.DELETE);
+ doThrow(new AccessControlException("mocked ACL exception")).when(mockSecurityManager).authoriseDelete(node);
try
{
@@ -342,9 +337,7 @@ public class AbstractStandardVirtualHost
node.open();
node.start();
- doThrow(new AccessControlException("mocked ACL exception")).when(mockSecurityManager).authoriseVirtualHostNode(
- TEST_VIRTUAL_HOST_NODE_NAME,
- Operation.UPDATE);
+ doThrow(new AccessControlException("mocked ACL exception")).when(mockSecurityManager).authoriseUpdate(node);
try
{
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java Thu Mar 12 14:13:28 2015
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.server.security.access.plugins;
-import java.security.AccessControlException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -33,7 +32,6 @@ import org.apache.log4j.Logger;
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.model.AbstractConfiguredObject;
-import org.apache.qpid.server.model.AccessControlProvider;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ManagedAttributeField;
@@ -41,7 +39,6 @@ import org.apache.qpid.server.model.Mana
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.StateTransition;
import org.apache.qpid.server.security.AccessControl;
-import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.util.urlstreamhandler.data.Handler;
public class ACLFileAccessControlProviderImpl
@@ -229,27 +226,6 @@ public class ACLFileAccessControlProvide
return returnVal;
}
- @Override
- protected void authoriseSetDesiredState(State desiredState) throws AccessControlException
- {
- if(desiredState == State.DELETED)
- {
- if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AccessControlProvider.class, Operation.DELETE))
- {
- throw new AccessControlException("Deletion of AccessControlProvider is denied");
- }
- }
- }
-
- @Override
- protected void authoriseSetAttributes(ConfiguredObject<?> modified, Set<String> attributes) throws AccessControlException
- {
- if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AccessControlProvider.class, Operation.UPDATE))
- {
- throw new AccessControlException("Setting of AccessControlProvider attributes is denied");
- }
- }
-
public AccessControl getAccessControl()
{
return _accessControl;
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java Thu Mar 12 14:13:28 2015
@@ -22,14 +22,10 @@
package org.apache.qpid.server.security.access.plugins;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import javax.security.auth.Subject;
-import org.apache.qpid.server.exchange.ExchangeImpl;
import org.apache.qpid.server.logging.EventLoggerProvider;
-import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.security.Result;
import org.apache.qpid.server.security.access.ObjectProperties;
import org.apache.qpid.server.security.access.ObjectType;
@@ -65,8 +61,6 @@ public class RuleSetTest extends QpidTes
private String _exchangeName = "amq.direct";
private String _exchangeType = "direct";
private Subject _testSubject = TestPrincipalUtils.createTestSubject(TEST_USER);
- private AMQQueue<?> _queue;
- private VirtualHost<?,?,?> _virtualHost;
@Override
public void setUp() throws Exception
@@ -74,11 +68,6 @@ public class RuleSetTest extends QpidTes
super.setUp();
_ruleSet = new RuleSet(mock(EventLoggerProvider.class));
-
- _virtualHost = mock(VirtualHost.class);
- _queue = mock(AMQQueue.class);
- when(_queue.getName()).thenReturn(_queueName);
- when(_queue.getParent(VirtualHost.class)).thenReturn(_virtualHost);
}
@Override
@@ -178,11 +167,13 @@ public class RuleSetTest extends QpidTes
{
_ruleSet.grant(0, TEST_USER, Permission.ALLOW, Operation.CREATE, ObjectType.QUEUE, new ObjectProperties(Property.VIRTUALHOST_NAME, ALLOWED_VH));
- when(_virtualHost.getName()).thenReturn(ALLOWED_VH);
- assertEquals(Result.ALLOWED, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.QUEUE, new ObjectProperties(_queue)));
-
- when(_virtualHost.getName()).thenReturn(DENIED_VH);
- assertEquals(Result.DEFER, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.QUEUE, new ObjectProperties(_queue)));
+ ObjectProperties allowedQueueObjectProperties = new ObjectProperties(_queueName);
+ allowedQueueObjectProperties.put(Property.VIRTUALHOST_NAME, ALLOWED_VH);
+ assertEquals(Result.ALLOWED, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.QUEUE, new ObjectProperties(allowedQueueObjectProperties)));
+
+ ObjectProperties deniedQueueObjectProperties = new ObjectProperties(_queueName);
+ deniedQueueObjectProperties.put(Property.VIRTUALHOST_NAME, DENIED_VH);
+ assertEquals(Result.DEFER, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.QUEUE, deniedQueueObjectProperties));
}
public void testQueueCreateNamedNullRoutingKey()
@@ -197,15 +188,16 @@ public class RuleSetTest extends QpidTes
{
_ruleSet.grant(0, TEST_USER, Permission.ALLOW, Operation.CREATE, ObjectType.EXCHANGE, new ObjectProperties(Property.VIRTUALHOST_NAME, ALLOWED_VH));
- ExchangeImpl<?> exchange = mock(ExchangeImpl.class);
- when(exchange.getParent(VirtualHost.class)).thenReturn(_virtualHost);
- when(exchange.getType()).thenReturn(_exchangeType);
- when(_virtualHost.getName()).thenReturn(ALLOWED_VH);
-
- assertEquals(Result.ALLOWED, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.EXCHANGE, new ObjectProperties(exchange)));
-
- when(_virtualHost.getName()).thenReturn(DENIED_VH);
- assertEquals(Result.DEFER, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.EXCHANGE, new ObjectProperties(exchange)));
+ ObjectProperties allowedExchangeProperties = new ObjectProperties(_exchangeName);
+ allowedExchangeProperties.put(Property.TYPE, _exchangeType);
+ allowedExchangeProperties.put(Property.VIRTUALHOST_NAME, ALLOWED_VH);
+
+ assertEquals(Result.ALLOWED, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.EXCHANGE, allowedExchangeProperties));
+
+ ObjectProperties deniedExchangeProperties = new ObjectProperties(_exchangeName);
+ deniedExchangeProperties.put(Property.TYPE, _exchangeType);
+ deniedExchangeProperties.put(Property.VIRTUALHOST_NAME, DENIED_VH);
+ assertEquals(Result.DEFER, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.EXCHANGE, deniedExchangeProperties));
}
public void testExchangeCreate()
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ProtocolEngine_0_10.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ProtocolEngine_0_10.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ProtocolEngine_0_10.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ProtocolEngine_0_10.java Thu Mar 12 14:13:28 2015
@@ -70,7 +70,7 @@ public class ProtocolEngine_0_10 extend
public ProtocolEngine_0_10(ServerConnection conn,
NetworkConnection network)
{
- super(new Assembler(conn));
+ super(new ServerAssembler(conn));
_connection = conn;
if(network != null)
Added: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerAssembler.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerAssembler.java?rev=1666200&view=auto
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerAssembler.java (added)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerAssembler.java Thu Mar 12 14:13:28 2015
@@ -0,0 +1,57 @@
+/*
+ *
+ * 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.protocol.v0_10;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.qpid.transport.network.Assembler;
+import org.apache.qpid.transport.network.NetworkEvent;
+
+public class ServerAssembler extends Assembler
+{
+ private static final Logger LOGGER = LoggerFactory.getLogger(ServerAssembler.class);
+
+
+ private final ServerConnection _connection;
+
+ public ServerAssembler(final ServerConnection connection)
+ {
+ super(connection);
+ _connection = connection;
+ }
+
+ @Override
+ public void received(final NetworkEvent event)
+ {
+ if (!_connection.isIgnoreFutureInput())
+ {
+ super.received(event);
+ }
+ else
+ {
+ LOGGER.debug("Ignored network event " + event + " as connection is ignoring further input ");
+ }
+ }
+
+
+}
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnection.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnection.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnection.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnection.java Thu Mar 12 14:13:28 2015
@@ -97,6 +97,7 @@ public class ServerConnection extends Co
private final int _maxMessageSize;
private ServerProtocolEngine _serverProtocolEngine;
+ private boolean _ignoreFutureInput;
public ServerConnection(final long connectionId,
Broker<?> broker,
@@ -734,4 +735,15 @@ public class ServerConnection extends Co
}
}
+
+ public void closeAndIgnoreFutureInput()
+ {
+ _ignoreFutureInput = true;
+ getSender().close();
+ }
+
+ public boolean isIgnoreFutureInput()
+ {
+ return _ignoreFutureInput;
+ }
}
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java Thu Mar 12 14:13:28 2015
@@ -250,7 +250,7 @@ public class ServerConnectionDelegate ex
") above the server's offered limit (" + getChannelMax() +")");
//Due to the error we must forcefully close the connection without negotiation
- sconn.getSender().close();
+ sconn.closeAndIgnoreFutureInput();
return;
}
@@ -261,7 +261,8 @@ public class ServerConnectionDelegate ex
") above the server's offered limit (" + getFrameMax() +")");
//Due to the error we must forcefully close the connection without negotiation
- sconn.getSender().close();
+ sconn.closeAndIgnoreFutureInput();
+
return;
}
else if(okMaxFrameSize > 0 && okMaxFrameSize < Constant.MIN_MAX_FRAME_SIZE)
@@ -271,7 +272,7 @@ public class ServerConnectionDelegate ex
") below the minimum permitted size (" + Constant.MIN_MAX_FRAME_SIZE +")");
//Due to the error we must forcefully close the connection without negotiation
- sconn.getSender().close();
+ sconn.closeAndIgnoreFutureInput();
return;
}
else if(okMaxFrameSize == 0)
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java Thu Mar 12 14:13:28 2015
@@ -920,15 +920,13 @@ public class AMQProtocolEngine implement
try
{
markChannelAwaitingCloseOk(channelId);
- closeSession(false); // currently performs the delete actions.
+ closeSession(false);
}
finally
{
try
{
writeFrame(frame);
-
- // add an async job and not
}
finally
{
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageMetaData_1_0.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageMetaData_1_0.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageMetaData_1_0.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageMetaData_1_0.java Thu Mar 12 14:13:28 2015
@@ -493,7 +493,13 @@ public class MessageMetaData_1_0 impleme
public String getType()
{
+ String subject = getSubject();
+ if(subject != null)
+ {
+ return subject;
+ }
+ // Use legacy annotation if present and there was no subject
if(_messageAnnotations == null || _messageAnnotations.get(JMS_TYPE) == null)
{
return null;
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java Thu Mar 12 14:13:28 2015
@@ -406,6 +406,13 @@ public class RestServlet extends Abstrac
@Override
protected void doPutWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
+ performCreateOrUpdate(request, response);
+ }
+
+ private void performCreateOrUpdate(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ boolean createOrUpdate = "PUT".equalsIgnoreCase(request.getMethod());
+
response.setContentType("application/json");
List<String> names = new ArrayList<String>();
@@ -461,6 +468,13 @@ public class RestServlet extends Abstrac
{
if (_hierarchy.length == 0)
{
+ if (!createOrUpdate)
+ {
+ sendErrorResponse(request, response,
+ "Only object creation is allowed with POST requests. Use PUT method to update broker attributes");
+ return;
+ }
+
try
{
doUpdate(getBroker(), providedObject);
@@ -484,7 +498,7 @@ public class RestServlet extends Abstrac
Collection<ConfiguredObject>[] objects = new Collection[_hierarchy.length];
if (_hierarchy.length == 1)
{
- createOrUpdate(providedObject, _hierarchy[0], getBroker(), null, request, response);
+ createOrUpdate(providedObject, _hierarchy[0], getBroker(), null, request, response, createOrUpdate);
}
else
{
@@ -547,26 +561,29 @@ public class RestServlet extends Abstrac
ConfiguredObject theParent = parents.remove(0);
ConfiguredObject[] otherParents = parents.toArray(new ConfiguredObject[parents.size()]);
- createOrUpdate(providedObject, objClass, theParent, otherParents, request, response);
+ createOrUpdate(providedObject, objClass, theParent, otherParents, request, response, createOrUpdate);
}
-
}
private void createOrUpdate(Map<String, Object> providedObject, Class<? extends ConfiguredObject> objClass,
ConfiguredObject theParent, ConfiguredObject[] otherParents, HttpServletRequest request,
- HttpServletResponse response) throws IOException
+ HttpServletResponse response, boolean createOrUpdate) throws IOException
{
try
{
Collection<? extends ConfiguredObject> existingChildren = theParent.getChildren(objClass);
- for(ConfiguredObject obj: existingChildren)
+
+ if (createOrUpdate)
{
- if((providedObject.containsKey("id") && String.valueOf(providedObject.get("id")).equals(obj.getId().toString()))
- || (obj.getName().equals(providedObject.get("name")) && equalParents(obj, otherParents, objClass)))
+ for (ConfiguredObject obj : existingChildren)
{
- doUpdate(obj, providedObject);
- response.setStatus(HttpServletResponse.SC_OK);
- return;
+ if ((providedObject.containsKey("id") && String.valueOf(providedObject.get("id")).equals(obj.getId().toString()))
+ || (obj.getName().equals(providedObject.get("name")) && equalParents(obj, otherParents, objClass)))
+ {
+ doUpdate(obj, providedObject);
+ response.setStatus(HttpServletResponse.SC_OK);
+ return;
+ }
}
}
@@ -626,11 +643,12 @@ public class RestServlet extends Abstrac
}
else
{
+ String message = e.getMessage();
if (e instanceof IllegalConfigurationException || e instanceof IllegalArgumentException)
{
if (LOGGER.isDebugEnabled())
{
- LOGGER.debug(e.getClass().getSimpleName() + " processing request : " + e.getMessage());
+ LOGGER.debug(e.getClass().getSimpleName() + " processing request : " + message);
}
else if (LOGGER.isTraceEnabled())
{
@@ -642,17 +660,22 @@ public class RestServlet extends Abstrac
LOGGER.warn("Unexpected exception processing request ", e);
}
- response.setStatus(HttpServletResponse.SC_CONFLICT);
+ sendErrorResponse(request, response, message);
- response.setContentType("application/json");
- response.setCharacterEncoding("UTF-8");
+ }
+ }
- Writer out = getOutputWriter(request, response);
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
- mapper.writeValue(out, Collections.singletonMap("errorMessage", e.getMessage()));
+ private void sendErrorResponse(HttpServletRequest request, HttpServletResponse response, String message) throws IOException
+ {
+ response.setStatus(HttpServletResponse.SC_CONFLICT);
- }
+ response.setContentType("application/json");
+ response.setCharacterEncoding("UTF-8");
+
+ Writer out = getOutputWriter(request, response);
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ mapper.writeValue(out, Collections.singletonMap("errorMessage", message));
}
@Override
@@ -678,6 +701,12 @@ public class RestServlet extends Abstrac
}
}
+ @Override
+ protected void doPostWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ performCreateOrUpdate(request, response);
+ }
+
private void setCachingHeadersOnResponse(HttpServletResponse response)
{
response.setHeader("Cache-Control","no-cache");
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/UserPreferencesServlet.java Thu Mar 12 14:13:28 2015
@@ -65,16 +65,6 @@ public class UserPreferencesServlet exte
private void getUserPreferences(String authenticationProviderName, String userId, HttpServletRequest request, HttpServletResponse response)
throws IOException
{
- try
- {
- assertUserPreferencesOperationAuthorized(userId);
- }
- catch (SecurityException e)
- {
- response.sendError(HttpServletResponse.SC_FORBIDDEN, "Viewing of preferences is not allowed");
- return;
- }
-
Map<String, Object> preferences = null;
PreferencesProvider preferencesProvider = getPreferencesProvider(authenticationProviderName);
if (preferencesProvider == null)
@@ -82,9 +72,17 @@ public class UserPreferencesServlet exte
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Preferences provider is not configured");
return;
}
- preferences = preferencesProvider.getPreferences(userId);
+ try
+ {
+ preferences = preferencesProvider.getPreferences(userId);
- sendJsonResponse(preferences, request, response);
+ sendJsonResponse(preferences, request, response);
+ }
+ catch (SecurityException e)
+ {
+ response.sendError(HttpServletResponse.SC_FORBIDDEN, "Viewing of preferences is not allowed");
+ return;
+ }
}
private void getUserList(String[] pathElements, HttpServletRequest request, HttpServletResponse response) throws IOException
@@ -177,16 +175,6 @@ public class UserPreferencesServlet exte
String userId = elements[1];
- try
- {
- assertUserPreferencesOperationAuthorized(userId);
- }
- catch (SecurityException e)
- {
- response.sendError(HttpServletResponse.SC_FORBIDDEN, "Deletion of preferences is not allowed");
- return;
- }
-
String providerName = elements[0];
Set<String> users = providerUsers.get(providerName);
@@ -216,7 +204,15 @@ public class UserPreferencesServlet exte
if (preferencesProvider != null && !usersToDelete.isEmpty())
{
String[] users = usersToDelete.toArray(new String[usersToDelete.size()]);
- preferencesProvider.deletePreferences(users);
+ try
+ {
+ preferencesProvider.deletePreferences(users);
+ }
+ catch (SecurityException e)
+ {
+ response.sendError(HttpServletResponse.SC_FORBIDDEN, "Deletion of preferences is not allowed");
+ return;
+ }
}
}
}
@@ -237,8 +233,4 @@ public class UserPreferencesServlet exte
return provider;
}
- private void assertUserPreferencesOperationAuthorized(String userId)
- {
- getBroker().getSecurityManager().authoriseUserOperation(Operation.UPDATE, userId);
- }
}
Modified: qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/metadata.js
URL: http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/metadata.js?rev=1666200&r1=1666199&r2=1666200&view=diff
==============================================================================
--- qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/metadata.js (original)
+++ qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/metadata.js Thu Mar 12 14:13:28 2015
@@ -68,8 +68,12 @@ define(["dojo/_base/xhr",
},
implementsManagedInterface: function (category, type, managedInterfaceName)
{
- var managedInterfaces = this.getMetaData(category, type).managedInterfaces;
- return array.indexOf(managedInterfaces, managedInterfaceName) >= 0 ;
+ var md = this.getMetaData(category, type);
+ if (md && md.managedInterfaces)
+ {
+ return array.indexOf(md.managedInterfaces, managedInterfaceName) >= 0 ;
+ }
+ return false;
},
validChildTypes: function (category, type, childCategory)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org