spring-security - Spring Security如何设置才能避免拦截到静态资源
本文介绍了spring-security - Spring Security如何设置才能避免拦截到静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
继承 FilterSecurityInterceptor 自定义Spring security 拦截器,
但是每次都拦截了css等静态资源,求教如何设置。
@Override
protected void configure(HttpSecurity http) throws Exception {
http
//.addFilterAfter(getMyFilterSecurityInterceptor(), FilterSecurityInterceptor.class)
.authorizeRequests()
//.mvcMatchers(HttpMethod.DELETE, "/delete/**").hasRole("ADMIN")
//.mvcMatchers(HttpMethod.GET, "/model-**").hasRole("ADMIN")
//任何尚未匹配的URL只需要对用户进行身份验证
.anyRequest().authenticated()
.and()
//登录地址,成功跳转地址,登录失败地址
.formLogin().loginPage("/login")
.defaultSuccessUrl("/", true)
.failureUrl("/login?error")
//授予所有用户以上地址的访问权限
.permitAll();
//设置可以iframe访问
http.headers().frameOptions().sameOrigin();
}
解决方案
可以再重写下面的方法(不影响你之前写的代码)
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/druid/**");
//可以仿照上面一句忽略静态资源
}
这篇关于spring-security - Spring Security如何设置才能避免拦截到静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文