-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Impl AD role extractor, refactor configs
- Loading branch information
Showing
3 changed files
with
103 additions
and
56 deletions.
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
47 changes: 47 additions & 0 deletions
47
...ain/java/io/kafbat/ui/service/rbac/extractor/RbacActiveDirectoryAuthoritiesExtractor.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,47 @@ | ||
package io.kafbat.ui.service.rbac.extractor; | ||
|
||
import io.kafbat.ui.model.rbac.Role; | ||
import io.kafbat.ui.model.rbac.provider.Provider; | ||
import io.kafbat.ui.service.rbac.AccessControlService; | ||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.ldap.core.DirContextOperations; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.ldap.authentication.ad.DefaultActiveDirectoryAuthoritiesPopulator; | ||
import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator; | ||
|
||
@Slf4j | ||
public class RbacActiveDirectoryAuthoritiesExtractor implements LdapAuthoritiesPopulator { | ||
|
||
private final DefaultActiveDirectoryAuthoritiesPopulator populator = new DefaultActiveDirectoryAuthoritiesPopulator(); | ||
private final AccessControlService acs; | ||
|
||
public RbacActiveDirectoryAuthoritiesExtractor(ApplicationContext context) { | ||
this.acs = context.getBean(AccessControlService.class); | ||
} | ||
|
||
@Override | ||
public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) { | ||
var adGroups = populator.getGrantedAuthorities(userData, username) | ||
.stream() | ||
.map(GrantedAuthority::getAuthority) | ||
.peek(group -> log.trace("Found AD group [{}] for user [{}]", group, username)) | ||
.collect(Collectors.toSet()); | ||
|
||
return acs.getRoles() | ||
.stream() | ||
.filter(r -> r.getSubjects() | ||
.stream() | ||
.filter(subject -> subject.getProvider().equals(Provider.LDAP_AD)) | ||
.filter(subject -> subject.getType().equals("group")) | ||
.anyMatch(subject -> adGroups.contains(subject.getValue())) | ||
) | ||
.map(Role::getName) | ||
.peek(role -> log.trace("Mapped role [{}] for user [{}]", role, username)) | ||
.map(SimpleGrantedAuthority::new) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
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