CAS实现单点登录
环境
客户端: www.app1.com
CAS服务器: www.cas-server.com
1.浏览器:发起请求 www.app1.com
2. 客户端:AuthenticationFilter 发现Session为空,ticket为空,重定向并保存service https://www.cas-server.com/cas/login?service=http://www.web.com/app
3. CAS服务器:展示 login 页面,默认提供 username / password 给用户验证
4. 浏览器:输入username / password
5. CAS服务器:对用户输入的 username / password 验证,若通过则生成Ticket Granting Ticket,存入服务器(默认为 Map 类型的 cache),同时将TGT id 作为 content创建 cookie 并发送到浏览器。
6. CAS服务器:通过TGT 生成service ticket. 重定向到 www.app1.com?ticket=ST-xxx
7. 客户端:AuthenticationFilter Filter 发现URL中有 ticket, 跳过 AuthenticationFilter过滤器,到达 Cas20ProxyReceivingTicketValidationFilter过滤器
8. 客户端:Cas20ProxyReceivingTicketValidationFilter 过滤器,使用7处的ticket 与service 作为参数验证
9. 客户端:请求CAS服务器验证https://www.cas-server.com/cas/serviceValidate?ticket=ST-xxx&&service=http://www.app1.com
10. 客户端: 解析 CAS服务器返回信息,生成 assertion (包含 username, validate info 等)
11. 客户端 设置 assertion 为 request 的 _const_cas_assertion_ 属性,同时会将assertion记录到session 中去。
12. 客户端:通过servlet 访问 http://www.web.com/app 服务,结束CAS的验证。
用户已成功登录,非第一次访问:
13. 客户端 通过重定向访问 www.app1.com
14. 客户端 AuthenticationFilter Filter 发现 session 中有Assertion, 结束本过滤器,转移到下一个过滤器 Cas20ProxyReceivingTicketValidationFilter.
15. 客户段 Cas20ProxyReceivingTicketValidationFilter 发现 本次访问的URL 无 ticket,结束本次过滤,转移到下一个过滤器,继续执行以后的 filter,通过servlet 访问 http://www.web.com/app 服务。
用户访问另一个应用:
16. 浏览器:请求www.app2.com
17.客户端:再次被重定向到CAS Server,CAS Server会主动获到TGC cookie
18.CAS服务器:如果 User 持有 TGC 且其还没失效,那么就走Step6 ,达到了 SSO 的效果;如果 TGC 失效,那么用户还是要重新认证 ( 走 Step3) 。