javax.jms.JMSSecurityRuntimeException Java Examples

The following examples show how to use javax.jms.JMSSecurityRuntimeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30000)
public void testCreateProducerAnonymousNotAuthorized() {
    MockJMSUser user = new MockJMSUser("user", "password");
    user.setCanProducerAnonymously(false);

    factory.addUser(user);

    JMSContext context = cf.createContext("user", "password");
    try {
        context.createProducer();
        fail("Should not be able to create producer when not authorized");
    } catch (JMSSecurityRuntimeException jmssre) {}
}
 
Example #2
Source File: JmsExceptionUtils.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Converts instances of sub-classes of {@link JMSException} into the corresponding sub-class of
 * {@link JMSRuntimeException}.
 *
 * @param e
 * @return
 */
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
   if (e instanceof javax.jms.IllegalStateException) {
      return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidClientIDException) {
      return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidDestinationException) {
      return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidSelectorException) {
      return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof JMSSecurityException) {
      return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof MessageFormatException) {
      return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof MessageNotWriteableException) {
      return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof ResourceAllocationException) {
      return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof TransactionInProgressException) {
      return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof TransactionRolledBackException) {
      return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
 
Example #3
Source File: SaslIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void doMechanismNegotiationFailsToFindMatchTestImpl(boolean createContext) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        String failureMessageBreadcrumb = "Could not find a suitable SASL mechanism."
                + " No supported mechanism, or none usable with the available credentials. Server offered: [SCRAM-SHA-1, UNKNOWN, PLAIN]";
        Symbol[] serverMechs = new Symbol[] { SCRAM_SHA_1, Symbol.valueOf("UNKNOWN"), PLAIN};

        testPeer.expectSaslMechanismNegotiationFailure(serverMechs);

        String uriOptions = "?jms.clientID=myclientid";
        ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + uriOptions);
        if(createContext) {
            try {
                factory.createContext(null, null);
                fail("Excepted exception to be thrown");
            } catch (JMSSecurityRuntimeException jmssre) {
                // Expected, we deliberately failed the mechanism negotiation process.
                assertNotNull("Expected an exception message", jmssre.getMessage());
                assertEquals("Unexpected message details", jmssre.getMessage(), failureMessageBreadcrumb);
            }
        } else {
            try {
                factory.createConnection(null, null);
                fail("Excepted exception to be thrown");
            } catch (JMSSecurityException jmsse) {
                // Expected, we deliberately failed the mechanism negotiation process.
                assertNotNull("Expected an exception message", jmsse.getMessage());
                assertEquals("Unexpected message details", jmsse.getMessage(), failureMessageBreadcrumb);
            }
        }

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #4
Source File: JMS2.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static JMSRuntimeException toRuntimeException(final JMSException e) {
    if (e instanceof javax.jms.IllegalStateException) {
        return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidClientIDException) {
        return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidDestinationException) {
        return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidSelectorException) {
        return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof JMSSecurityException) {
        return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageFormatException) {
        return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageNotWriteableException) {
        return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof ResourceAllocationException) {
        return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionInProgressException) {
        return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionRolledBackException) {
        return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
 
Example #5
Source File: JMSExceptionSupportTest.java    From pooled-jms with Apache License 2.0 4 votes vote down vote up
@Test(expected = JMSSecurityRuntimeException.class)
public void testConvertsJMSSecurityExceptionToJMSSecurityRuntimeException() {
    throw JMSExceptionSupport.createRuntimeException(new JMSSecurityException("error"));
}
 
Example #6
Source File: JmsExceptionSupportTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(expected = JMSSecurityRuntimeException.class)
public void testConvertsJMSSecurityExceptionToJMSSecurityRuntimeException() {
    throw JmsExceptionSupport.createRuntimeException(new JMSSecurityException("error"));
}