第二步 客户端web应用程序集成CAS
1. 从官网下载CAS Client, 将客户端的jar,
cas-client-core-3.2.1.jar commons-logging-1.1.jar 引入到web应用程序的classpath中
2 .配置web.xml文件, 主要是添加过滤器拦截通信, 下面的实例代码, 假设web应用程序的端口是8888
原因:
4、测试是否会跳转到cas验证页面,以及登录成功后会不会回到原页面
5、只要在系统的登出事件中, 将URL访问地址指向CAS服务登出的servlet, 就可以了。http://CAS服务器IP:8080/cas/logout
<!-- CAS 单点登录(SSO) 过滤器配置 (start) -->
<!-- 该过滤器用于实现单点登出功能。-->
<filter>
<filter-name>CAS Single Sign Out Filter</filter-name>
<filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CAS Single Sign Out Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- CAS: 用于单点退出 -->
<listener>
<listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
</listener>
<!-- 该过滤器负责用户的认证工作,必须启用它 -->
<filter>
<filter-name>CASFilter</filter-name>
<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<!-- 下面的URL是Cas服务器的登录地址 -->
<param-value>http://localhost:8888/cas-server/login</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<!-- 下面的URL是具体某一个应用的访问地址 -->
<param-value>http://localhost:8888/</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 该过滤器负责对Ticket的校验工作,必须启用它 -->
<filter>
<filter-name>CAS Validation Filter</filter-name>
<filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
<init-param>
<param-name>redirectAfterValidation</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>casServerUrlPrefix</param-name>
<!-- 下面的URL是Cas服务器的认证地址 -->
<param-value>http://localhost:8888/cas-server</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<!-- 下面的URL是具体某一个应用的访问地址 -->
<param-value>http://localhost:8888/</param-value>
</init-param>
<init-param>
<param-name>renew</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>gateway</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3、启动报错如下
java.lang.RuntimeException: java.io.FileNotFoundException: https://localhost:8443/serviceValidate?ticket=ST-1-1HUXO9iETnaNI2jbuvqK-cas01.example.org&service=http%3A%2F%2Flocalhost%3A8080%2FCasClient%2FIndex.jsp
org.jasig.cas.client.util.CommonUtils.getResponseFromServer(CommonUtils.java:328)
org.jasig.cas.client.util.CommonUtils.getResponseFromServer(CommonUtils.java:291)
org.jasig.cas.client.validation.AbstractCasProtocolUrlBasedTicketValidator.retrieveResponseFromServer(AbstractCasProtocolUrlBasedTicketValidator.java:32)
org.jasig.cas.client.validation.AbstractUrlBasedTicketValidator.validate(AbstractUrlBasedTicketValidator.java:187)
org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:164)
org.jasig.cas.client.authentication.AuthenticationFilter.doFilter(AuthenticationFilter.java:102)
原因:
4、测试是否会跳转到cas验证页面,以及登录成功后会不会回到原页面
5、只要在系统的登出事件中, 将URL访问地址指向CAS服务登出的servlet, 就可以了。http://CAS服务器IP:8080/cas/logout