From f87f56294df3d1494e9bb548fe989bb111e1c08b Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Thu, 14 Mar 2013 15:38:01 +0000 Subject: [PATCH] fix and test for: https://issues.apache.org/jira/browse/AMQ-4373 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1456485 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/util/JMSExceptionSupport.java | 15 +++++++++++++-- .../security/SimpleAuthenticationPluginTest.java | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/activemq-client/src/main/java/org/apache/activemq/util/JMSExceptionSupport.java b/activemq-client/src/main/java/org/apache/activemq/util/JMSExceptionSupport.java index 9382362792..5d55273422 100755 --- a/activemq-client/src/main/java/org/apache/activemq/util/JMSExceptionSupport.java +++ b/activemq-client/src/main/java/org/apache/activemq/util/JMSExceptionSupport.java @@ -17,6 +17,7 @@ package org.apache.activemq.util; import javax.jms.JMSException; +import javax.jms.JMSSecurityException; import javax.jms.MessageEOFException; import javax.jms.MessageFormatException; @@ -46,7 +47,12 @@ public final class JMSExceptionSupport { if (msg == null || msg.length() == 0) { msg = cause.toString(); } - JMSException exception = new JMSException(msg); + JMSException exception; + if (cause instanceof SecurityException) { + exception = new JMSSecurityException(msg); + } else { + exception = new JMSException(msg); + } exception.initCause(cause); return exception; } @@ -59,7 +65,12 @@ public final class JMSExceptionSupport { if (msg == null || msg.length() == 0) { msg = cause.toString(); } - JMSException exception = new JMSException(msg); + JMSException exception; + if (cause instanceof SecurityException) { + exception = new JMSSecurityException(msg); + } else { + exception = new JMSException(msg); + } exception.setLinkedException(cause); exception.initCause(cause); return exception; diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java index 9e90d95c3e..1a154b261b 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java @@ -20,6 +20,7 @@ import java.net.URI; import javax.jms.Connection; import javax.jms.JMSException; +import javax.jms.JMSSecurityException; import javax.jms.Message; import javax.jms.MessageProducer; import javax.jms.Session; @@ -104,6 +105,19 @@ public class SimpleAuthenticationPluginTest extends SecurityTestSupport { } catch (Exception ignore) {} } + public void testConnectionStartThrowsJMSSecurityException() throws Exception { + + Connection connection = factory.createConnection("badUser", "password"); + try { + connection.start(); + fail("Should throw JMSSecurityException"); + } catch (JMSSecurityException jmsEx) { + } catch (Exception e) { + LOG.info("Expected JMSSecurityException but was: {}", e.getClass()); + fail("Should throw JMSSecurityException"); + } + } + public void testSecurityContextClearedOnPurge() throws Exception { connection.close();