次の基本的なセキュリティ構成がinMemoryAuthentication()句を適用しないのはなぜですか?
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.httpBasic()
.and()
.authorizeRequests()
.anyRequest().authenticated();
super.configure(http);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("username").password("password");
super.configure(auth);
}
}
アプリケーションの初期化後も、user
Spring自体によって生成されるデフォルトのみがあり、のようなユーザーは存在しませんusername
。
からスーパーメソッドを呼び出さないでくださいvoid configure(AuthenticationManagerBuilder auth)
。それはあなたが無視さdisableLocalConfigureAuthenticationBldr
れるtrue
ことにつながるフラグを設定しますAuthenticationManagerBuilder
。最後に、void configure(AuthenticationManagerBuilder auth)
メソッドは次のようになります。
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("username").password("password").roles("USER");
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加