设置CAS Filter过滤某些URL

本文介绍了在公司系统中引入CASSSO实现单点登录功能的过程。详细讲述了如何配置CASClient的Filter来拦截请求,并讨论了解决非页面请求被拦截的问题。最终方案是通过创建独立的Servlet来处理数据传输请求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

公司的平台引入了CAS SSO来实现整个系统的单点登录功能,在CAS Client的web.xml中需要配置Filter来拦截外来的请求,实现单点登录、单点登出、权限认证、Ticket认证、设置用户信息等。

其中一个系统是多点部署的,不同的点之间要通过HTTP来传输数据,Server端是用SpringMVC实现的,那么类似这种非通过页面发起的请求就需要排除在CAS的Filter之外。刚开始的思路是在FilterMapping声明时使用正则表达式,但是部署测试无效,通过Google从SOF上得知,Servlet是不支持正则的,如下说明:

No, you can't use a regex there. According to the Java Servlet Specification v2.4 (section srv.11.1), the url-path is interpreted as follows:

•A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.
•A string beginning with a ‘*.’ prefix is used as an extension mapping.
•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.

•All other strings are used for exact matches only.

No regexes. Not even complicated wild-cards.


意思好像是以"/"开头的只能通过前缀过滤,以"*"开头的只能通过后缀过滤,其它字符串只能完全匹配,不支持正则,甚至是复杂的通配符。既然Servlet不支持,那只好另寻它路了。其它还能想到的方法有:
[list]
[*]1. 自定义Filter,然后引用CAS自身的Filter;
[*]2. 将传送数据的请求从MVC中剥离。
[/list]
因为CAS权限验证、登入、登出的功能是分多个Filter拦截的,修改比较复杂,而且有潜在的风险。所以最后选择了写一个单独的Servlet实现接收数据的功能。


=========================================
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值