3
3
import static com .provectus .kafka .ui .config .auth .AbstractAuthSecurityConfig .AUTH_WHITELIST ;
4
4
5
5
import com .provectus .kafka .ui .service .rbac .AccessControlService ;
6
+ import com .provectus .kafka .ui .service .rbac .extractor .RbacLdapAuthoritiesExtractor ;
6
7
import java .util .Collection ;
7
8
import java .util .List ;
8
- import javax . annotation . Nullable ;
9
+ import java . util . Optional ;
9
10
import lombok .RequiredArgsConstructor ;
10
11
import lombok .extern .slf4j .Slf4j ;
11
12
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
12
13
import org .springframework .boot .autoconfigure .ldap .LdapAutoConfiguration ;
13
14
import org .springframework .boot .context .properties .EnableConfigurationProperties ;
15
+ import org .springframework .context .ApplicationContext ;
14
16
import org .springframework .context .annotation .Bean ;
15
17
import org .springframework .context .annotation .Configuration ;
16
18
import org .springframework .context .annotation .Import ;
@@ -50,9 +52,9 @@ public class LdapSecurityConfig {
50
52
51
53
@ Bean
52
54
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 ();
56
58
BindAuthenticator ba = new BindAuthenticator (contextSource );
57
59
if (props .getBase () != null ) {
58
60
ba .setUserDnPatterns (new String [] {props .getBase ()});
@@ -67,7 +69,7 @@ public ReactiveAuthenticationManager authenticationManager(BaseLdapPathContextSo
67
69
AbstractLdapAuthenticationProvider authenticationProvider ;
68
70
if (!props .isActiveDirectory ()) {
69
71
authenticationProvider = rbacEnabled
70
- ? new LdapAuthenticationProvider (ba , ldapAuthoritiesPopulator )
72
+ ? new LdapAuthenticationProvider (ba , authoritiesExtractor )
71
73
: new LdapAuthenticationProvider (ba );
72
74
} else {
73
75
authenticationProvider = new ActiveDirectoryLdapAuthenticationProvider (props .getActiveDirectoryDomain (),
@@ -97,11 +99,24 @@ public BaseLdapPathContextSource contextSource() {
97
99
98
100
@ Bean
99
101
@ 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 ;
105
120
}
106
121
107
122
@ Bean
0 commit comments