Added user substitution during ACL pattern mathing
This commit is contained in:
+7
-3
@@ -130,9 +130,9 @@ class AuthorizationsCollector implements IAuthorizator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client != null && !client.isEmpty()) {
|
if (isNotEmpty(client) || isNotEmpty(username)) {
|
||||||
for (Authorization auth : m_patternAuthorizations) {
|
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 (auth.permission == permission || auth.permission == READWRITE) {
|
||||||
if (SubscriptionsStore.matchTopics(topic, substitutedTopic)) {
|
if (SubscriptionsStore.matchTopics(topic, substitutedTopic)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -141,7 +141,7 @@ class AuthorizationsCollector implements IAuthorizator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username != null && !username.isEmpty()) {
|
if (isNotEmpty(username)) {
|
||||||
if (m_userAuthorizations.containsKey(username)) {
|
if (m_userAuthorizations.containsKey(username)) {
|
||||||
for (Authorization auth : m_userAuthorizations.get(username)) {
|
for (Authorization auth : m_userAuthorizations.get(username)) {
|
||||||
if (auth.permission == permission || auth.permission == READWRITE) {
|
if (auth.permission == permission || auth.permission == READWRITE) {
|
||||||
@@ -155,6 +155,10 @@ class AuthorizationsCollector implements IAuthorizator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNotEmpty(String client) {
|
||||||
|
return client != null && !client.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return m_globalAuthorizations.isEmpty();
|
return m_globalAuthorizations.isEmpty();
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-1
@@ -140,10 +140,18 @@ public class AuthorizationsCollectorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParsePatternClientLineACL() throws ParseException {
|
public void testPatternClientLineACL() throws ParseException {
|
||||||
authorizator.parse("pattern read /weather/italy/%c");
|
authorizator.parse("pattern read /weather/italy/%c");
|
||||||
|
|
||||||
//Verify
|
//Verify
|
||||||
assertTrue(authorizator.canRead("/weather/italy/anemometer1", "", "anemometer1"));
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user