`
iamlotus
  • 浏览: 106619 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

在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
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics