33import static com .provectus .kafka .ui .config .auth .AbstractAuthSecurityConfig .AUTH_WHITELIST ;
44
55import com .provectus .kafka .ui .service .rbac .AccessControlService ;
6+ import com .provectus .kafka .ui .service .rbac .extractor .RbacLdapAuthoritiesExtractor ;
67import java .util .Collection ;
78import java .util .List ;
8- import javax . annotation . Nullable ;
9+ import java . util . Optional ;
910import lombok .RequiredArgsConstructor ;
1011import lombok .extern .slf4j .Slf4j ;
1112import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
1213import org .springframework .boot .autoconfigure .ldap .LdapAutoConfiguration ;
1314import org .springframework .boot .context .properties .EnableConfigurationProperties ;
15+ import org .springframework .context .ApplicationContext ;
1416import org .springframework .context .annotation .Bean ;
1517import org .springframework .context .annotation .Configuration ;
1618import org .springframework .context .annotation .Import ;
@@ -50,9 +52,9 @@ public class LdapSecurityConfig {
5052
5153 @ Bean
5254 public ReactiveAuthenticationManager authenticationManager (BaseLdapPathContextSource contextSource ,
53- LdapAuthoritiesPopulator ldapAuthoritiesPopulator ,
54- @ Nullable AccessControlService acs ) {
55- var rbacEnabled = acs != null && acs .isRbacEnabled ();
55+ LdapAuthoritiesPopulator authoritiesExtractor ,
56+ AccessControlService acs ) {
57+ var rbacEnabled = acs .isRbacEnabled ();
5658 BindAuthenticator ba = new BindAuthenticator (contextSource );
5759 if (props .getBase () != null ) {
5860 ba .setUserDnPatterns (new String [] {props .getBase ()});
@@ -67,7 +69,7 @@ public ReactiveAuthenticationManager authenticationManager(BaseLdapPathContextSo
6769 AbstractLdapAuthenticationProvider authenticationProvider ;
6870 if (!props .isActiveDirectory ()) {
6971 authenticationProvider = rbacEnabled
70- ? new LdapAuthenticationProvider (ba , ldapAuthoritiesPopulator )
72+ ? new LdapAuthenticationProvider (ba , authoritiesExtractor )
7173 : new LdapAuthenticationProvider (ba );
7274 } else {
7375 authenticationProvider = new ActiveDirectoryLdapAuthenticationProvider (props .getActiveDirectoryDomain (),
@@ -97,11 +99,24 @@ public BaseLdapPathContextSource contextSource() {
9799
98100 @ Bean
99101 @ Primary
100- public LdapAuthoritiesPopulator ldapAuthoritiesPopulator (BaseLdapPathContextSource contextSource ) {
101- var authoritiesPopulator = new DefaultLdapAuthoritiesPopulator (contextSource , props .getGroupFilterSearchBase ());
102- authoritiesPopulator .setRolePrefix ("" );
103- authoritiesPopulator .setConvertToUpperCase (false );
104- return authoritiesPopulator ;
102+ public DefaultLdapAuthoritiesPopulator ldapAuthoritiesExtractor (ApplicationContext context ,
103+ BaseLdapPathContextSource contextSource ,
104+ AccessControlService acs ) {
105+ var rbacEnabled = acs != null && acs .isRbacEnabled ();
106+
107+ DefaultLdapAuthoritiesPopulator extractor ;
108+
109+ if (rbacEnabled ) {
110+ extractor = new RbacLdapAuthoritiesExtractor (context , contextSource , props .getGroupFilterSearchBase ());
111+ } else {
112+ extractor = new DefaultLdapAuthoritiesPopulator (contextSource , props .getGroupFilterSearchBase ());
113+ }
114+
115+ Optional .ofNullable (props .getGroupFilterSearchFilter ()).ifPresent (extractor ::setGroupSearchFilter );
116+ extractor .setRolePrefix ("" );
117+ extractor .setConvertToUpperCase (false );
118+ extractor .setSearchSubtree (true );
119+ return extractor ;
105120 }
106121
107122 @ Bean
0 commit comments