环境
cas-server-4.1.8,cas-client-3.4.0,Java-8,Maven-3,Tomcat-7.0.72
CAS Server 安装
点此进入 CAS 下载列表,选择下载 cas-4.1.8.zip。
解压缩 cas-4.1.8.zip 并进入 cas-server-webapp 目录,在当前目录打开 cmd 并执行安装命令。
mvn -e -ff clean install -Dmaven.test.skip=true
经亲身测试(自己拉的电信12M网络),该安装过程非常漫长,主要因为镜像原因导致依赖包下载非常慢,此过程需静心等待。或直接下载我已经打好包的 cas.war 文件(注:该文件的依赖包版本有稍做修改,此不影响正常使用)。
安装完成后,在 cas-server-webapp/target 目录下可以看到 cas.war 文件,该文件便是 cas server 应用服务的 war 包。
cas server 安全认证是基于 https 的,这里使用 JDK 自带的 keytool 工具生成数字证书,生产环境系统的应用需要到证书提供商处购买证书。证书的生成及 Tomcat 的配置可参考文章:keytool 生成数字证书 – tomcat https 配置 。
首先确保 Tomcat 的 https 可以正常访问,将 cas.war 文件拷贝到 apache-tomcat-7.0.72/webapps 下进行发布,启动 Tomcat,访问 https://www.fanlychie.com:8443/cas。
上图是用火狐浏览器打开的链接,选择高级 -> 添加例外 -> 确认安全例外。
用户名和密码在 apache-tomcat-7.0.72/webapps/cas/WEB-INF/deployerConfigContext.xml 配置文件中,找到并打开该文件,大概在 105 行
<bean id="primaryAuthenticationHandler" class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler"> <property name="users"> <map> <entry key="casuser" value="Mellon" /> </map> </property> </bean>
可以看到默认的用户名是 casuser,密码是 Mellon。
看到上图的页面,表明 cas server 已经部署成功。
CAS Server 配置基于数据库用户认证
回到 cas-4.1.8.zip 解压缩的目录,并进入 cas-server-support-jdbc 目录,在当前目录打开 cmd 并执行安装命令
mvn -e -ff clean install -Dmaven.test.skip=true
安装完成后在 target 目录得到 cas-server-support-jdbc-4.1.8.jar 文件。
将该文件拷贝到 apache-tomcat-7.0.72/webapps/cas/WEB-INF/lib 目录下,并向此目录添加 c3p0-0.9.1.2.jar,mysql-connector-java-5.1.17.jar 两个文件。嫌麻烦的话,点此下载这三个 jar 包的压缩包文件。
再次打开 apache-tomcat-7.0.72/webapps/cas/WEB-INF/deployerConfigContext.xml 文件,大概在第 54 行。
<bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager"> <constructor-arg> <map> <!-- | IMPORTANT | Every handler requires a unique name. | If more than one instance of the same handler class is configured, you must explicitly | set its name to something other than its default name (typically the simple class name). --> <entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" /> <!-- 注销此项 <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" /> --> <!-- 添加此项 --> <entry key-ref="myAuthenticationHandler" value-ref="primaryPrincipalResolver" /> </map> </constructor-arg> <!-- Uncomment the metadata populator to capture the password. <property name="authenticationMetaDataPopulators"> <util:list> <bean class="org.jasig.cas.authentication.CacheCredentialsMetaDataPopulator"/> </util:list> </property> --> <!-- | Defines the security policy around authentication. Some alternative policies that ship with CAS: | | * NotPreventedAuthenticationPolicy - all credential must either pass or fail authentication | * AllAuthenticationPolicy - all presented credential must be authenticated successfully | * RequiredHandlerAuthenticationPolicy - specifies a handler that must au