Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows List or String in topics-filter-regex #659

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/akhq/configs/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
public class Group {
String name;
List<String> roles;
Map<String, Object> attributes;
Map<String, List<String>> attributes;
}
2 changes: 1 addition & 1 deletion src/main/java/org/akhq/utils/UserGroupUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Map<String, Object> getUserAttributes(List<String> groups) {
.flatMap(group -> (group.getAttributes() != null) ? group.getAttributes().entrySet().stream() : null)
.collect(Collectors.toMap(
Map.Entry::getKey,
item -> new ArrayList<>(Collections.singletonList(item.getValue())),
item -> new ArrayList<>(item.getValue()),
(e1, e2) -> {
((List) e1).addAll((List) e2); return e1;
}
Expand Down
73 changes: 73 additions & 0 deletions src/test/java/org/akhq/configs/UserGroupUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.akhq.configs;

import io.micronaut.context.ApplicationContext;
import org.akhq.utils.UserGroupUtils;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;

public class UserGroupUtilsTest {
@Test
void testTopicRegexpAsString() {
ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class,"filterregex");

UserGroupUtils userGroupUtils = ctx.getBean(UserGroupUtils.class);

List<String> actual = (List<String>)userGroupUtils.getUserAttributes(List.of("as-string")).get("topicsFilterRegexp");

assertEquals(
1,
actual.size()
);
assertIterableEquals(
List.of("test.*"),
actual
);

ctx.close();
}

@Test
void testTopicRegexpAsList() {

ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class,"filterregex");

UserGroupUtils userGroupUtils = ctx.getBean(UserGroupUtils.class);

List<String> actual = (List<String>)userGroupUtils.getUserAttributes(List.of("as-list")).get("topicsFilterRegexp");

assertEquals(
2,
actual.size()
);
assertIterableEquals(
List.of("item1","item2"),
actual
);

ctx.close();
}
@Test
void testTopicRegexpAsMixed() {

ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class,"filterregex");

UserGroupUtils userGroupUtils = ctx.getBean(UserGroupUtils.class);

List<String> actual = (List<String>)userGroupUtils.getUserAttributes(List.of("as-string","as-list")).get("topicsFilterRegexp");

assertEquals(
3,
actual.size()
);
assertIterableEquals(
List.of("test.*","item1","item2"),
actual
);

ctx.close();
}
}
15 changes: 15 additions & 0 deletions src/test/resources/application-filterregex.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
akhq:
security:
groups:
as-string:
roles:
- topic/read
attributes:
topics-filter-regexp: "test.*"
as-list:
roles:
- topic/read
attributes:
topics-filter-regexp:
- "item1"
- "item2"