git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1456485 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2013-03-14 15:38:01 +00:00
parent fbe632e968
commit f87f56294d
2 changed files with 27 additions and 2 deletions

View File

@ -17,6 +17,7 @@
package org.apache.activemq.util; package org.apache.activemq.util;
import javax.jms.JMSException; import javax.jms.JMSException;
import javax.jms.JMSSecurityException;
import javax.jms.MessageEOFException; import javax.jms.MessageEOFException;
import javax.jms.MessageFormatException; import javax.jms.MessageFormatException;
@ -46,7 +47,12 @@ public final class JMSExceptionSupport {
if (msg == null || msg.length() == 0) { if (msg == null || msg.length() == 0) {
msg = cause.toString(); 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); exception.initCause(cause);
return exception; return exception;
} }
@ -59,7 +65,12 @@ public final class JMSExceptionSupport {
if (msg == null || msg.length() == 0) { if (msg == null || msg.length() == 0) {
msg = cause.toString(); 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.setLinkedException(cause);
exception.initCause(cause); exception.initCause(cause);
return exception; return exception;

View File

@ -20,6 +20,7 @@ import java.net.URI;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.JMSException; import javax.jms.JMSException;
import javax.jms.JMSSecurityException;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageProducer; import javax.jms.MessageProducer;
import javax.jms.Session; import javax.jms.Session;
@ -104,6 +105,19 @@ public class SimpleAuthenticationPluginTest extends SecurityTestSupport {
} catch (Exception ignore) {} } 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 { public void testSecurityContextClearedOnPurge() throws Exception {
connection.close(); connection.close();