AMQ-8116 ActiveMQWildcardPermission buggy

ActiveMQWildcardPermission with multiple tokens inconsistent with parent
WildcardPermission class

Update ActiveMQWildcardPermission.java

add testcase

(cherry picked from commit 9cf9d20d51)
This commit is contained in:
ikucuze 2021-01-06 11:26:30 +01:00 committed by jbonofre
parent 4530777c51
commit b8c58028f0
2 changed files with 20 additions and 9 deletions

View File

@ -59,18 +59,25 @@ public class ActiveMQWildcardPermission extends WildcardPermission {
} else {
Set<String> thisPart = getParts().get(i);
for (String token : thisPart) {
if (token.equals(WILDCARD_TOKEN)) {
continue;
// all tokens from otherPart must pass at least one token from thisPart
for (String otherToken : otherPart) {
if (!caseSensitive) {
otherToken = otherToken.toLowerCase();
}
for (String otherToken : otherPart) {
if (!caseSensitive) {
otherToken = otherToken.toLowerCase();
boolean otherIsMatched = false;
for (String token : thisPart) {
if (token.equals(WILDCARD_TOKEN)) {
otherIsMatched = true;
break;
}
if (!matches(token, otherToken)) {
return false;
if (matches(token, otherToken)) {
otherIsMatched = true;
break;
}
}
}
if (!otherIsMatched) {
return false;
}
}
i++;
}

View File

@ -117,6 +117,10 @@ public class ActiveMQWildcardPermissionTest {
assertNoMatch("*:ActiveMQ*", "topic:TEST:*");
assertMatch("topic:ActiveMQ.Advisory*", "topic:ActiveMQ.Advisory.Connection:create");
assertMatch("foo?ar", "foobar");
assertMatch("queue:*:read,write", "queue:testqueue:read");
assertMatch("queue:*:read,write", "queue:test*:read,write");
assertNoMatch("queue:*:read,write", "queue:*:read,write,delete");
}
protected static void assertMatch(String pattern, String value) {