mirror of https://github.com/apache/activemq.git
applied patch from Kelly Campbell for AMQ-940 wth thanks
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@450044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2b11b8c36d
commit
094f00750f
|
@ -72,6 +72,11 @@ public class ConnectionContext {
|
||||||
|
|
||||||
public void setSecurityContext(SecurityContext subject) {
|
public void setSecurityContext(SecurityContext subject) {
|
||||||
this.securityContext = subject;
|
this.securityContext = subject;
|
||||||
|
if (subject != null) {
|
||||||
|
setUserName(subject.getUserName());
|
||||||
|
} else {
|
||||||
|
setUserName(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,7 +207,7 @@ public class ConnectionContext {
|
||||||
return userName;
|
return userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserName(String userName) {
|
protected void setUserName(String userName) {
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ final public class OpenWireFormat implements WireFormat {
|
||||||
private static final int MARSHAL_CACHE_PREFERED_SIZE = MARSHAL_CACHE_SIZE-100;
|
private static final int MARSHAL_CACHE_PREFERED_SIZE = MARSHAL_CACHE_SIZE-100;
|
||||||
|
|
||||||
private DataStreamMarshaller dataMarshallers[];
|
private DataStreamMarshaller dataMarshallers[];
|
||||||
private int version;
|
private int version = 2;
|
||||||
private boolean stackTraceEnabled=false;
|
private boolean stackTraceEnabled=false;
|
||||||
private boolean tcpNoDelayEnabled=false;
|
private boolean tcpNoDelayEnabled=false;
|
||||||
private boolean cacheEnabled=false;
|
private boolean cacheEnabled=false;
|
||||||
|
|
|
@ -17,8 +17,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.security;
|
package org.apache.activemq.security;
|
||||||
|
|
||||||
|
import org.apache.activemq.CombinationTestSupport;
|
||||||
import org.apache.activemq.JmsTestSupport;
|
import org.apache.activemq.JmsTestSupport;
|
||||||
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
|
import org.apache.activemq.command.ActiveMQMessage;
|
||||||
import org.apache.activemq.command.ActiveMQQueue;
|
import org.apache.activemq.command.ActiveMQQueue;
|
||||||
import org.apache.activemq.command.ActiveMQTopic;
|
import org.apache.activemq.command.ActiveMQTopic;
|
||||||
|
|
||||||
|
@ -37,6 +40,15 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
|
|
||||||
public ActiveMQDestination destination;
|
public ActiveMQDestination destination;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides to set the JMSXUserID flag to true.
|
||||||
|
*/
|
||||||
|
protected BrokerService createBroker() throws Exception {
|
||||||
|
BrokerService broker = super.createBroker();
|
||||||
|
broker.setPopulateJMSXUserID(true);
|
||||||
|
return broker;
|
||||||
|
}
|
||||||
|
|
||||||
public void testUserReceiveFails() throws JMSException {
|
public void testUserReceiveFails() throws JMSException {
|
||||||
doReceive(true);
|
doReceive(true);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +86,9 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUserReceiveSucceeds() throws JMSException {
|
public void testUserReceiveSucceeds() throws JMSException {
|
||||||
doReceive(false);
|
Message m = doReceive(false);
|
||||||
|
assertEquals("system", ((ActiveMQMessage)m).getUserID());
|
||||||
|
assertEquals("system", m.getStringProperty("JMSXUserID"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGuestReceiveSucceeds() throws JMSException {
|
public void testGuestReceiveSucceeds() throws JMSException {
|
||||||
|
@ -86,7 +100,9 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUserSendSucceeds() throws JMSException {
|
public void testUserSendSucceeds() throws JMSException {
|
||||||
doSend(false);
|
Message m = doSend(false);
|
||||||
|
assertEquals("user", ((ActiveMQMessage)m).getUserID());
|
||||||
|
assertEquals("user", m.getStringProperty("JMSXUserID"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUserSendFails() throws JMSException {
|
public void testUserSendFails() throws JMSException {
|
||||||
|
@ -104,7 +120,7 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
/**
|
/**
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
*/
|
*/
|
||||||
public void doSend(boolean fail) throws JMSException {
|
public Message doSend(boolean fail) throws JMSException {
|
||||||
|
|
||||||
Connection adminConnection = factory.createConnection("system", "manager");
|
Connection adminConnection = factory.createConnection("system", "manager");
|
||||||
connections.add(adminConnection);
|
connections.add(adminConnection);
|
||||||
|
@ -134,13 +150,13 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
assertEquals("0", ((TextMessage) m).getText());
|
assertEquals("0", ((TextMessage) m).getText());
|
||||||
assertNull(consumer.receiveNoWait());
|
assertNull(consumer.receiveNoWait());
|
||||||
}
|
}
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws JMSException
|
* @throws JMSException
|
||||||
*/
|
*/
|
||||||
public void doReceive(boolean fail) throws JMSException {
|
public Message doReceive(boolean fail) throws JMSException {
|
||||||
|
|
||||||
connection.start();
|
connection.start();
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
@ -152,7 +168,7 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
}
|
}
|
||||||
catch (JMSException e) {
|
catch (JMSException e) {
|
||||||
if (fail && e.getCause() instanceof SecurityException)
|
if (fail && e.getCause() instanceof SecurityException)
|
||||||
return;
|
return null;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,9 +181,13 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
assertNotNull(m);
|
assertNotNull(m);
|
||||||
assertEquals("0", ((TextMessage) m).getText());
|
assertEquals("0", ((TextMessage) m).getText());
|
||||||
assertNull(consumer.receiveNoWait());
|
assertNull(consumer.receiveNoWait());
|
||||||
|
return m;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestUserReceiveFails() {
|
public void initCombosForTestUserReceiveFails() {
|
||||||
addCombinationValues("userName", new Object[] { "user" });
|
addCombinationValues("userName", new Object[] { "user" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
|
@ -175,23 +195,35 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
new ActiveMQTopic("GUEST.BAR"), });
|
new ActiveMQTopic("GUEST.BAR"), });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestInvalidAuthentication() {
|
public void initCombosForTestInvalidAuthentication() {
|
||||||
addCombinationValues("userName", new Object[] { "user" });
|
addCombinationValues("userName", new Object[] { "user" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestUserReceiveSucceeds() {
|
public void initCombosForTestUserReceiveSucceeds() {
|
||||||
addCombinationValues("userName", new Object[] { "user" });
|
addCombinationValues("userName", new Object[] { "user" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
addCombinationValues("destination", new Object[] { new ActiveMQQueue("USERS.FOO"), new ActiveMQTopic("USERS.FOO"), });
|
addCombinationValues("destination", new Object[] { new ActiveMQQueue("USERS.FOO"), new ActiveMQTopic("USERS.FOO"), });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestGuestReceiveSucceeds() {
|
public void initCombosForTestGuestReceiveSucceeds() {
|
||||||
addCombinationValues("userName", new Object[] { "guest" });
|
addCombinationValues("userName", new Object[] { "guest" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
addCombinationValues("destination", new Object[] { new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR"), });
|
addCombinationValues("destination", new Object[] { new ActiveMQQueue("GUEST.BAR"), new ActiveMQTopic("GUEST.BAR"), });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestGuestReceiveFails() {
|
public void initCombosForTestGuestReceiveFails() {
|
||||||
addCombinationValues("userName", new Object[] { "guest" });
|
addCombinationValues("userName", new Object[] { "guest" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
|
@ -199,6 +231,9 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
new ActiveMQTopic("USERS.FOO"), });
|
new ActiveMQTopic("USERS.FOO"), });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestUserSendSucceeds() {
|
public void initCombosForTestUserSendSucceeds() {
|
||||||
addCombinationValues("userName", new Object[] { "user" });
|
addCombinationValues("userName", new Object[] { "user" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
|
@ -206,12 +241,18 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
new ActiveMQTopic("GUEST.BAR"), });
|
new ActiveMQTopic("GUEST.BAR"), });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestUserSendFails() {
|
public void initCombosForTestUserSendFails() {
|
||||||
addCombinationValues("userName", new Object[] { "user" });
|
addCombinationValues("userName", new Object[] { "user" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
addCombinationValues("destination", new Object[] { new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), });
|
addCombinationValues("destination", new Object[] { new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestGuestSendFails() {
|
public void initCombosForTestGuestSendFails() {
|
||||||
addCombinationValues("userName", new Object[] { "guest" });
|
addCombinationValues("userName", new Object[] { "guest" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
|
@ -219,6 +260,9 @@ public class SecurityTestSupport extends JmsTestSupport {
|
||||||
new ActiveMQTopic("USERS.FOO"), });
|
new ActiveMQTopic("USERS.FOO"), });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombosForTestGuestSendSucceeds() {
|
public void initCombosForTestGuestSendSucceeds() {
|
||||||
addCombinationValues("userName", new Object[] { "guest" });
|
addCombinationValues("userName", new Object[] { "guest" });
|
||||||
addCombinationValues("password", new Object[] { "password" });
|
addCombinationValues("password", new Object[] { "password" });
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.security;
|
package org.apache.activemq.security;
|
||||||
|
|
||||||
|
import org.apache.activemq.CombinationTestSupport;
|
||||||
import org.apache.activemq.broker.Broker;
|
import org.apache.activemq.broker.Broker;
|
||||||
import org.apache.activemq.broker.BrokerPlugin;
|
import org.apache.activemq.broker.BrokerPlugin;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
@ -124,13 +125,16 @@ public class SimpleSecurityBrokerSystemTest extends SecurityTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link CombinationTestSupport}
|
||||||
|
*/
|
||||||
public void initCombos() {
|
public void initCombos() {
|
||||||
addCombinationValues("authorizationPlugin", new Object[] { new AuthorizationPlugin(createAuthorizationMap()), });
|
addCombinationValues("authorizationPlugin", new Object[] { new AuthorizationPlugin(createAuthorizationMap()), });
|
||||||
addCombinationValues("authenticationPlugin", new Object[] { new SimpleAuthenticationFactory(), new JaasAuthenticationPlugin(), });
|
addCombinationValues("authenticationPlugin", new Object[] { new SimpleAuthenticationFactory(), new JaasAuthenticationPlugin(), });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BrokerService createBroker() throws Exception {
|
protected BrokerService createBroker() throws Exception {
|
||||||
BrokerService broker = new BrokerService();
|
BrokerService broker = super.createBroker();
|
||||||
broker.setPlugins(new BrokerPlugin[] { authorizationPlugin, authenticationPlugin });
|
broker.setPlugins(new BrokerPlugin[] { authorizationPlugin, authenticationPlugin });
|
||||||
broker.setPersistent(false);
|
broker.setPersistent(false);
|
||||||
return broker;
|
return broker;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<beans>
|
<beans>
|
||||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
|
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
|
||||||
|
|
||||||
<broker useJmx="false" persistent="false" xmlns="http://activemq.org/config/1.0">
|
<broker useJmx="false" persistent="false" xmlns="http://activemq.org/config/1.0" populateJMSXUserID="true">
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- use JAAS to authenticate using the login.config file on the classpath to configure JAAS -->
|
<!-- use JAAS to authenticate using the login.config file on the classpath to configure JAAS -->
|
||||||
|
|
Loading…
Reference in New Issue