mirror of https://github.com/apache/activemq.git
fix and test for: https://issues.apache.org/jira/browse/AMQ-4542
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1487018 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d379076196
commit
067660ce88
|
@ -138,6 +138,13 @@ public class PropertyExpression implements Expression {
|
||||||
return message.getGroupID();
|
return message.getGroupID();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
JMS_PROPERTY_EXPRESSIONS.put("JMSXUserID", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object evaluate(Message message) {
|
||||||
|
return message.getUserID();
|
||||||
|
}
|
||||||
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq", new SubExpression() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.test;
|
package org.apache.activemq.test;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
@ -24,39 +23,54 @@ import javax.jms.Message;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.security.SimpleSecurityBrokerSystemTest;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest {
|
public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.class);
|
||||||
|
|
||||||
protected String userName = "James";
|
protected String userName = "James";
|
||||||
|
|
||||||
|
@Override
|
||||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||||
ActiveMQConnectionFactory answer = super.createConnectionFactory();
|
ActiveMQConnectionFactory answer = super.createConnectionFactory();
|
||||||
answer.setUserName(userName);
|
answer.setUserName(userName);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void configureBroker(BrokerService answer) throws Exception {
|
protected void configureBroker(BrokerService answer) throws Exception {
|
||||||
answer.setPopulateJMSXUserID(true);
|
answer.setPopulateJMSXUserID(true);
|
||||||
super.configureBroker(answer);
|
super.configureBroker(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertMessagesReceivedAreValid(List receivedMessages) throws JMSException {
|
@Override
|
||||||
|
protected void assertMessagesReceivedAreValid(List<Message> receivedMessages) throws JMSException {
|
||||||
super.assertMessagesReceivedAreValid(receivedMessages);
|
super.assertMessagesReceivedAreValid(receivedMessages);
|
||||||
|
|
||||||
// lets assert that the user ID is set
|
// lets assert that the user ID is set
|
||||||
for (Iterator iter = receivedMessages.iterator(); iter.hasNext();) {
|
for (Message message : receivedMessages) {
|
||||||
Message message = (Message)iter.next();
|
|
||||||
String userID = message.getStringProperty("JMSXUserID");
|
String userID = message.getStringProperty("JMSXUserID");
|
||||||
|
|
||||||
LOG.info("Received message with userID: " + userID);
|
LOG.info("Received message with userID: " + userID);
|
||||||
|
assertEquals("JMSXUserID header", userName, userID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assertMessagesAreReceived2() throws JMSException {
|
||||||
|
waitForMessagesToBeDelivered();
|
||||||
|
assertMessagesReceivedAreValid2(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assertMessagesReceivedAreValid2(List<Message> receivedMessages) throws JMSException {
|
||||||
|
super.assertMessagesReceivedAreValid(receivedMessages);
|
||||||
|
|
||||||
|
// lets assert that the user ID is set
|
||||||
|
for (Message message : receivedMessages) {
|
||||||
|
String userID = (String) message.getObjectProperty("JMSXUserID");
|
||||||
|
LOG.info("Received message with userID: " + userID);
|
||||||
assertEquals("JMSXUserID header", userName, userID);
|
assertEquals("JMSXUserID header", userName, userID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,4 +91,21 @@ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopic
|
||||||
assertMessagesAreReceived();
|
assertMessagesAreReceived();
|
||||||
LOG.info("" + data.length + " messages(s) received, closing down connections");
|
LOG.info("" + data.length + " messages(s) received, closing down connections");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSpoofedJMSXUserIdIsIgnoredAsObjectProperty() throws Exception {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
messages.clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
|
Message message = createMessage(i);
|
||||||
|
configureMessage(message);
|
||||||
|
message.setStringProperty("JMSXUserID", "spoofedId");
|
||||||
|
if (verbose) {
|
||||||
|
LOG.info("About to send a message: " + message + " with text: " + data[i]);
|
||||||
|
}
|
||||||
|
sendMessage(i, message);
|
||||||
|
}
|
||||||
|
assertMessagesAreReceived2();
|
||||||
|
LOG.info("" + data.length + " messages(s) received, closing down connections");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue