Differenz zwischen registerGlobal (), configure (), configureGlobal (), configureGlobalSecurity in Spring security
Ich habe unten drei Codefragmente, die alle dasselbe tun: In-Memory-Authentifizierung erstellen. Wie wirkt es sich auf die Definition in verschiedenen Methodennamen aus?
registerGlobalkonfiguriere configureGlobal configureGlobalSecurityErster
public void registerGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER","ADMIN");
}
}
Das Zweite
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
Dritte
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
Vierte
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
}
UPDATE 1: Eine weitere Sache möchte ich hinzufügen:
ie Methode @configure () ist in der Klasse WebSecurityConfigurerAdapter vorhanden, während andere nicht vorhanden sind.
UPDATE 2:
Ich habe die Methode in meinem Beispielprojekt wie folgt umbenannt und zu meiner Überraschung funktioniert sie und authentifiziert die Benutzer.
Du nennst es irgendetwas und es funktioniert
@Autowired
public void anyMethodName(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
}