1717import org .springframework .security .config .annotation .authentication .configuration .AuthenticationConfiguration ;
1818import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
1919import org .springframework .security .config .annotation .web .configuration .WebSecurityCustomizer ;
20- import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
2120import org .springframework .security .config .http .SessionCreationPolicy ;
2221import org .springframework .security .core .userdetails .User ;
2322import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
@@ -34,13 +33,12 @@ public class WebSecurityConfig {
3433
3534 @ Bean
3635 public SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
37- http .csrf (AbstractHttpConfigurer :: disable )
36+ return http .csrf (csrf -> csrf . disable () )
3837 .sessionManagement (
3938 session -> session .sessionCreationPolicy (SessionCreationPolicy .STATELESS ))
4039 .authorizeHttpRequests (auth -> auth .anyRequest ().authenticated ())
41- .httpBasic (withDefaults ());
42-
43- return http .build ();
40+ .httpBasic (withDefaults ())
41+ .build ();
4442 }
4543
4644 @ Bean
@@ -121,16 +119,10 @@ public AuthenticationProvider ldapAuthProvider() {
121119 authPopulator .setSearchSubtree (true );
122120 authPopulator .setIgnorePartialResultException (true );
123121
124- LdapAuthenticationProvider provider =
125- new LdapAuthenticationProvider (
126- new BindAuthenticator (contextSource ) {
127- {
128- setUserDnPatterns (new String [] {ldap_user_dn_pattern });
129- }
130- },
131- authPopulator );
122+ BindAuthenticator bindAuthenticator = new BindAuthenticator (contextSource );
123+ bindAuthenticator .setUserDnPatterns (new String [] {ldap_user_dn_pattern });
132124
133- return provider ;
125+ return new LdapAuthenticationProvider ( bindAuthenticator , authPopulator ) ;
134126 }
135127
136128 @ Bean
@@ -147,16 +139,10 @@ public AuthenticationProvider embeddedLdapAuthProvider() {
147139 authPopulator .setSearchSubtree (true );
148140 authPopulator .setIgnorePartialResultException (true );
149141
150- LdapAuthenticationProvider provider =
151- new LdapAuthenticationProvider (
152- new BindAuthenticator (contextSource ) {
153- {
154- setUserDnPatterns (new String [] {embedded_ldap_user_dn_pattern });
155- }
156- },
157- authPopulator );
142+ BindAuthenticator bindAuthenticator = new BindAuthenticator (contextSource );
143+ bindAuthenticator .setUserDnPatterns (new String [] {embedded_ldap_user_dn_pattern });
158144
159- return provider ;
145+ return new LdapAuthenticationProvider ( bindAuthenticator , authPopulator ) ;
160146 }
161147
162148 @ Bean
@@ -176,12 +162,10 @@ public AuthenticationProvider demoAuthProvider() {
176162 .build ());
177163 }
178164
179- return new DaoAuthenticationProvider () {
180- {
181- setUserDetailsService (manager );
182- setPasswordEncoder (encoder );
183- }
184- };
165+ DaoAuthenticationProvider provider = new DaoAuthenticationProvider ();
166+ provider .setUserDetailsService (manager );
167+ provider .setPasswordEncoder (encoder );
168+ return provider ;
185169 }
186170
187171 @ Bean
0 commit comments