WEB.xml添加
<filter> <filter-name>myFilterChainProxy</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetBeanName</param-name> <param-value>filterChainProxy</param-value> </init-param> </filter> <filter-mapping> <filter-name>myFilterChainProxy</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
注意红色字体的filterChainProxy,这个为扩展填写的filter chain.
Spring配置文件添加filterChainProxy的配置,参考如下:
<b:bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy"> <filter-chain-map path-type="ant"> <filter-chain pattern="/resource/**" filters="sourceFilterSecurityInterceptor" /> </filter-chain-map> </b:bean>
sourceFilterSecurityInterceptor为配置的普通filter类,可同时配置多个,用逗号分割。
同样filter-chain-map也可以配置多个filter-chain,不用再去修改web.xml了。
注:使用SpringSecurity的场合不要被迷惑,再配多一个DelegatingFilterProxy就好了。大多数权限判定的场合用SpringSecurity就行了。但若遇到不能满足的时候,用自己构造的filter chain有什么不好的呢.
本文介绍如何在Spring Security中使用自定义的FilterChain来实现更灵活的安全控制。通过在WEB.xml中配置DelegatingFilterProxy,并在Spring配置文件中设置filterChainProxy,可以针对不同的URL路径应用特定的过滤器,如sourceFilterSecurityInterceptor。
168万+

被折叠的 条评论
为什么被折叠?



