25
25
import org .apache .activemq .artemis .jms .server .config .impl .FileJMSConfiguration ;
26
26
import org .apache .activemq .artemis .spi .core .security .ActiveMQJAASSecurityManager ;
27
27
import org .apache .activemq .artemis .spi .core .security .jaas .InVMLoginModule ;
28
+ import org .apache .activemq .artemis .tests .integration .IntegrationTestLogger ;
28
29
import org .apache .activemq .artemis .tests .util .ActiveMQTestBase ;
29
30
import org .apache .qpid .jms .JmsConnectionFactory ;
31
+ import org .junit .After ;
30
32
import org .junit .Assert ;
31
33
import org .junit .Assume ;
34
+ import org .junit .Before ;
32
35
import org .junit .Test ;
33
36
import org .junit .runner .RunWith ;
34
37
import org .junit .runners .Parameterized ;
@@ -58,24 +61,30 @@ public static Collection<Object[]> parameters() {
58
61
@ Parameterized .Parameter (0 )
59
62
public String protocol ;
60
63
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
+ }
65
71
66
- ActiveMQServer server = getActiveMQServer ("multicast_topic.xml" );
72
+ @ After
73
+ public void stopServer () throws Exception {
67
74
try {
68
- server .start ();
69
- internal_testSecureSharedDurableSubscriber (getConnectionFactory ("b" , "b" ));
70
- } finally {
71
- try {
75
+ if (server != null ) {
72
76
server .stop ();
73
- } catch (Exception e ) {
74
77
}
78
+ } catch (Throwable e ) {
79
+ e .printStackTrace ();
75
80
}
76
81
}
77
82
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" );
79
88
String message = "blah" ;
80
89
81
90
//Expect to be able to create subscriber on pre-defined/existing queue.
@@ -101,20 +110,7 @@ private void internal_testSecureSharedDurableSubscriber(ConnectionFactory connec
101
110
public void testSecureSharedSubscriber () throws Exception {
102
111
//This is because OpenWire does not support JMS 2.0
103
112
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" );
118
114
String message = "blah" ;
119
115
120
116
//Expect to be able to create subscriber on pre-defined/existing queue.
@@ -138,19 +134,7 @@ private void internal_testSecureSharedSubscriber(ConnectionFactory connectionFac
138
134
139
135
@ Test
140
136
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" );
154
138
String message = "blah" ;
155
139
156
140
//Expect to be able to create subscriber on pre-defined/existing queue.
@@ -177,8 +161,31 @@ private void internal_testSecureDurableSubscriber(ConnectionFactory connectionFa
177
161
} catch (JMSSecurityException j ) {
178
162
//Expected exception
179
163
}
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
+ }
180
186
}
181
187
188
+
182
189
private ConnectionFactory getConnectionFactory (String user , String password ) {
183
190
switch (protocol ) {
184
191
case "CORE" : return getActiveMQConnectionFactory (user , password );
0 commit comments