0
JWTでSpring Securityプロジェクトを開発しようとしています。 Spring Security(JWTトークンなし)を使用せずにLogin APIにアクセスしたいです。しかし、以下の設定では、(login apiの場合も)毎回403エラーを出すJWTトークンをチェックしています。JWTによるスプリングセキュリティ
以下は私のWebSecurityConfigです。
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private JwtAuthFilter jwtAuthFilter;
@Autowired
private TokenAuthenticationService jwtAuthenticationProvider;
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(jwtAuthenticationProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/api/v1/login");
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/api/v1/login")
.permitAll()
.and()
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
}
}
ログインパス構成の場合、事前
応答をありがとう。私はconfigure(HttpSecurity http)でこれをチェックできるように、(ignoringAntMatchers)のようなクリーンな方法はありますか? – kedar
ant marchersについてはわかりませんが、ログインパスを設定する必要がある場合は、私が返信を編集してそこにdocsの例を追加しました。 –