@SuppressWarnings("SpringJavaAutowiringInspection")
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private JwtAuthenticationEntryPoint unauthorizedHandler;
@Autowired
private UserDetailsService userDetailsService;
@Autowired
public void configureAuthentication(AuthenticationManagerBuilder
authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder.userDetailsService(userDetailsService);
}
@Bean
public JwtAuthenticationTokenFilter authenticationTokenFilterBean() throws Exception {
return new JwtAuthenticationTokenFilter();
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/test").permitAll()
.antMatchers("/api/**").permitAll()
.anyRequest().authenticated();
httpSecurity.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
}
}
私はSpring Securityの前に実行されるカスタムフィルタを持っています。私はいくつかのURL(/test
のような)をフィルタから除外し、春のセキュリティと他のものを傍受されるようにしたいと思っています(/api/**
のように)。スプリングセキュリティでカスタムフィルタのURLを除外
郵便配達員を使用してlocalhost/test
をテストするとき、私はantMatchers("/test").permitAll()
を持っていてもまだフィルタを通過します。
フィルタをバイパスするにはどうすればよいですか?
@YoungHyunYoo:構成全体を除外したい場合は、antMatcher(antMatchersではなく)を使用することもできます。https://stackoverflow.com/questions/35890540/when-to-use-も参照してください。春のセキュリティ - antmatcher。 – dur