ARTEMIS-3339 Fix management role match key comparator

This commit is contained in:
Domenico Francesco Bruscino 2021-06-15 15:07:58 +02:00 committed by clebertsuconic
parent 48d489ec42
commit b1d326ba8b
2 changed files with 9 additions and 5 deletions

View File

@ -41,10 +41,11 @@ public class JMXAccessControlList {
return +1;
} else if (!key1ContainsWildCard && key2ContainsWildcard) {
return -1;
} else if (key1ContainsWildCard && key2ContainsWildcard) {
return key2.length() - key1.length();
} else if (key1.length() == key2.length()) {
return key1.compareTo(key2);
}
return key1.length() - key2.length();
return key2.length() - key1.length();
};
public void addToWhiteList(String domain, String key) {

View File

@ -99,10 +99,13 @@ public class JMXAccessControlListTest {
public void testBasicRoleWithWildcardInKey() throws MalformedObjectNameException {
JMXAccessControlList controlList = new JMXAccessControlList();
controlList.addToRoleAccess("org.myDomain", "type=foo*","listSomething", "update");
controlList.addToRoleAccess("org.myDomain", "type=bar*","listSomething", "browse");
controlList.addToRoleAccess("org.myDomain", "type=foo.bar*","listSomething", "admin");
controlList.addToRoleAccess("org.myDomain", null,"listSomething", "view");
List<String> roles = controlList.getRolesForObject(new ObjectName("org.myDomain:type=foo.bar.test"), "listSomething");
Assert.assertArrayEquals(roles.toArray(), new String[]{"admin"});
Assert.assertArrayEquals(controlList.getRolesForObject(new ObjectName("org.myDomain:type=foo.bar.test"),
"listSomething").toArray(), new String[]{"admin"});
Assert.assertArrayEquals(controlList.getRolesForObject(new ObjectName("org.myDomain:type=bar.test"),
"listSomething").toArray(), new String[]{"browse"});
}
@Test