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();
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXUserID", new SubExpression() {
|
||||
|
||||
@Override
|
||||
public Object evaluate(Message message) {
|
||||
return message.getUserID();
|
||||
}
|
||||
});
|
||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq", new SubExpression() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.activemq.test;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
|
@ -24,7 +23,6 @@ import javax.jms.Message;
|
|||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.security.SimpleSecurityBrokerSystemTest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -36,27 +34,43 @@ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopic
|
|||
|
||||
protected String userName = "James";
|
||||
|
||||
@Override
|
||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||
ActiveMQConnectionFactory answer = super.createConnectionFactory();
|
||||
answer.setUserName(userName);
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureBroker(BrokerService answer) throws Exception {
|
||||
answer.setPopulateJMSXUserID(true);
|
||||
super.configureBroker(answer);
|
||||
}
|
||||
|
||||
protected void assertMessagesReceivedAreValid(List receivedMessages) throws JMSException {
|
||||
@Override
|
||||
protected void assertMessagesReceivedAreValid(List<Message> receivedMessages) throws JMSException {
|
||||
super.assertMessagesReceivedAreValid(receivedMessages);
|
||||
|
||||
// lets assert that the user ID is set
|
||||
for (Iterator iter = receivedMessages.iterator(); iter.hasNext();) {
|
||||
Message message = (Message)iter.next();
|
||||
for (Message message : receivedMessages) {
|
||||
String userID = message.getStringProperty("JMSXUserID");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -77,4 +91,21 @@ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopic
|
|||
assertMessagesAreReceived();
|
||||
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