-
-
Notifications
You must be signed in to change notification settings - Fork 216
Issues/300: rbac now supports regex for values #648
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
Closed
francoisvandenplas
wants to merge
5
commits into
kafbat:main
from
francoisvandenplas:issues/300-regex-for-rbac
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bd2c6fd
Issues/300: rbac now supports regex for values
33b4a54
Issues/300: fix checkstyle
f15fc92
Issues/300: Other extractors handle regex as values.
1c47f7c
Issues/300: Log message now reflects the new matching strategy
d42b88a
Merge branch 'main' into issues/300-regex-for-rbac
francoisvandenplas 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
api/src/test/java/io/kafbat/ui/config/ProviderAuthorityExtractorTest.java
This file contains hidden or 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,68 @@ | ||
| package io.kafbat.ui.config; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import io.kafbat.ui.config.auth.OAuthProperties; | ||
| import io.kafbat.ui.model.rbac.Role; | ||
| import io.kafbat.ui.service.rbac.AccessControlService; | ||
| import io.kafbat.ui.service.rbac.extractor.OauthAuthorityExtractor; | ||
| import io.kafbat.ui.service.rbac.extractor.ProviderAuthorityExtractor; | ||
| import io.kafbat.ui.util.AccessControlServiceMock; | ||
| import java.io.InputStream; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import lombok.SneakyThrows; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.security.core.authority.AuthorityUtils; | ||
| import org.springframework.security.oauth2.core.user.DefaultOAuth2User; | ||
| import org.springframework.security.oauth2.core.user.OAuth2User; | ||
| import org.yaml.snakeyaml.Yaml; | ||
| import org.yaml.snakeyaml.introspector.BeanAccess; | ||
|
|
||
| public class ProviderAuthorityExtractorTest { | ||
|
|
||
|
|
||
| private final AccessControlService accessControlService = new AccessControlServiceMock().getMock(); | ||
| Yaml yaml; | ||
| ProviderAuthorityExtractor extractor; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| yaml = new Yaml(); | ||
| yaml.setBeanAccess(BeanAccess.FIELD); | ||
| extractor = new OauthAuthorityExtractor(); | ||
|
|
||
| InputStream rolesFile = this.getClass() | ||
| .getClassLoader() | ||
| .getResourceAsStream("roles_definition.yaml"); | ||
|
|
||
| Role[] roleArray = yaml.loadAs(rolesFile, Role[].class); | ||
| when(accessControlService.getRoles()).thenReturn(List.of(roleArray)); | ||
|
|
||
| } | ||
|
|
||
| @SneakyThrows | ||
| @Test | ||
| void extractAuthoritiesFromRegex() { | ||
|
|
||
| OAuth2User oauth2User = new DefaultOAuth2User( | ||
| AuthorityUtils.createAuthorityList("SCOPE_message:read"), | ||
| Map.of("role_definition", Set.of("ROLE-ADMIN", "ANOTHER-ROLE"), "user_name", "[email protected]"), | ||
| "user_name"); | ||
|
|
||
| HashMap<String, Object> additionalParams = new HashMap<>(); | ||
| OAuthProperties.OAuth2Provider provider = new OAuthProperties.OAuth2Provider(); | ||
| provider.setCustomParams(Map.of("roles-field", "role_definition")); | ||
| additionalParams.put("provider", provider); | ||
|
|
||
| Set<String> roles = extractor.extract(accessControlService, oauth2User, additionalParams).block(); | ||
|
|
||
| assertEquals(Set.of("viewer", "admin"), roles); | ||
|
|
||
| } | ||
|
|
||
| } |
This file contains hidden or 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,34 @@ | ||
| - name: 'admin' | ||
| subjects: | ||
| - provider: 'OAUTH' | ||
| value: 'ROLE-[A-Z]+' | ||
| type: 'role' | ||
| clusters: | ||
| - local | ||
| - remote | ||
| permissions: | ||
| - resource: APPLICATIONCONFIG | ||
| actions: [ all ] | ||
| - name: 'viewer' | ||
| subjects: | ||
| - provider: 'LDAP' | ||
| value: 'CS-XXX' | ||
| type: 'kafka-viewer' | ||
| - provider: 'OAUTH' | ||
| value: '.*@kafka.com' | ||
| type: 'user' | ||
| clusters: | ||
| - remote | ||
| permissions: | ||
| - resource: APPLICATIONCONFIG | ||
| actions: [ all ] | ||
| - name: 'editor' | ||
| subjects: | ||
| - provider: 'OAUTH' | ||
| value: 'ROLE_EDITOR' | ||
| type: 'role' | ||
| clusters: | ||
| - local | ||
| permissions: | ||
| - resource: APPLICATIONCONFIG | ||
| actions: [ all ] |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.