Added user substitution during ACL pattern mathing

This commit is contained in:
andrea
2015-05-26 22:51:16 +02:00
parent db4b7ca192
commit 78eddadac4
2 changed files with 16 additions and 4 deletions
@@ -130,9 +130,9 @@ class AuthorizationsCollector implements IAuthorizator {
}
}
if (client != null && !client.isEmpty()) {
if (isNotEmpty(client) || isNotEmpty(username)) {
for (Authorization auth : m_patternAuthorizations) {
String substitutedTopic = auth.topic.replace("%c", client);
String substitutedTopic = auth.topic.replace("%c", client).replace("%u", username);
if (auth.permission == permission || auth.permission == READWRITE) {
if (SubscriptionsStore.matchTopics(topic, substitutedTopic)) {
return true;
@@ -141,7 +141,7 @@ class AuthorizationsCollector implements IAuthorizator {
}
}
if (username != null && !username.isEmpty()) {
if (isNotEmpty(username)) {
if (m_userAuthorizations.containsKey(username)) {
for (Authorization auth : m_userAuthorizations.get(username)) {
if (auth.permission == permission || auth.permission == READWRITE) {
@@ -155,6 +155,10 @@ class AuthorizationsCollector implements IAuthorizator {
return false;
}
private boolean isNotEmpty(String client) {
return client != null && !client.isEmpty();
}
public boolean isEmpty() {
return m_globalAuthorizations.isEmpty();
}
@@ -140,10 +140,18 @@ public class AuthorizationsCollectorTest {
}
@Test
public void testParsePatternClientLineACL() throws ParseException {
public void testPatternClientLineACL() throws ParseException {
authorizator.parse("pattern read /weather/italy/%c");
//Verify
assertTrue(authorizator.canRead("/weather/italy/anemometer1", "", "anemometer1"));
}
@Test
public void testPatternClientAndUserLineACL() throws ParseException {
authorizator.parse("pattern read /weather/%u/%c");
//Verify
assertTrue(authorizator.canRead("/weather/italy/anemometer1", "italy", "anemometer1"));
}
}