【发布时间】:2013-11-23 22:08:50
【问题描述】:
我正在尝试在春季添加网络安全性,但我不希望过滤器应用于某些事情。在java中是怎么做到的?
也许有更好的方法来做到这一点,因为我创建了一个自定义过滤器,但由于它的依赖关系,这是我能想到实例化它的唯一方法。
总的来说,我想做的是这样的:
/resources/** 不应该通过过滤器,
/login (POST) 不应该通过过滤器,
其他一切都应该通过过滤器
通过我在春季发现的各种示例,我能够想出这个作为开始,但它显然不起作用:
@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;
}
}
【问题讨论】:
标签: java spring spring-security