以编程方式禁用Spring Security
我有一个具有spring安全性的web应用程序,默认情况下所有页面都需要授权。在我的情况下,管理员可以在某些时候决定禁用某些页面的安全性或完全禁用它。这怎么能最好地实现?我正在考虑修改FilterChainProxy
,但是我不清楚究竟如何(getFilterChains()
返回一个不可修改的列表)?以编程方式禁用Spring Security
子类DelgatingFilterProxy
和检查标志是否调用委托与否。
然后在您的web.xml中使用该代替用于springSecurityFilterChain
(假设您正在使用命名空间配置)的DelegatingFilterProxy
。例如:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>com.foo.spring.MyDelegatingFilterProxy</filter-class>
</filter>
在你的DelegatingFilterProxy检查标志(例如,系统属性),看看你是否应该委托与否。
class MyDelegatingFilterProxy extends DelegatingFilterProxy {
override def doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) {
if (System.getProperty("skipSpringSecurity" != null) {
// Ignore the DelegatingProxyFilter delegate
chain.doFilter(request, response)
} else {
// Call the delegate
super.doFilter(request, response, chain)
}
}
}
您可以使用相同的技术来使用毯子通配符像<security:intercept-url pattern="/**" access="ROLE_USER" />
然后跳到呼吁下/有一套路径的春季安全过滤器(静态文件等)。
非常感谢,这就是我一直在寻找的东西,它的效果非常好! – kpentchev 2012-03-22 09:27:54
Spring Security如何配置?你可以选择添加一个自定义permissionEvaluator来验证你的条件?
看一看spring-security writing a custom PermissionEvaluator - how to inject a DAO service?
我有一些特定的选民和AuthenticationProvider的,但除此之外,它使用默认的Web应用程序配置' \t \t \t \t \t \t \t security:ht ' – kpentchev 2012-03-21 14:44:33
首先,您的配置看起来很不寻常,因为* everything *似乎受到保护,包括登录页面(通常不是)。 您能解释一下管理员可以禁用页面安全的情况吗?看起来不寻常和有趣的同时。 – 2012-03-21 15:52:36
那么它使用http-basic,因此使用默认的浏览器验证对话框。该应用程序是一种数据库搜索/浏览/服务器,并且由于默认情况下所有内容都受到保护,因此管理员可能需要/决定公开它(例如,由于需要与应用程序通信但不支持身份验证的第三方应用程序) 。 – kpentchev 2012-03-21 17:51:12