博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单点登录(SSO)入门第二篇--SSO之实现CAS
阅读量:2390 次
发布时间:2019-05-10

本文共 6026 字,大约阅读时间需要 20 分钟。

本文简要介绍了CAS及其实现原理,并对CAS demo环境的搭建进行了描述。

一、CAS简介

CAS(Central Authentication Service) 最初是 Yale 大学发起的一个开源项目,后来成为Jasig 组织下的一个项目,故也成为Jasig CAS。

CAS是一个开源的,提供一个java服务端并且支持多种语言编写的客户端(Java、.Net、PHP等)的单点登录解决方案。

二、CAS实现原理

CAS SSO 访问流程如图所示

1. 访问服务: SSO 客户端发送请求访问应用系统提供的服务资源。
2. 定向认证: SSO 客户端会重定向用户请求到 SSO 服务器。
3. 用户认证:用户身份认证。
4. 发放票据: SSO 服务器会产生一个随机的 Service Ticket 。
5. 验证票据: SSO 服务器验证票据 Service Ticket 的合法性,验证通过后,允许客户端访问服务。
6. 传输用户信息: SSO 服务器验证票据通过后,传输用户认证结果信息给客户端。

三、CAS应用搭建

本次环境搭建选用的版本为服务端cas-server-webapp-4.0.0,客户端cas-client-3.1.10

1、cas服务端

下载cas-server-webapp-4.0.0.zip,解压之,在modules文件夹下找到cas-server-webapp-4.0.0.war

将cas-server-webapp-4.0.0.war放到Tomcat的webapps文件加下,启动Tomcat,如图可访问该cas server

在webapps\cas-server-webapp-4.0.0\WEB-INF下找到deployerConfigContext.xml,

如图可知其默认认证方式为用户名casuser,密码Mellon

在登录页输入给定的用户名密码,如图可登录cas server

以上为http方式,CAS强烈建议使用https方式进行登录验证。为cas server的tomcat配置ssl以支持https登录,如图

2、cas客户端

cas客户端可以是你的任一web应用,只需配置web.xml并添加cas-client的jar支持,即可与cas server交互。

下载cas-client-3.1.10-release.zip,解压之,在modules文件夹下可看到cas-client相关jar包,如图。

本例使用的cas客户端应用是官网下载的mywebapp.war,里面已经配置了web.xml,只需根据我们的环境进行修改。

mywebapp.war放到tomcat的webaps下,启动后在解压的mywebapp lib下放入cas-client相关jar包。

修改后的web.xml如下

[html] 
 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!--  
  3. Copyright (c) 2008, Martin W. Kirst  
  4. All rights reserved.  
  5.   
  6. Redistribution and use in source and binary forms, with or without   
  7. modification, are permitted provided that the following conditions are met:   
  8.   
  9. * Redistributions of source code must retain the above copyright notice,   
  10.   this list of conditions and the following disclaimer.  
  11.   
  12. * Redistributions in binary form must reproduce the above copyright  
  13.   notice, this list of conditions and the following disclaimer in the  
  14.   documentation and/or other materials provided with the distribution.  
  15.   
  16. * Neither the name of the Martin W. Kirst nor the names of its   
  17.   contributors may be used to endorse or promote products derived from   
  18.   this software without specific prior written permission.  
  19.   
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS   
  21. IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   
  22. TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A   
  23. PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER   
  24. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,   
  25. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,   
  26. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   
  28. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING   
  29. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS   
  30. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   
  31. -->  
  32. <web-app id="mywebapp" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  33.       
  34.     <display-name>mywebapp</display-name>  
  35.       
  36.     <description>  
  37.           
  38.         Simple sample, how to use CAS Java Client 3.x.  
  39.         In this sample exists a public area (/)  
  40.         and a private area (/protected/*).   
  41.           
  42.     </description>  
  43.   
  44. <!-- Sign out not yet implemented -->  
  45. <!--   
  46.     <filter>  
  47.         <filter-name>CAS Single Sign Out Filter</filter-name>  
  48.         <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>  
  49.     </filter>  
  50. -->  
  51.   
  52.     <filter>  
  53.         <filter-name>CAS Authentication Filter</filter-name>  
  54.         <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>  
  55.         <init-param>  
  56.             <param-name>casServerLoginUrl</param-name>  
  57.             <param-value>http://localhost:8080/cas/</param-value>  
  58.         </init-param>  
  59.         <init-param>  
  60.             <param-name>serverName</param-name>  
  61.             <param-value>http://localhost:8060</param-value>  
  62.         </init-param>  
  63.         <init-param>  
  64.             <param-name>renew</param-name>  
  65.             <param-value>false</param-value>  
  66.         </init-param>  
  67.         <init-param>  
  68.             <param-name>gateway</param-name>  
  69.             <param-value>false</param-value>  
  70.         </init-param>  
  71.     </filter>  
  72.       
  73.     <filter>  
  74.         <filter-name>CAS Validation Filter</filter-name>  
  75.         <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>  
  76.         <init-param>  
  77.             <param-name>casServerUrlPrefix</param-name>  
  78.             <param-value>http://localhost:8080/cas/</param-value>  
  79.         </init-param>  
  80.         <init-param>  
  81.             <param-name>serverName</param-name>  
  82.             <param-value>http://localhost:8060</param-value>  
  83.         </init-param>  
  84.     </filter>  
  85.       
  86.     <filter>  
  87.         <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>  
  88.         <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>  
  89.     </filter>  
  90.       
  91.     <filter>  
  92.         <filter-name>CAS Assertion Thread Local Filter</filter-name>  
  93.         <filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>  
  94.     </filter>  
  95.   
  96.     <!-- ************************* -->  
  97.   
  98. <!-- Sign out not yet implemented -->  
  99. <!--   
  100.     <filter-mapping>  
  101.         <filter-name>CAS Single Sign Out Filter</filter-name>  
  102.         <url-pattern>/*</url-pattern>  
  103.     </filter-mapping>  
  104. -->  
  105.   
  106.     <filter-mapping>  
  107.         <filter-name>CAS Authentication Filter</filter-name>  
  108.         <url-pattern>/protected/*</url-pattern>  
  109.     </filter-mapping>  
  110.   
  111.     <filter-mapping>  
  112.         <filter-name>CAS Validation Filter</filter-name>  
  113.         <url-pattern>/*</url-pattern>  
  114.     </filter-mapping>  
  115.        
  116.     <filter-mapping>  
  117.         <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>  
  118.         <url-pattern>/*</url-pattern>  
  119.     </filter-mapping>  
  120.       
  121.     <filter-mapping>  
  122.         <filter-name>CAS Assertion Thread Local Filter</filter-name>  
  123.         <url-pattern>/*</url-pattern>  
  124.     </filter-mapping>  
  125.       
  126.     <filter-mapping>  
  127.         <filter-name>CAS Validation Filter</filter-name>  
  128.         <url-pattern>/proxyCallback</url-pattern>     
  129.     </filter-mapping>  
  130.       
  131.     <!--  *********************** -->  
  132.   
  133. <!-- Sign out not yet implemented -->  
  134. <!--   
  135.     <listener>  
  136.         <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>  
  137.     </listener>  
  138. -->  
  139.   
  140.     <!--  *********************** -->  
  141.   
  142.     <welcome-file-list>  
  143.         <welcome-file>index.jsp</welcome-file>  
  144.     </welcome-file-list>  
  145.       
  146. </web-app>  

启动客户端tomcat,如图所示

点击‘got to protected area’则跳入cas server登录页面,输入用户名密码即可进行登录。

客户端tomcat中复制一份mywebapp ,命名为mywebapp2,启动tomcat可看到如mywebapp 登录,则访问mywebapp2的保护页面时,可直接获取登录信息,无需再次进行登录。

四、参考资料

CAS教程

CAS客户端web.xml配置

CAS客户端样例

CAS实现SSO单点登录原理

你可能感兴趣的文章
Five must-know open source SDN controllers
查看>>
Finding Bad Guys with 35 million Flows, 2 Analysts, 5 Minutes and 0 Dollars
查看>>
SANS FOR572 Logstash
查看>>
apt成熟度模型
查看>>
Digital Forensics Framework v0.4.3 available
查看>>
linux设置bond网卡绑定
查看>>
Is your .svn showing (like 3300 other sites)?
查看>>
PCI DSS Update Could Include Virtualization Security(转载自baoz)
查看>>
List of Windows Auto Start Locations
查看>>
OSSIM 2.1 - Multiple security vulnerabilities
查看>>
PHP文件上传源码分析(RFC1867)
查看>>
关于php5.*后的时区问题 date_default_timezone_set ();
查看>>
“Cache-control”常见的取值有private、no-cache、max-age、must-revalidate等
查看>>
安全工具集合
查看>>
Metasploit 3.3 Development Updates
查看>>
Windows Services for UNIX Version 3.5
查看>>
Linux 测试工具
查看>>
Modifying SSH to Capture Login Credentials from Attackers
查看>>
nikto 2.1 coming
查看>>
How to own a Windows Domain
查看>>