Ersetzen Sie den Standardauthentifizierungsmanager in Spring Security/Boot

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Ersetzen Sie den Standardauthentifizierungsmanager in Spring Security/Boot

by Anonymous » 11 Apr 2025, 13:08

Der Standardauthentifizierungsmanager in der Spring Security ist ein Providermanager , der in meiner Spring -Boot -App an einen DaoAuthenticationProvider
Delegiert ist.

Code: Select all

DaoAuthenticationProvider

[*]

Code: Select all

TwoFactorAuthenticationProvider
Um dies zu erreichen

Code: Select all

@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfiguration {

@Bean
public AuthenticationManager authenticationManager(UserDetailsService userDetailsService,
PasswordEncoder passwordEncoder,
HttpSecurity http) throws Exception {

var singleFactorProvider = new DaoAuthenticationProvider(passwordEncoder);
singleFactorProvider.setUserDetailsService(userDetailsService);
var twoFactorProvider = new TwoFactorAuthenticationProvider(passwordEncoder, userDetailsService);

return http.getSharedObject(AuthenticationManagerBuilder.class)
.authenticationProvider(singleFactorProvider)
.authenticationProvider(twoFactorProvider)
.build();
}

@Bean
public SecurityFilterChain configure(AuthenticationManager authenticationManager,
HttpSecurity http) throws Exception {
// The real class has additional configuration, but I've omitted it as it's
// not relevant to the question
return http.authenticationManager(authenticationManager).build()
}
}
< /code>
Wenn ich versuche, einen Verweis auf diesen Authentifizierungsmanager zu erhalten, erhalte ich stattdessen die Standardimplementierung. Ich kann den AuthenticationManager 
nicht direkt injizieren, da es eine zirkuläre Bean -Definition verursacht. Stattdessen habe ich
  • die Authentifizierungskonfiguration und aufrufen AuthenticationManager ()
  • Injizieren der Authentifizierungsmanager (/Code>
    Ins "in der Authentifizierungsmanager (/code>
  • " injiziert, in denen die Authentifizierung der Authentifizierung der Authentifizierung der AuthenticationManitern (/codes>

Top