Eclipse配置CAS client

1.新建一个Maven项目

Eclipse配置CAS client

2.Next,选择

Eclipse配置CAS client

3.输入group id 和 artifact id -->  Finish

4.项目创建完成的目录结构

Eclipse配置CAS client

编辑pom.xml文件,写上依赖

Eclipse配置CAS client

注意把servlet-api依赖给去掉了,因为Tomcat库中已经有了这个jar包,不去掉会导致冲突,程序无法正常运行。

Eclipse配置CAS client不去掉servlet-api依赖的库,可以看到两个包冲突了。

5.配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<display-name>Archetype Created Web Application</display-name> <!-- 单点退出 -->
<listener>
<listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
</listener>
<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> <!-- 该filter负责对请求进行登录验证拦截 -->
<filter>
<filter-name>CAS Authentication Filter</filter-name>
<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<param-value>https://rs-pc:8443/cas-server-webapp-3.5.2.1/login</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://rs-pc:8080</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CAS Authentication Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 该filter负责对请求参数ticket进行验证 -->
<filter>
<filter-name>CAS Validation Filter</filter-name>
<filter-class>org.jasig.cas.client.validation.Cas10TicketValidationFilter</filter-class>
<init-param>
<param-name>casServerUrlPrefix</param-name>
<param-value>https://rs-pc:8443/cas-server-webapp-3.5.2.1</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://rs-pc:8080</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- HttpServletRequest包裹类,支持getUserPrincipal,getRemoteUser方法取得用户信息 -->
<filter>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 把Assertion信息放在ThreadLocal变量中,不在web层也能获取当前登录信息 -->
<filter>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

7.让客户端信任服务端生成的证书,首先将服务端生成的证书casserver.cer文件,复制到$JAVA_HOME/Jre/lib/security下,以管理员方式运行cmd,切换到$JAVA_HOME/Jre/lib/security目录下执行命令:

keytool -import -trustcacerts -alias casclient -storepass changeit -file casserver.cer -keystore cacerts

提示是否导入证书,输入y,回车即可。

8.右键项目Run As -> Run on Server

Eclipse配置CAS client

要将(Cas Server也运行起来)

上一篇:别再搞混了,数据库≠数据仓库


下一篇:[原]基于CAS实现单点登录(SSO):cas client端的退出问题