Skip to content

Commit 3a5971e

Browse files
ARTEMIS-1872 Improving Security Checks on AMQP Protocol
Also improving test coverage on SecureConfigurationTest This commit will fix JMSConnectionWithSecurityTest.
1 parent 88b2399 commit 3a5971e

File tree

4 files changed

+55
-45
lines changed

4 files changed

+55
-45
lines changed

artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void createTemporaryQueue(SimpleString address,
248248
try {
249249
serverSession.createQueue(address, queueName, routingType, filter, true, false);
250250
} catch (ActiveMQSecurityException se) {
251-
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingConsumer(se.getMessage());
251+
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingTempDestination(se.getMessage());
252252
}
253253
}
254254

artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException;
3030
import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException;
3131
import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException;
32+
import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPSecurityException;
3233
import org.apache.activemq.artemis.protocol.amqp.logger.ActiveMQAMQPProtocolMessageBundle;
3334
import org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult;
3435
import org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult;
@@ -108,6 +109,8 @@ public void initialise() throws Exception {
108109

109110
try {
110111
sessionSPI.createTemporaryQueue(address, defRoutingType);
112+
} catch (ActiveMQAMQPSecurityException e) {
113+
throw e;
111114
} catch (ActiveMQSecurityException e) {
112115
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingTempDestination(e.getMessage());
113116
} catch (Exception e) {

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/SecureConfigurationTest.java

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
2626
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
2727
import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
28+
import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
2829
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
2930
import org.apache.qpid.jms.JmsConnectionFactory;
31+
import org.junit.After;
3032
import org.junit.Assert;
3133
import org.junit.Assume;
34+
import org.junit.Before;
3235
import org.junit.Test;
3336
import org.junit.runner.RunWith;
3437
import org.junit.runners.Parameterized;
@@ -58,24 +61,30 @@ public static Collection<Object[]> parameters() {
5861
@Parameterized.Parameter(0)
5962
public String protocol;
6063

61-
@Test
62-
public void testSecureSharedDurableSubscriber() throws Exception {
63-
//This is because OpenWire does not support JMS 2.0
64-
Assume.assumeFalse(protocol.equals("OPENWIRE"));
64+
ActiveMQServer server;
65+
66+
@Before
67+
public void startSever() throws Exception {
68+
server = getActiveMQServer("multicast_topic.xml");
69+
server.start();
70+
}
6571

66-
ActiveMQServer server = getActiveMQServer("multicast_topic.xml");
72+
@After
73+
public void stopServer() throws Exception {
6774
try {
68-
server.start();
69-
internal_testSecureSharedDurableSubscriber(getConnectionFactory("b", "b"));
70-
} finally {
71-
try {
75+
if (server != null) {
7276
server.stop();
73-
} catch (Exception e) {
7477
}
78+
} catch (Throwable e) {
79+
e.printStackTrace();
7580
}
7681
}
7782

78-
private void internal_testSecureSharedDurableSubscriber(ConnectionFactory connectionFactory) throws JMSException {
83+
@Test
84+
public void testSecureSharedDurableSubscriber() throws Exception {
85+
//This is because OpenWire does not support JMS 2.0
86+
Assume.assumeFalse(protocol.equals("OPENWIRE"));
87+
ConnectionFactory connectionFactory = getConnectionFactory("b", "b");
7988
String message = "blah";
8089

8190
//Expect to be able to create subscriber on pre-defined/existing queue.
@@ -101,20 +110,7 @@ private void internal_testSecureSharedDurableSubscriber(ConnectionFactory connec
101110
public void testSecureSharedSubscriber() throws Exception {
102111
//This is because OpenWire does not support JMS 2.0
103112
Assume.assumeFalse(protocol.equals("OPENWIRE"));
104-
105-
ActiveMQServer server = getActiveMQServer("multicast_topic.xml");
106-
try {
107-
server.start();
108-
internal_testSecureSharedSubscriber(getConnectionFactory("b", "b"));
109-
} finally {
110-
try {
111-
server.stop();
112-
} catch (Exception e) {
113-
}
114-
}
115-
}
116-
117-
private void internal_testSecureSharedSubscriber(ConnectionFactory connectionFactory) throws JMSException {
113+
ConnectionFactory connectionFactory = getConnectionFactory("b", "b");
118114
String message = "blah";
119115

120116
//Expect to be able to create subscriber on pre-defined/existing queue.
@@ -138,19 +134,7 @@ private void internal_testSecureSharedSubscriber(ConnectionFactory connectionFac
138134

139135
@Test
140136
public void testSecureDurableSubscriber() throws Exception {
141-
ActiveMQServer server = getActiveMQServer("multicast_topic.xml");
142-
try {
143-
server.start();
144-
internal_testSecureDurableSubscriber(getConnectionFactory("b", "b"));
145-
} finally {
146-
try {
147-
server.stop();
148-
} catch (Exception e) {
149-
}
150-
}
151-
}
152-
153-
private void internal_testSecureDurableSubscriber(ConnectionFactory connectionFactory) throws JMSException {
137+
ConnectionFactory connectionFactory = getConnectionFactory("b", "b");
154138
String message = "blah";
155139

156140
//Expect to be able to create subscriber on pre-defined/existing queue.
@@ -177,8 +161,31 @@ private void internal_testSecureDurableSubscriber(ConnectionFactory connectionFa
177161
} catch (JMSSecurityException j) {
178162
//Expected exception
179163
}
164+
165+
Connection connection = null;
166+
167+
try {
168+
connection = connectionFactory.createConnection();
169+
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
170+
171+
try {
172+
session.createTemporaryQueue();
173+
Assert.fail("Security exception expected, but did not occur, excepetion expected as not permissioned to create a temporary queue");
174+
} catch (JMSSecurityException jmsse) {
175+
IntegrationTestLogger.LOGGER.info("Client should have thrown a JMSSecurityException but only threw JMSException");
176+
} catch (JMSException e) {
177+
e.printStackTrace();
178+
Assert.fail("thrown a JMSEXception instead of a JMSSEcurityException");
179+
}
180+
181+
// Should not be fatal
182+
assertNotNull(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
183+
} finally {
184+
connection.close();
185+
}
180186
}
181187

188+
182189
private ConnectionFactory getConnectionFactory(String user, String password) {
183190
switch (protocol) {
184191
case "CORE": return getActiveMQConnectionFactory(user, password);

tests/integration-tests/src/test/resources/multicast_topic.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ under the License.
8585

8686
<security-settings>
8787
<security-setting match="#">
88-
<permission type="createNonDurableQueue" roles="a,b"/>
89-
<permission type="deleteNonDurableQueue" roles="a,b"/>
90-
<permission type="createDurableQueue" roles="a,b"/>
91-
<permission type="deleteDurableQueue" roles="a,b"/>
88+
<permission type="createNonDurableQueue" roles="a"/>
89+
<permission type="deleteNonDurableQueue" roles="a"/>
90+
<permission type="createDurableQueue" roles="a"/>
91+
<permission type="deleteDurableQueue" roles="a"/>
9292
<permission type="browse" roles="a"/>
93-
<permission type="send" roles="a,b"/>
94-
<permission type="consume" roles="a,b" />
93+
<permission type="send" roles="a"/>
94+
<permission type="consume" roles="a" />
9595
<!-- we need this otherwise ./artemis data imp wouldn't work -->
9696
<permission type="manage" roles="a"/>
9797
</security-setting>

0 commit comments

Comments
 (0)