源码下载:http://pan.baidu.com/s/1bniDFD9
1、下载cas-server-3.5.2-release.zip并把cas-server-webapp.war部署到tomcat
2、配置依赖jar包
//spring
compile 'org.springframework:spring-beans:3.0.4.RELEASE'
compile 'org.springframework:spring-core:3.0.4.RELEASE'
compile 'org.springframework:spring-web:3.0.4.RELEASE'
compile 'org.springframework:spring-webmvc:3.0.4.RELEASE'
compile 'org.springframework:spring-context:3.0.4.RELEASE'
compile 'org.springframework:spring-context-support:3.0.4.RELEASE'
//json
compile 'org.codehaus.jackson:jackson-core-lgpl:1.8.1'
compile 'org.codehaus.jackson:jackson-mapper-lgpl:1.8.1'
compile 'commons-fileupload:commons-fileupload:1.3.1'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.4'
//shiro
compile 'org.apache.shiro:shiro-core:1.2.3'
compile 'org.apache.shiro:shiro-web:1.2.3'
compile 'org.apache.shiro:shiro-spring:1.2.3'
compile 'org.apache.shiro:shiro-cas:1.2.3'
//j2ee
compile 'javax.servlet:javax.servlet-api:3.1.0'
//log
compile "org.slf4j:slf4j-log4j12:1.7.5"
//jedis
compile "redis.clients:jedis:2.1.0"
testCompile 'junit:junit:4.11'
3、Shiro 对 cas 集成后,cas client的配置更加简单了。原理就是将casFilter添加到到shiroFilter的filterChain中,在Spring项目中集成Shiro和CAS
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
/shiro-cas= casFilter,anon
/styles/**= anon
/login =anon
/**= user
4、部署多个应用,去除cas的https登录,如果不去除,https的cookie会出问题,导致多个web应用单点登录失败
5、注意事项&成功截图
vim /opt/tomcat7/webapps/ROOT/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml
vim /opt/tomcat7/webapps/ROOT/WEB-INF/deployerConfigContext.xml
修改cas Server端:
/WebRoot/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml 文件:
p:cookieSecure="true" //默认为true,使用https,如果只需要http,修改为false即可 p:cookieMaxAge="-1" p:cookieName="CASTGC" p:cookiePath="/cas" /> 第二个要修改的地方: 修改deployerConfigContext.xml文件,在authenticationHandlers属性中 p:httpClient-ref="httpClient" p:requireSecure="false" /> 这个文件增加属性 p:requireSecure="false" 如果不修改deployerConfigContext.xml会报错误: TicketCreationException: error.authentication.credentials.bad 成功截图