Я пытаюсь добавить веб-безопасность в spring, но я не хочу, чтобы фильтр применялся к определенным вещам. Как это делается в java?
И, возможно, есть лучший способ сделать это, потому что я создал настраиваемый фильтр, но это единственный способ, который я могу создать для его создания из-за его зависимостей.
В целом, я хочу сделать следующее:
/resources/**
НЕ ДОЛЖНО проходить фильтр,
/login
(POST) НЕ ДОЛЖЕН проходить фильтр,
все остальное СЛЕДУЕТ пройти фильтр
В рамках различных примеров, которые я нашел через spring, я смог придумать это как для начала, но явно не работает:
@Configuration
@EnableWebSecurity
@Import(MyAppConfig.class)
public class MySecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
public void configure(WebSecurity webSecurity) throws Exception
{
webSecurity.ignoring().antMatchers("/resources/**");
}
@Override
public void configure(HttpSecurity httpSecurity) throws Exception
{
httpSecurity
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.antMatchers("/login").permitAll();
httpSecurity.httpBasic();
httpSecurity.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Bean
@Autowired
public TokenFilterSecurityInterceptor<TokenInfo> tokenInfoTokenFilterSecurityInterceptor(MyTokenUserInfoCache userInfoCache, ServerStatusService serverStatusService, HttpSecurity httpSecurity) throws Exception
{
TokenService<TokenInfo> tokenService = new TokenServiceImpl(userInfoCache);
TokenFilterSecurityInterceptor<TokenInfo> tokenFilter = new TokenFilterSecurityInterceptor<TokenInfo>(tokenService, serverStatusService, "RUN_ROLE");
httpSecurity.addFilter(tokenFilter);
return tokenFilter;
}
}