Java Code Examples for org.apache.qpid.jms.JmsConnectionFactory#setPopulateJMSXUserID()

The following examples show how to use org.apache.qpid.jms.JmsConnectionFactory#setPopulateJMSXUserID() . 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: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testUserIdSetWhenConfiguredForInclusion() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        // Expect a PLAIN connection
        String user = "user";
        String pass = "qwerty123456";

        testPeer.expectSaslPlain(user, pass);
        testPeer.expectOpen();
        testPeer.expectBegin();
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        JmsConnectionFactory factory = new JmsConnectionFactory(
            "amqp://localhost:" + testPeer.getServerPort());
        factory.setPopulateJMSXUserID(true);

        Connection connection = factory.createConnection(user, pass);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("TestQueue");
        MessageProducer producer = session.createProducer(queue);

        Binary binaryUserId = new Binary(user.getBytes(Charset.forName("UTF-8")));
        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        propertiesMatcher.withUserId(equalTo(binaryUserId));
        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true);
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);

        testPeer.expectTransfer(messageMatcher);

        producer.send(session.createMessage());

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 2
Source File: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testUserIdNotSetWhenNotConfiguredForInclusion() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        // Expect a PLAIN connection
        String user = "user";
        String pass = "qwerty123456";

        testPeer.expectSaslPlain(user, pass);
        testPeer.expectOpen();
        testPeer.expectBegin();
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        JmsConnectionFactory factory = new JmsConnectionFactory(
            "amqp://localhost:" + testPeer.getServerPort());
        factory.setPopulateJMSXUserID(false);

        Connection connection = factory.createConnection(user, pass);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("TestQueue");
        MessageProducer producer = session.createProducer(queue);

        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        propertiesMatcher.withUserId(nullValue());
        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true);
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);

        testPeer.expectTransfer(messageMatcher);

        producer.send(session.createMessage());

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 3
Source File: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testUserIdNotSpoofedWhenConfiguredForInclusion() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        // Expect a PLAIN connection
        String user = "user";
        String pass = "qwerty123456";

        testPeer.expectSaslPlain(user, pass);
        testPeer.expectOpen();
        testPeer.expectBegin();
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        JmsConnectionFactory factory = new JmsConnectionFactory(
            "amqp://localhost:" + testPeer.getServerPort());
        factory.setPopulateJMSXUserID(true);

        Connection connection = factory.createConnection(user, pass);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("TestQueue");
        MessageProducer producer = session.createProducer(queue);

        Binary binaryUserId = new Binary(user.getBytes(Charset.forName("UTF-8")));
        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        propertiesMatcher.withUserId(equalTo(binaryUserId));
        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true);
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);

        testPeer.expectTransfer(messageMatcher);

        Message message = session.createMessage();
        message.setStringProperty("JMSXUserID", "spoofed");

        producer.send(message);

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 4
Source File: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testUserIdNotSpoofedWhenNotConfiguredForInclusion() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        // Expect a PLAIN connection
        String user = "user";
        String pass = "qwerty123456";

        testPeer.expectSaslPlain(user, pass);
        testPeer.expectOpen();
        testPeer.expectBegin();
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        JmsConnectionFactory factory = new JmsConnectionFactory(
            "amqp://localhost:" + testPeer.getServerPort());
        factory.setPopulateJMSXUserID(false);

        Connection connection = factory.createConnection(user, pass);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("TestQueue");
        MessageProducer producer = session.createProducer(queue);

        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        propertiesMatcher.withUserId(nullValue());
        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true);
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);

        testPeer.expectTransfer(messageMatcher);

        Message message = session.createMessage();
        message.setStringProperty("JMSXUserID", "spoofed");

        producer.send(message);

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 5
Source File: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testUserIdNotSpoofedWhenConfiguredForInclusionWithForgeinMessage() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        // Expect a PLAIN connection
        String user = "user";
        String pass = "qwerty123456";

        testPeer.expectSaslPlain(user, pass);
        testPeer.expectOpen();
        testPeer.expectBegin();
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        JmsConnectionFactory factory = new JmsConnectionFactory(
            "amqp://localhost:" + testPeer.getServerPort());
        factory.setPopulateJMSXUserID(true);

        Connection connection = factory.createConnection(user, pass);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("TestQueue");
        MessageProducer producer = session.createProducer(queue);

        Binary binaryUserId = new Binary(user.getBytes(Charset.forName("UTF-8")));
        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        propertiesMatcher.withUserId(equalTo(binaryUserId));
        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true);
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);

        testPeer.expectTransfer(messageMatcher);

        Message message = new CustomForeignMessage();
        message.setStringProperty("JMSXUserID", "spoofed");

        producer.send(message);

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 6
Source File: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testUserIdNotSpoofedWhenNotConfiguredForInclusionWithForeignMessage() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        // Expect a PLAIN connection
        String user = "user";
        String pass = "qwerty123456";

        testPeer.expectSaslPlain(user, pass);
        testPeer.expectOpen();
        testPeer.expectBegin();
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        JmsConnectionFactory factory = new JmsConnectionFactory(
            "amqp://localhost:" + testPeer.getServerPort());
        factory.setPopulateJMSXUserID(false);

        Connection connection = factory.createConnection(user, pass);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("TestQueue");
        MessageProducer producer = session.createProducer(queue);

        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        propertiesMatcher.withUserId(nullValue());
        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true);
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);

        testPeer.expectTransfer(messageMatcher);

        Message message = new CustomForeignMessage();
        producer.send(message);

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}