javax.jms.JMSSecurityException Java Examples
The following examples show how to use
javax.jms.JMSSecurityException.
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: SaslIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doSaslFailureCodesTestImpl(UnsignedByte saslFailureCode) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.expectSaslFailingExchange(new Symbol[] {PLAIN, ANONYMOUS}, PLAIN, saslFailureCode); ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + "?jms.clientID=myClientID"); try { factory.createConnection("username", "password"); fail("Excepted exception to be thrown"); }catch (JMSSecurityException jmsse) { LOG.info("Caught expected security exception: {}", jmsse.getMessage()); } testPeer.waitForAllHandlersToComplete(1000); } }
Example #2
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 10000) public void testNoUserOrPassword() throws Exception { Connection connection = null; try { connection = createConnection("", "", null, false); connection.start(); fail("Expected JMSException"); } catch (JMSSecurityException ex) { instanceLog.debug("Failed to authenticate connection with no user / password.", ex); } finally { if (connection != null) { connection.close(); } } }
Example #3
Source File: MockJMSConnection.java From pooled-jms with Apache License 2.0 | 6 votes |
private void ensureConnected() throws JMSException { if (isConnected() || closed.get()) { return; } synchronized(this.connectionId) { if (isConnected() || closed.get()) { return; } if (clientID == null || clientID.trim().isEmpty()) { throw new IllegalArgumentException("Client ID cannot be null or empty string"); } if (!user.isValid()) { executor.shutdown(); throw new JMSSecurityException(user.getFailureCause()); } connected.set(true); } }
Example #4
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAutoCreateOnSendToQueueSecurity() throws Exception { ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "rejectAll"); Role role = new Role("rejectAll", false, false, false, false, false, false, false, false, false, false); Set<Role> roles = new HashSet<>(); roles.add(role); server.getSecurityRepository().addMatch("#", roles); Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = ActiveMQJMSClient.createQueue(QUEUE_NAME); try { session.createProducer(queue); Assert.fail("Sending a message here should throw a JMSSecurityException"); } catch (Exception e) { Assert.assertTrue(e instanceof JMSSecurityException); } connection.close(); }
Example #5
Source File: SecureConfigurationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testTemporaryQueue() throws Exception { ConnectionFactory connectionFactory = getConnectionFactory("a", "a"); String message = "blah"; //Expect to be able to create subscriber on pre-defined/existing queue. String messageRecieved = sendAndReceiveText(connectionFactory, "clientId", message, s -> s.createTemporaryQueue(), (d, s) -> s.createConsumer(d)); Assert.assertEquals(message, messageRecieved); connectionFactory = getConnectionFactory("c", "c"); try { sendAndReceiveText(connectionFactory, "clientId", message, s -> s.createTemporaryQueue(), (d, s) -> s.createConsumer(d)); Assert.fail("Security exception expected, but did not occur, excepetion expected as not permissioned to create a temporary queue"); } catch (JMSSecurityException jmsse) { } catch (JMSException e) { e.printStackTrace(); Assert.fail("thrown a JMSEXception instead of a JMSSEcurityException"); } }
Example #6
Source File: SecureConfigurationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testTemporaryTopic() throws Exception { ConnectionFactory connectionFactory = getConnectionFactory("a", "a"); String message = "blah"; //Expect to be able to create subscriber on pre-defined/existing queue. String messageRecieved = sendAndReceiveText(connectionFactory, "clientId", message, s -> s.createTemporaryTopic(), (d, s) -> s.createConsumer(d)); Assert.assertEquals(message, messageRecieved); connectionFactory = getConnectionFactory("c", "c"); try { sendAndReceiveText(connectionFactory, "clientId", message, s -> s.createTemporaryTopic(), (d, s) -> s.createConsumer(d)); Assert.fail("Security exception expected, but did not occur, excepetion expected as not permissioned to create a temporary queue"); } catch (JMSSecurityException jmsse) { } catch (JMSException e) { e.printStackTrace(); Assert.fail("thrown a JMSEXception instead of a JMSSEcurityException"); } }
Example #7
Source File: SecureConfigurationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSecureQueue() throws Exception { ConnectionFactory connectionFactory = getConnectionFactory("b", "b"); String message = "blah"; //Expect to be able to create subscriber on pre-defined/existing queue. String messageRecieved = sendAndReceiveTextUsingQueue(connectionFactory, "clientId", message, "secured_queue", (q, s) -> s.createConsumer(q)); Assert.assertEquals(message, messageRecieved); connectionFactory = getConnectionFactory("a", "a"); messageRecieved = sendAndReceiveTextUsingQueue(connectionFactory, "clientId", message, "new-queue-1", (q, s) -> s.createConsumer(q)); Assert.assertEquals(message, messageRecieved); connectionFactory = getConnectionFactory("b", "b"); try { sendAndReceiveTextUsingQueue(connectionFactory, "clientId", message, "new-queue-2", (q, s) -> s.createConsumer(q)); Assert.fail("Security exception expected, but did not occur, excepetion expected as not permissioned to dynamically create address, or queue"); } catch (JMSSecurityException j) { //Expected exception } connectionFactory = getConnectionFactory("a", "a"); messageRecieved = sendAndReceiveTextUsingQueue(connectionFactory, "clientId", message, "new-queue-2", (q, s) -> s.createConsumer(q)); Assert.assertEquals(message, messageRecieved); }
Example #8
Source File: JmsAnonymousProducerTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testAnonymousProducerNotAuthorized() throws Exception { connection = createAmqpConnection("guest", "password"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("USERS.txQueue"); MessageProducer producer = session.createProducer(null); try { producer.send(queue, session.createTextMessage()); fail("Should not be able to produce here."); } catch (JMSSecurityException jmsSE) { LOG.info("Caught expected exception"); } catch (JMSException jms) { LOG.info("Caught expected exception"); } }
Example #9
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doConnectThrowsSecurityViolationOnFailureFromSaslImplicitlyWithoutClientIDTestImpl(UnsignedByte saslFailureCode) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.expectSaslFailingExchange(new Symbol[] {PLAIN, ANONYMOUS}, PLAIN, saslFailureCode); ConnectionFactory factory = new JmsConnectionFactory("failover:(amqp://localhost:" + testPeer.getServerPort() + ")"); Connection connection = factory.createConnection("username", "password"); try { connection.start(); fail("Excepted exception to be thrown"); }catch (JMSSecurityException jmsse) { LOG.info("Caught expected security exception: {}", jmsse.getMessage()); } testPeer.waitForAllHandlersToComplete(1000); } }
Example #10
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doConnectThrowsSecurityViolationOnFailureFromSaslWithOrExplicitlyWithoutClientIDTestImpl(boolean clientID, UnsignedByte saslFailureCode) throws Exception { String optionString; if (clientID) { optionString = "?jms.clientID=myClientID"; } else { optionString = "?jms.awaitClientID=false"; } try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.expectSaslFailingExchange(new Symbol[] {PLAIN, ANONYMOUS}, PLAIN, saslFailureCode); ConnectionFactory factory = new JmsConnectionFactory("failover:(amqp://localhost:" + testPeer.getServerPort() + ")" + optionString); try { factory.createConnection("username", "password"); fail("Excepted exception to be thrown"); }catch (JMSSecurityException jmsse) { LOG.info("Caught expected security exception: {}", jmsse.getMessage()); } testPeer.waitForAllHandlersToComplete(1000); } }
Example #11
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testRepeatedWrongPasswordAttempts() throws Exception { for (int i = 0; i < 25; ++i) { Connection connection = null; try { connection = createConnection(fullUser, "wrongPassword", null, false); connection.start(); fail("Expected JMSException"); } catch (JMSSecurityException ex) { instanceLog.debug("Failed to authenticate connection with incorrect password."); } finally { if (connection != null) { connection.close(); } } } }
Example #12
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testConsumerNotAuthorized() throws Exception { Connection connection = createConnection(noprivUser, noprivPass); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = session.createQueue(getQueueName()); try { session.createConsumer(queue); fail("Should not be able to consume here."); } catch (JMSSecurityException jmsSE) { instanceLog.debug("Caught expected exception"); } } finally { connection.close(); } }
Example #13
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testBrowserNotAuthorized() throws Exception { Connection connection = createConnection(noprivUser, noprivPass); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = session.createQueue(getQueueName()); try { QueueBrowser browser = session.createBrowser(queue); // Browser is not created until an enumeration is requesteda browser.getEnumeration(); fail("Should not be able to consume here."); } catch (JMSSecurityException jmsSE) { instanceLog.debug("Caught expected exception"); } } finally { connection.close(); } }
Example #14
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testProducerNotAuthorized() throws Exception { Connection connection = createConnection(guestUser, guestPass); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = session.createQueue(getQueueName()); try { session.createProducer(queue); fail("Should not be able to produce here."); } catch (JMSSecurityException jmsSE) { instanceLog.debug("Caught expected exception"); } } finally { connection.close(); } }
Example #15
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testAnonymousProducerNotAuthorized() throws Exception { Connection connection = createConnection(guestUser, guestPass); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = session.createQueue(getQueueName()); MessageProducer producer = session.createProducer(null); try { producer.send(queue, session.createTextMessage()); fail("Should not be able to produce here."); } catch (JMSSecurityException jmsSE) { instanceLog.debug("Caught expected exception"); } } finally { connection.close(); } }
Example #16
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testCreateTemporaryQueueNotAuthorized() throws JMSException { Connection connection = createConnection(guestUser, guestPass); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { session.createTemporaryQueue(); } catch (JMSSecurityException jmsse) { instanceLog.debug("Client should have thrown a JMSSecurityException but only threw JMSException"); } // Should not be fatal assertNotNull(connection.createSession(false, Session.AUTO_ACKNOWLEDGE)); } finally { connection.close(); } }
Example #17
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testCreateTemporaryTopicNotAuthorized() throws JMSException { Connection connection = createConnection(guestUser, guestPass); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { session.createTemporaryTopic(); } catch (JMSSecurityException jmsse) { instanceLog.debug("Client should have thrown a JMSSecurityException but only threw JMSException"); } // Should not be fatal assertNotNull(connection.createSession(false, Session.AUTO_ACKNOWLEDGE)); } finally { connection.close(); } }
Example #18
Source File: JMSConnectionWithSecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testConsumerNotAuthorizedToCreateQueues() throws Exception { Connection connection = createConnection(noprivUser, noprivPass); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = session.createQueue(getQueueName(getPrecreatedQueueSize() + 1)); try { session.createConsumer(queue); fail("Should not be able to consume here."); } catch (JMSSecurityException jmsSE) { instanceLog.debug("Caught expected exception"); } } finally { connection.close(); } }
Example #19
Source File: JmsContextTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testContextClosePreservesSessionCloseException() throws JMSException { JmsConnection connection = Mockito.mock(JmsConnection.class); JmsSession session = Mockito.mock(JmsSession.class); Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session); JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE); Mockito.doThrow(IllegalStateException.class).when(session).close(); Mockito.doThrow(JMSSecurityException.class).when(connection).close(); context.createTemporaryTopic(); Mockito.verify(connection, Mockito.times(1)).createSession(JMSContext.AUTO_ACKNOWLEDGE); try { context.close(); fail("Should throw ISRE"); } catch (IllegalStateRuntimeException isre) { } }
Example #20
Source File: MockJMSConnectionFactory.java From pooled-jms with Apache License 2.0 | 6 votes |
private MockJMSConnection createMockConnection(String username, String password) throws JMSException { MockJMSUser user = validateUser(username, password); if (!user.isValid() && !deferAuthenticationToConnection) { throw new JMSSecurityException(user.getFailureCause()); } MockJMSConnection connection = new MockJMSConnection(user); if (clientID != null && !clientID.isEmpty()) { connection.setClientID(clientID, true); } else { connection.setClientID(UUID.randomUUID().toString(), false); } try { connection.initialize(); } catch (JMSException e) { connection.close(); } return connection; }
Example #21
Source File: SaslGssApiIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doMechanismSelectedTestImpl(String username, String password, Symbol clientSelectedMech, Symbol[] serverMechs, boolean enableGssapiExplicitly) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.expectSaslFailingAuthentication(serverMechs, clientSelectedMech); String uriOptions = "?jms.clientID=myclientid"; if(enableGssapiExplicitly) { uriOptions += "&amqp.saslMechanisms=PLAIN," + GSSAPI; } ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + uriOptions); try { factory.createConnection(username, password); fail("Excepted exception to be thrown"); }catch (JMSSecurityException jmsse) { // Expected, we deliberately failed the SASL process, // we only wanted to verify the correct mechanism // was selected, other tests verify the remainder. LOG.info("Caught expected security exception: {}", jmsse.getMessage()); } testPeer.waitForAllHandlersToComplete(1000); } }
Example #22
Source File: SaslGssApiIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 20000) public void testSaslGssApiKrbConfigError() throws Exception { final String loginConfigScope = "KRB5-CLIENT-DOES-NOT-EXIST"; try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.expectSaslGSSAPIFail(); String uriOptions = "?sasl.options.configScope=" + loginConfigScope + "&amqp.saslMechanisms=" + GSSAPI; ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + uriOptions); factory.createConnection(); fail("Expect exception on no login config"); } catch (JMSSecurityException expected) { assertTrue(expected.getMessage().contains(loginConfigScope)); } }
Example #23
Source File: SaslIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doMechanismSelectionRestrictedTestImpl(String username, String password, Symbol clientSelectedMech, Symbol[] serverMechs, String mechanismsOptionValue) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.expectSaslFailingAuthentication(serverMechs, clientSelectedMech); String uriOptions = "?jms.clientID=myclientid"; if(mechanismsOptionValue != null) { uriOptions += "&amqp.saslMechanisms=" + mechanismsOptionValue; } ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + uriOptions); try { factory.createConnection(username, password); fail("Excepted exception to be thrown"); }catch (JMSSecurityException jmsse) { // Expected, we deliberately failed the SASL process, // we only wanted to verify the correct mechanism // was selected, other tests verify the remainder. } testPeer.waitForAllHandlersToComplete(1000); } }
Example #24
Source File: SecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Login with valid user and password * But try send to address not authorised - Persistent * Should not allow and should throw exception */ @Test public void testLoginValidUserAndPasswordButNotAuthorisedToSend() throws Exception { SimpleString queueName = SimpleString.toSimpleString("guest.cannot.send"); if (getJmsServer().locateQueue(queueName) == null) { getJmsServer().createQueue(new QueueConfiguration(queueName).setRoutingType(RoutingType.ANYCAST)); } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = connectionFactory.createConnection("guest", "guest"); Session session = connection.createSession(); Destination destination = session.createQueue(queueName.toString()); MessageProducer messageProducer = session.createProducer(destination); try { messageProducer.send(session.createTextMessage("hello")); fail("JMSSecurityException expected as guest is not allowed to send"); } catch (JMSSecurityException activeMQSecurityException) { //pass } connection.close(); }
Example #25
Source File: SaslIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private void doMechanismSelectedTestImpl(String username, String password, Symbol clientSelectedMech, Symbol[] serverMechs, boolean wait) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.expectSaslFailingAuthentication(serverMechs, clientSelectedMech); ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + "?jms.clientID=myclientid"); try { factory.createConnection(username, password); fail("Excepted exception to be thrown"); }catch (JMSSecurityException jmsse) { // Expected, we deliberately failed the SASL process, // we only wanted to verify the correct mechanism // was selected, other tests verify the remainder. LOG.info("Caught expected security exception: {}", jmsse.getMessage()); } if (wait) { Thread.sleep(200); } testPeer.waitForAllHandlersToComplete(1000); } }
Example #26
Source File: SessionIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doCreateTemporaryDestinationFailsWhenLinkRefusedTestImpl(boolean topic, boolean deferAttachResponseWrite) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { Connection connection = testFixture.establishConnecton(testPeer); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { if (topic) { testPeer.expectAndRefuseTempTopicCreationAttach(AmqpError.UNAUTHORIZED_ACCESS, "Not Authorized to create temp topics.", false); //Expect the detach response to the test peer after refusal. testPeer.expectDetach(true, false, false); session.createTemporaryTopic(); } else { testPeer.expectAndRefuseTempQueueCreationAttach(AmqpError.UNAUTHORIZED_ACCESS, "Not Authorized to create temp queues.", false); //Expect the detach response to the test peer after refusal. testPeer.expectDetach(true, false, false); session.createTemporaryQueue(); } fail("Should have thrown security exception"); } catch (JMSSecurityException jmsse) { } testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #27
Source File: SessionIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testConsumerNotAuthorized() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { Connection connection = testFixture.establishConnecton(testPeer); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String topicName = "myTopic"; Topic destination = session.createTopic(topicName); testPeer.expectReceiverAttach(notNullValue(), notNullValue(), false, true, false, false, AmqpError.UNAUTHORIZED_ACCESS, "Destination is not readable"); testPeer.expectDetach(true, true, true); try { session.createConsumer(destination); fail("Should have thrown a security exception"); } catch (JMSSecurityException jmsse) { } testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #28
Source File: JmsQueueConnectionTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=30000, expected = JMSSecurityException.class) public void testCreateConnectionCallUnknwonUser() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI()); connection = factory.createQueueConnection("unknown", "unknown"); assertNotNull(connection); connection.start(); }
Example #29
Source File: JmsTopicConnectionTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=30000, expected = JMSSecurityException.class) public void testCreateConnectionAsUnknwonUser() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI()); factory.setUsername("unknown"); factory.setPassword("unknown"); connection = factory.createTopicConnection(); assertNotNull(connection); connection.start(); }
Example #30
Source File: JmsQueueConnectionTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=30000, expected = JMSSecurityException.class) public void testCreateConnectionAsUnknwonUser() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI()); factory.setUsername("unknown"); factory.setPassword("unknown"); connection = factory.createQueueConnection(); assertNotNull(connection); connection.start(); }