Skip to content

Commit

Permalink
BE: Fix double LDAP bean init (#220)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Zabaluev <[email protected]>
  • Loading branch information
alexeyzavyalov and Haarolean authored Apr 2, 2024
1 parent 1d318cb commit c7b4d16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/io/kafbat/ui/KafkaUiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication(exclude = LdapAutoConfiguration.class)
@SpringBootApplication
@EnableScheduling
@EnableAsync
public class KafkaUiApplication {
Expand Down
14 changes: 4 additions & 10 deletions api/src/main/java/io/kafbat/ui/config/auth/LdapSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
import org.springframework.ldap.core.support.LdapContextSource;
Expand All @@ -43,7 +40,6 @@
@Configuration
@EnableWebFluxSecurity
@ConditionalOnProperty(value = "auth.type", havingValue = "LDAP")
@Import(LdapAutoConfiguration.class)
@EnableConfigurationProperties(LdapProperties.class)
@RequiredArgsConstructor
@Slf4j
Expand All @@ -52,18 +48,18 @@ public class LdapSecurityConfig {
private final LdapProperties props;

@Bean
public ReactiveAuthenticationManager authenticationManager(BaseLdapPathContextSource contextSource,
public ReactiveAuthenticationManager authenticationManager(LdapContextSource ldapContextSource,
LdapAuthoritiesPopulator authoritiesExtractor,
AccessControlService acs) {
var rbacEnabled = acs.isRbacEnabled();
BindAuthenticator ba = new BindAuthenticator(contextSource);
BindAuthenticator ba = new BindAuthenticator(ldapContextSource);
if (props.getBase() != null) {
ba.setUserDnPatterns(new String[] {props.getBase()});
}
if (props.getUserFilterSearchFilter() != null) {
LdapUserSearch userSearch =
new FilterBasedLdapUserSearch(props.getUserFilterSearchBase(), props.getUserFilterSearchFilter(),
contextSource);
ldapContextSource);
ba.setUserSearch(userSearch);
}

Expand All @@ -88,8 +84,7 @@ public ReactiveAuthenticationManager authenticationManager(BaseLdapPathContextSo
}

@Bean
@Primary
public BaseLdapPathContextSource contextSource() {
public LdapContextSource ldapContextSource() {
LdapContextSource ctx = new LdapContextSource();
ctx.setUrl(props.getUrls());
ctx.setUserDn(props.getAdminUser());
Expand All @@ -99,7 +94,6 @@ public BaseLdapPathContextSource contextSource() {
}

@Bean
@Primary
public DefaultLdapAuthoritiesPopulator ldapAuthoritiesExtractor(ApplicationContext context,
BaseLdapPathContextSource contextSource,
AccessControlService acs) {
Expand Down

0 comments on commit c7b4d16

Please sign in to comment.