Я создал собственный фильтр для аутентификации токена AuthenticationTokenFilter, и он расширен OncePerRequestFilter. Я настраиваю некоторые API-интерфейсы как API-интерфейсы белого списка в моем SecurityConfig, для этих Apis из белого списка я пытался обойти свой AuthenticationTokenFilter.
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.BASIC_AUTH_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationTokenFilter authenticationTokenFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().
regexMatchers("^(?!/webjars/).*",
"^(?!/swagger-resources/).*",
"^(?!/swagger-ui.html).*").permitAll().
antMatchers("/healthcheck/ping",
"/user" + ApiMapper.SIGN_IN_API,
"/user" + ApiMapper.FORGET_PASSWORD,
"/user" + ApiMapper.SIGN_OUT_API,
ApiMapper.SWAGGER_RESOURCE,
ApiMapper.FAVICON_ICO,
ApiMapper.APP_ENDPOINTS).permitAll().
anyRequest().authenticated().
and().
// If user isn't authorised to access a path...
exceptionHandling().
// ...redirect them to /403
accessDeniedPage("/403").
and().
anonymous().disable();
http.addFilterBefore(authenticationTokenFilter, BasicAuthenticationFilter.class);
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().
regexMatchers("^(?!/webjars/).*").
regexMatchers("^(?!/swagger-resources/).*").
regexMatchers("^(?!/swagger-ui.html/).*").
antMatchers("/healthcheck/ping",
"/user" + ApiMapper.SIGN_IN_API,
"/user" + ApiMapper.FORGET_PASSWORD,
"/user" + ApiMapper.SIGN_OUT_API,
ApiMapper.SWAGGER_RESOURCE + "/.*",
ApiMapper.FAVICON_ICO,
ApiMapper.APP_ENDPOINTS);
}
}
Я нашел аналогичный ответ здесь, но я уже игнорировал настройку WebSecurity. Итак, почему мне нужно написать то же самое на уровне фильтров.
Где я делаю не так или, может быть, я не в том контексте.
@dur nope, я просто хочу отключить фильтр для определенного API, настроенного в webSecurity.ignoring ().
Да, я знаю. И?




Возможный дубликат stackoverflow.com/questions/39314176/…