2017-02-15 7 views
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); 
} 

}

ログインパス構成の場合、事前

答えて

0

のおかげで、このようなものを使用することができます。

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin() 
      .usernameParameter("username") // default is username 
      .passwordParameter("password") // default is password 
      .loginPage("/authentication/login") // default is /login with an HTTP get 
      .failureUrl("/authentication/login?failed") // default is /login?error 
      .loginProcessingUrl("/authentication/login/process"); // default is /login 
                    // with an HTTP 
                    // post 
} 

いくつかのパスがconfigure(WebSecurity web)をオーバーライドすることができ、無視する必要がある場合:

@Override 
public void configure(WebSecurity web) throws Exception { 
    web.ignoring().antMatchers("/api/v1/somepath").antMatchers("/static/**"); 
} 
+0

応答をありがとう。私はconfigure(HttpSecurity http)でこれをチェックできるように、(ignoringAntMatchers)のようなクリーンな方法はありますか? – kedar

+0

ant marchersについてはわかりませんが、ログインパスを設定する必要がある場合は、私が返信を編集してそこにdocsの例を追加しました。 –

関連する問題