在web.xml的filter中拦截welcome-page

在用spring security作权限控制的过程中,遇到以下需求:

如果用户已经登录了,那么输入主页url时不要到登录页(index.html),而是直接跳到登录后的主页(main.html)。

由于"/"和"index.html"本来不需要权限,所以在applicationContext-security.xml里是如下配置的

 

<s:intercept-url pattern="/" filters="none" />
<s:intercept-url pattern="/index.html" filters="none" />

 

 本想去掉这两行在自定义的ProcessingFilter里判断如果登录就直接chain.filter(...),结果发现不行。因为如果不用filters="none",那么spring security缺省会匹配到/**,而/**是有权限要求的。

 

没办法,只好自己写一个Filter配到web.xml中实现此功能。当然,这样看上去很不优雅,不过暂时没有更好的解决方法。这里要注意,按照servlet 2.4 spec的说法,对于mapping中的url

 

 写道
• A string containing only the ’/’ character indicates the "default" servlet of
the application. In this case the servlet path is the request URI minus the context
path and the path info is null.

 

 但实际上如果自己写的那个Filter在mapping中配成 

    <filter-mapping>

		<filter-name>directlyNavigateToMainPageWhenAuthenticationSuccessFilter</filter-name>
		<url-pattern>/</url-pattern>
	</filter-mapping>

 

是怎么也捕捉不到"/"和”/index.html“的,解决方法是直接在这里配成welcome-page中的地址

	<filter-mapping>
		<filter-name>directlyNavigateToMainPageWhenAuthenticationSuccessFilter</filter-name>
		<url-pattern>/index.html</url-pattern>
	</filter-mapping>
 

这样就能捕获了。

 

不知道是我对spec理解错误了吗?总觉得 "/"应该可以捕获缺省页的啊。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值