Skip to content

Commit 38c39b6

Browse files
committed
ARTEMIS-6057 support literalMatchMarkers in security repo such that fqqn with wildcards can be supported
1 parent 8a8803a commit 38c39b6

3 files changed

Lines changed: 130 additions & 2 deletions

File tree

artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public ActiveMQServerImpl(Configuration configuration,
507507

508508
addressSettingsRepository.setDefault(new AddressSettings());
509509

510-
securityRepository = new HierarchicalObjectRepository<>(configuration.getWildcardConfiguration(), new SecuritySettingsMatchModifier());
510+
securityRepository = new HierarchicalObjectRepository<>(configuration.getWildcardConfiguration(), new SecuritySettingsMatchModifier(), this.configuration.getLiteralMatchMarkers());
511511

512512
securityRepository.setDefault(new HashSet<>());
513513

artemis-server/src/main/java/org/apache/activemq/artemis/core/settings/impl/HierarchicalObjectRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public T getMatch(final String match) {
264264

265265
@Override
266266
public boolean containsExactMatch(String match) {
267-
return exactMatches.containsKey(match);
267+
return exactMatches.containsKey(match) || literalMatches.containsKey(match);
268268
}
269269

270270
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.artemis.tests.integration.jms.client;
18+
19+
import org.apache.activemq.artemis.api.core.QueueConfiguration;
20+
import org.apache.activemq.artemis.api.core.RoutingType;
21+
import org.apache.activemq.artemis.core.config.Configuration;
22+
import org.apache.activemq.artemis.core.config.CoreAddressConfiguration;
23+
import org.apache.activemq.artemis.core.security.Role;
24+
import org.apache.activemq.artemis.core.server.ActiveMQServer;
25+
import org.apache.activemq.artemis.core.settings.HierarchicalRepository;
26+
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
27+
import org.apache.activemq.artemis.tests.util.JMSTestBase;
28+
import org.apache.activemq.artemis.utils.CompositeAddress;
29+
import org.junit.jupiter.api.Test;
30+
31+
import javax.jms.Connection;
32+
import javax.jms.DeliveryMode;
33+
import javax.jms.Message;
34+
import javax.jms.MessageConsumer;
35+
import javax.jms.MessageProducer;
36+
import javax.jms.ObjectMessage;
37+
import javax.jms.Session;
38+
import javax.jms.Topic;
39+
40+
import java.util.HashSet;
41+
import java.util.Set;
42+
43+
import static org.junit.jupiter.api.Assertions.assertNotNull;
44+
45+
public class WildcardOnboardSecureTest extends JMSTestBase {
46+
47+
private final String publishTo = "test.topic.A";
48+
private final String subscribeToWildcard = "test.topic.*";
49+
private final String clientId = "id1";
50+
private final String subscriberName = "sub1";
51+
52+
@Test
53+
public void testConsumeFromExistingWildcardWithJustConsumePermissionViaLiteral() throws Exception {
54+
Session sendSession = createSession(null);
55+
MessageProducer producerA = createProducer(sendSession, publishTo);
56+
57+
ObjectMessage received;
58+
try (MessageConsumer consumerWC = createConsumer(subscribeToWildcard)) {
59+
60+
Message message = sendSession.createObjectMessage(1);
61+
producerA.send(message);
62+
63+
received = (ObjectMessage) consumerWC.receive(500);
64+
}
65+
assertNotNull(received);
66+
assertNotNull(received.getObject());
67+
}
68+
69+
@Override
70+
protected boolean useSecurity() {
71+
return true;
72+
}
73+
74+
@Override
75+
protected Configuration createDefaultConfig(boolean netty) throws Exception {
76+
Configuration configuration = super.createDefaultConfig(netty);
77+
configuration.setLiteralMatchMarkers("()"); // NB for this test, now supported by security repo
78+
return configuration;
79+
}
80+
81+
@Override
82+
protected void extraServerConfig(ActiveMQServer server) {
83+
HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
84+
ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
85+
securityManager.getConfiguration().addUser("joe", "joe");
86+
securityManager.getConfiguration().addRole("joe", "joe");
87+
Role joe = new Role("joe", true, true, false, false, false, false, false, false, false, false, false, false);
88+
Set<Role> roles = new HashSet<>();
89+
// no auto create permissions
90+
roles.add(joe);
91+
92+
securityRepository.addMatch(publishTo, roles);
93+
// need to escape wildcard chars with () to form a literal match
94+
securityRepository.addMatch("(" + CompositeAddress.toFullyQualified(subscribeToWildcard, clientId + "." + subscriberName) + ")", roles);
95+
securityManager.getConfiguration().addRole("joe", "joe");
96+
// pre create address and consumer queue
97+
server.getConfiguration().addAddressConfiguration(new CoreAddressConfiguration().setName(publishTo).addRoutingType(RoutingType.MULTICAST));
98+
server.getConfiguration().addQueueConfiguration(QueueConfiguration.of(clientId + "." + subscriberName).setAddress(subscribeToWildcard).setRoutingType(RoutingType.MULTICAST));
99+
}
100+
101+
private Session createSession(String clientId) throws Exception {
102+
Connection connection = cf.createConnection("joe", "joe");
103+
if (clientId != null) {
104+
connection.setClientID(clientId);
105+
}
106+
connection.start();
107+
addConnection(connection);
108+
109+
return connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
110+
}
111+
112+
private MessageProducer createProducer(Session session, String topicName) throws Exception {
113+
Topic topic = session.createTopic(topicName);
114+
115+
MessageProducer producer = session.createProducer(topic);
116+
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
117+
118+
return producer;
119+
}
120+
121+
private MessageConsumer createConsumer(String topicName) throws Exception {
122+
123+
Session session = createSession(clientId);
124+
Topic topic = session.createTopic(topicName);
125+
126+
return session.createDurableConsumer(topic, subscriberName);
127+
}
128+
}

0 commit comments

Comments
 (0)