From 08b64b592cb844cbd746b33e5f17c94b2158a115 Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Thu, 13 Feb 2014 19:41:22 +0000 Subject: QPID-5551 : replace AMQSecurityException with QpidSecurityException in the broker git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1568015 13f79535-47bb-0310-9956-ffa450edef68 --- .../protocol/v0_10/ServerSessionDelegate.java | 37 ++++++++++++++++++++++ .../qpid/server/protocol/v0_8/AMQChannel.java | 14 +++++--- .../server/protocol/v0_8/AMQProtocolEngine.java | 8 +---- .../v0_8/handler/BasicConsumeMethodHandler.java | 8 +++++ .../v0_8/handler/BasicGetMethodHandler.java | 21 ++++++++---- .../v0_8/handler/BasicPublishMethodHandler.java | 10 +++++- .../v0_8/handler/ExchangeDeclareHandler.java | 5 +++ .../v0_8/handler/ExchangeDeleteHandler.java | 5 +++ .../protocol/v0_8/handler/QueueBindHandler.java | 5 +++ .../protocol/v0_8/handler/QueueDeclareHandler.java | 17 ++++++++-- .../protocol/v0_8/handler/QueueDeleteHandler.java | 11 ++++++- .../protocol/v0_8/handler/QueuePurgeHandler.java | 13 ++++++-- .../protocol/v0_8/handler/QueueUnbindHandler.java | 10 +++++- .../apache/qpid/server/protocol/v0_8/AckTest.java | 12 +++---- .../qpid/server/protocol/v0_8/AcknowledgeTest.java | 14 ++++---- .../server/protocol/v0_8/BrokerTestHelper_0_8.java | 4 ++- .../protocol/v0_8/QueueBrowserUsesNoAckTest.java | 4 +-- .../qpid/server/protocol/v1_0/SendingLink_1_0.java | 21 ++++++++++-- .../qpid/server/protocol/v1_0/Session_1_0.java | 9 ++++-- .../server/management/amqp/ManagementNode.java | 8 ++--- .../plugin/servlet/rest/RestServlet.java | 4 +-- 21 files changed, 189 insertions(+), 51 deletions(-) (limited to 'qpid/java/broker-plugins') diff --git a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java index d3d53504be..3d50da6ed5 100644 --- a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java +++ b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java @@ -42,6 +42,7 @@ import org.apache.qpid.server.model.UUIDGenerator; import org.apache.qpid.server.plugin.ExchangeType; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.QueueArgumentsConverter; +import org.apache.qpid.server.security.QpidSecurityException; import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.MessageStore; @@ -301,6 +302,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot subscribe to queue '" + queueName + "' with destination '" + destination); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } } } @@ -786,6 +791,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot declare exchange '" + exchangeName); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } @@ -898,6 +907,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot delete exchange '" + method.getExchange() ); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } private boolean nameNullOrEmpty(String name) @@ -992,6 +1005,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot add binding '" + method.getBindingKey()); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } else { @@ -1045,6 +1062,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot remove binding '" + method.getBindingKey()); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } } } @@ -1272,6 +1293,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot delete '" + method.getQueue()); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } }; final ServerSession s = (ServerSession) session; @@ -1324,6 +1349,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot declare queue '" + queueName); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } } @@ -1401,6 +1430,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot delete queue '" + queueName); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } } } @@ -1432,6 +1465,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, method, e, "Cannot purge queue '" + queueName); } + catch (QpidSecurityException e) + { + exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage()); + } } } } diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQChannel.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQChannel.java index 5afb2069c1..4eeb9d8fb2 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQChannel.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQChannel.java @@ -29,7 +29,7 @@ import java.util.concurrent.locks.Lock; import org.apache.log4j.Logger; import org.apache.qpid.AMQConnectionException; import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; +import org.apache.qpid.server.security.QpidSecurityException; import org.apache.qpid.common.AMQPFilterTypes; import org.apache.qpid.framing.AMQMethodBody; import org.apache.qpid.framing.AMQShortString; @@ -262,13 +262,13 @@ public class AMQChannel implements AMQSessionModel, AsyncAutoCommitTransaction.F return _channelId; } - public void setPublishFrame(MessagePublishInfo info, final MessageDestination e) throws AMQSecurityException + public void setPublishFrame(MessagePublishInfo info, final MessageDestination e) throws QpidSecurityException { String routingKey = info.getRoutingKey() == null ? null : info.getRoutingKey().asString(); SecurityManager securityManager = getVirtualHost().getSecurityManager(); if (!securityManager.authorisePublish(info.isImmediate(), routingKey, e.getName())) { - throw new AMQSecurityException("Permission denied: " + e.getName()); + throw new QpidSecurityException("Permission denied: " + e.getName()); } _currentMessage = new IncomingMessage(info); _currentMessage.setMessageDestination(e); @@ -515,7 +515,8 @@ public class AMQChannel implements AMQSessionModel, AsyncAutoCommitTransaction.F * @throws AMQException if something goes wrong */ public AMQShortString consumeFromSource(AMQShortString tag, MessageSource source, boolean acks, - FieldTable filters, boolean exclusive, boolean noLocal) throws AMQException + FieldTable filters, boolean exclusive, boolean noLocal) + throws AMQException, QpidSecurityException { if (tag == null) { @@ -588,6 +589,11 @@ public class AMQChannel implements AMQSessionModel, AsyncAutoCommitTransaction.F _tag2SubscriptionTargetMap.remove(tag); throw e; } + catch (QpidSecurityException e) + { + _tag2SubscriptionTargetMap.remove(tag); + throw e; + } return tag; } diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java index ba61afc376..329aa396b0 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java @@ -46,7 +46,7 @@ import org.apache.log4j.Logger; import org.apache.qpid.AMQChannelException; import org.apache.qpid.AMQConnectionException; import org.apache.qpid.AMQException; -import org.apache.qpid.AMQSecurityException; +import org.apache.qpid.server.security.QpidSecurityException; import org.apache.qpid.codec.AMQCodecFactory; import org.apache.qpid.common.QpidProperties; import org.apache.qpid.common.ServerPropertyNames; @@ -628,12 +628,6 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi _logger.info(e.getMessage() + " whilst processing:" + methodBody); closeConnection(channelId, e); } - catch (AMQSecurityException e) - { - AMQConnectionException ce = evt.getMethod().getConnectionException(AMQConstant.ACCESS_REFUSED, e.getMessage()); - _logger.info(e.getMessage() + " whilst processing:" + methodBody); - closeConnection(channelId, ce); - } } catch (Exception e) { diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/BasicConsumeMethodHandler.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/BasicConsumeMethodHandler.java index b28bb5a0ad..ad4235b786 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/BasicConsumeMethodHandler.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/BasicConsumeMethodHandler.java @@ -35,6 +35,7 @@ import org.apache.qpid.server.protocol.AMQSessionModel; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.protocol.v0_8.state.AMQStateManager; import org.apache.qpid.server.protocol.v0_8.state.StateAwareMethodListener; +import org.apache.qpid.server.security.QpidSecurityException; import org.apache.qpid.server.virtualhost.VirtualHost; public class BasicConsumeMethodHandler implements StateAwareMethodListener @@ -175,6 +176,13 @@ public class BasicConsumeMethodHandler implements StateAwareMethodListener @@ -88,7 +89,14 @@ public class BasicPublishMethodHandler implements StateAwareMethodListener { throw body.getChannelException(AMQConstant.CHANNEL_ERROR, e.toString()); } + catch (QpidSecurityException e) + { + throw body.getConnectionException(AMQConstant.ACCESS_REFUSED, e.getMessage()); + } if (_log.isInfoEnabled()) { diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/QueueDeclareHandler.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/QueueDeclareHandler.java index 263175d590..1286a20970 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/QueueDeclareHandler.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/QueueDeclareHandler.java @@ -39,9 +39,11 @@ import org.apache.qpid.server.queue.QueueArgumentsConverter; import org.apache.qpid.server.queue.QueueRegistry; import org.apache.qpid.server.protocol.v0_8.state.AMQStateManager; import org.apache.qpid.server.protocol.v0_8.state.StateAwareMethodListener; +import org.apache.qpid.server.security.QpidSecurityException; import org.apache.qpid.server.store.DurableConfigurationStoreHelper; import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.util.Action; +import org.apache.qpid.server.util.ConnectionScopedRuntimeException; import org.apache.qpid.server.virtualhost.VirtualHost; import java.util.Map; @@ -185,6 +187,10 @@ public class QueueDeclareHandler implements StateAwareMethodListener @@ -103,10 +104,18 @@ public class QueuePurgeHandler implements StateAwareMethodListener @@ -105,7 +106,14 @@ public class QueueUnbindHandler implements StateAwareMethodListener