Skip to content

BE: RBAC: Impl Active Directory populator #717

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

Merged
merged 8 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,32 @@ public ReactiveAuthenticationManager authenticationManager(LdapContextSource lda
ba.setUserSearch(userSearch);
}

var authenticationProvider = getAuthenticationProvider(authoritiesExtractor, rbacEnabled, ba);

AuthenticationManager am = new ProviderManager(List.of(authenticationProvider));

return new ReactiveAuthenticationManagerAdapter(am);
}

private AbstractLdapAuthenticationProvider getAuthenticationProvider(LdapAuthoritiesPopulator authoritiesExtractor,
boolean rbacEnabled,
BindAuthenticator bindAuthenticator) {
AbstractLdapAuthenticationProvider authenticationProvider;

if (!props.isActiveDirectory()) {
authenticationProvider = rbacEnabled
? new LdapAuthenticationProvider(ba, authoritiesExtractor)
: new LdapAuthenticationProvider(ba);
? new LdapAuthenticationProvider(bindAuthenticator, authoritiesExtractor)
: new LdapAuthenticationProvider(bindAuthenticator);
} else {
authenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(props.getActiveDirectoryDomain(),
props.getUrls()); // TODO Issue #3741
props.getUrls());
authenticationProvider.setUseAuthenticationRequestCredentials(true);
}

if (rbacEnabled) {
authenticationProvider.setUserDetailsContextMapper(new UserDetailsMapper());
}

AuthenticationManager am = new ProviderManager(List.of(authenticationProvider));

return new ReactiveAuthenticationManagerAdapter(am);
return authenticationProvider;
}

@Bean
Expand All @@ -99,6 +107,10 @@ public DefaultLdapAuthoritiesPopulator ldapAuthoritiesExtractor(ApplicationConte
AccessControlService acs) {
var rbacEnabled = acs != null && acs.isRbacEnabled();

if (props.isActiveDirectory()) {
return null;
}

DefaultLdapAuthoritiesPopulator extractor;

if (rbacEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@Slf4j
public class RbacLdapAuthoritiesExtractor extends NestedLdapAuthoritiesPopulator {

private static final Set<Provider> SUPPORTED_PROVIDERS = Set.of(Provider.LDAP, Provider.LDAP_AD);

private final AccessControlService acs;

public RbacLdapAuthoritiesExtractor(ApplicationContext context,
Expand All @@ -36,7 +38,7 @@ protected Set<GrantedAuthority> getAdditionalRoles(DirContextOperations user, St
.stream()
.filter(r -> r.getSubjects()
.stream()
.filter(subject -> subject.getProvider().equals(Provider.LDAP))
.filter(subject -> SUPPORTED_PROVIDERS.contains(subject.getProvider()))
.filter(subject -> subject.getType().equals("group"))
.anyMatch(subject -> ldapGroups.contains(subject.getValue()))
)
Expand Down
Loading