-
-
Notifications
You must be signed in to change notification settings - Fork 659
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
fix(auth): Rolling back group configuration to a map format #526
Merged
tchiotludo
merged 3 commits into
tchiotludo:dev
from
ronrother:proposed_fix_group_override
Dec 8, 2020
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ out/* | |
logs/* | ||
|
||
### Kafka HQ ### | ||
src/**/*-*.yml | ||
src/main/*-*.yml | ||
connects-plugins/ | ||
|
||
### Docs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
package org.akhq.configs; | ||
|
||
import io.micronaut.context.annotation.ConfigurationProperties; | ||
import io.micronaut.core.convert.format.MapFormat; | ||
import lombok.Data; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@ConfigurationProperties("akhq.security") | ||
@Data | ||
public class SecurityProperties { | ||
private List<BasicAuth> basicAuth = new ArrayList<>(); | ||
private List<Group> groups; | ||
private String defaultGroup; | ||
|
||
@MapFormat(transformation = MapFormat.MapTransformation.FLAT) | ||
private Map<String, Group> groups = new HashMap<>(); | ||
|
||
@PostConstruct | ||
public void init() { | ||
groups.entrySet().forEach(entry -> entry.getValue().setName(entry.getKey())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/java/org/akhq/configs/SecurityPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.akhq.configs; | ||
|
||
import io.micronaut.context.ApplicationContext; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.platform.commons.util.CollectionUtils; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class SecurityPropertiesTest { | ||
|
||
@Test | ||
void shouldReturnAllBasicGroups() { | ||
ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class); | ||
SecurityProperties securityProperties = ctx.getBean(SecurityProperties.class); | ||
|
||
assertEquals( | ||
CollectionUtils.toSet(new String[] {"admin", "limited", "operator", "no-filter"}), | ||
securityProperties.getGroups().keySet() | ||
); | ||
|
||
ctx.close(); | ||
} | ||
|
||
@Test | ||
void shouldReturnAllBasicPlusConfiguredGroups() { | ||
ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class, "extragroups"); | ||
SecurityProperties securityProperties = ctx.getBean(SecurityProperties.class); | ||
|
||
assertEquals( | ||
CollectionUtils.toSet(new String[] {"admin", "limited", "operator", "no-filter", "extra", "another"}), | ||
securityProperties.getGroups().keySet() | ||
); | ||
|
||
ctx.close(); | ||
} | ||
|
||
@Test | ||
void shouldOverrideBasicGroups() { | ||
ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class, "overridegroups"); | ||
SecurityProperties securityProperties = ctx.getBean(SecurityProperties.class); | ||
|
||
assertEquals( | ||
CollectionUtils.toSet(new String[] {"admin", "limited", "operator", "no-filter", "extra"}), | ||
securityProperties.getGroups().keySet() | ||
); | ||
assertEquals( | ||
Collections.singletonList("topic/read"), | ||
securityProperties.getGroups().get("admin").roles | ||
); | ||
|
||
ctx.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
akhq: | ||
security: | ||
groups: | ||
extra: | ||
roles: | ||
- topic/read | ||
another: | ||
roles: | ||
- topic/read | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
akhq: | ||
security: | ||
groups: | ||
admin: | ||
roles: | ||
- topic/read | ||
limited: | ||
roles: | ||
- topic/read | ||
extra: | ||
roles: | ||
- topic/read | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor changes here :
And everywhere else.
We need to have a name & a key here because people with LDAP have group case sensitive.
I have a lot of issues about that in the past that lead me to go to array (that was not a good idea at the end).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a name property to the default groups with the same name as the key. I also changed the PostConstruct of
SecurityProperties
so that, when a name is not specified in the configuration, the key will be used as default.