首先下载CAS客户端 , 里面含有必要的 Jar
1: 启动cas 服务器端: 即 启动集成有 cas 的tomcat
2: 新建一个webapp 工程:client1
web.xml 配置如下:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> <init-param> <!-- CAS服务端登录地址 --> <param-name>casServerLoginUrl</param-name> <param-value>https://localhost/cas/</param-value> </init-param> <init-param> <!-- 当前网站域名 --> <param-name>serverName</param-name> <param-value>http://localhost:8080</param-value> </init-param> </filter> <filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
注意: serverName 不需要添加工程的context 上下文(/client1)
导入 jar
cas-client-core-3.1.10.jar
commons-logging-1.1.jar
http://localhost:8080/client1 (error)
3: 启动 tomcat 客户端: (注意客户端不比配置 SSL 支持)
进行访问 index.jsp 页面 ; 但是此时会被 web.xml 中配置的 filter 拦截:
进而跳转到 指定的 casServerLoginUrl 进行验证
然后输入 用户名,密码 如果验证成功, 将会成功跳转到 index.jsp
4: 新建一个 新的web 工程 client2
配置与 第三步一样, 发布到 Tomcat 中
再浏览器中 http://localhost:8080/client2/
此时不要要 验证 直接跳转到 index.jsp 中