私のアプリケーションはAPIとブラウザの両方を提供します。私はすべてのカスタムプロバイダーとフィルターでAPIトークン認証を実装しました。設定がブラウザのバージョンを妨害しているようです。複数の認証プロバイダ(API +ブラウザ)を使用したSpringブート設定
私はドキュメントやその他の例を掘り下げた後にどこにも行かないので、解決方法について助言が必要な2つの質問があります。
1) がブラウザから送信されても、私のStatelessAuthenticationFilter
が呼び出されています。私は持っています。リクエストマッチャーを "/ api/**"に指定しました。何故ですか?
2)AuthenticationManager
は2つを登録していません。AuthenticationProvider
これは間違って呼び出されているStatelessAuthenticationFilter
をデバッグした後の私の結論です。あなたが見ることができるように
ここで私は
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
@Order(1)
@Configuration
public static class A extends WebSecurityConfigurerAdapter {
@Autowired
TokenAuthenticationProvider tokenAuthenticationProvider;
@Autowired
ApiEntryPoint apiEntryPoint;
@Override
protected void configure(HttpSecurity http) throws Exception {
StatelessAuthenticationFilter filter = new StatelessAuthenticationFilter();
AntPathRequestMatcher requestMatcher = new AntPathRequestMatcher("/api/**");
filter.setRequiresAuthenticationRequestMatcher(requestMatcher);
filter.setAuthenticationManager(super.authenticationManager());
http.csrf().disable()
.exceptionHandling().authenticationEntryPoint(apiEntryPoint)
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(tokenAuthenticationProvider);
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/api/user/register");
}
}
@Configuration
public static class B extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(new DaoAuthenticationProvider());
}
}
}
を持っている設定クラスだ、Bクラスが何も指定されていない、まだ私はローカルホストにアクセスするとき:8080 StatelessAuthenticationFilterが呼び出されます。ここで何が起こっているのですか?