参考文献:
cas官网:https://apereo.github.io/cas/4.2.x/index.html
http://www.iwooto.com/2016/11/06/CAS4.2.7%E5%8D%95%E7%82%B9%E7%99%BB%E5%BD%95/
http://blog.csdn.net/frankcheng5143/article/details/52371154
http://blog.csdn.net/dotuian/article/details/9311109
http://www.cnblogs.com/secsea/p/5177284.html
1、下载maven3.3版本并在myeclipse中配置
2、下载cas-overlay,下载地址:https://github.com/apereo/cas-overlay-template/tree/4.2
3、myeclipse导入maven项目
如果网慢可以把下边的注释掉,用阿里的仓库
<repositories>
<repository>
<id>sonatype-releases</id>
<url>http://oss.sonatype.org/content/repositories/releases/</url>
</repository>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>shibboleth-releases</id>
<url>https://build.shibboleth.net/nexus/content/repositories/releases</url>
</repository>
</repositories>
阿里仓库中没有
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<version>${cas.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
我是自己下的war包放到本地仓库。。。
4、配置文件路径修改
官网是这么写的,研究了半天原来他写的是linux路径。。。
注:下载的路径是linux的路径,如果是windows环境需要修改路径
我的etc目录如下
(1)propertyFileConfigurer.xml中修改casProperties路径
<util:properties id="casProperties" location="file:D:\hao\app-maven\cas-overlay-template-4.2\etc\cas\cas.properties" />
(2)pom中修改log4j2.xml路径
将下面的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warName>cas</warName>
<overlays>
<overlay>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<excludes>
<exclude>WEB-INF/cas.properties</exclude>
<exclude>WEB-INF/classes/log4j2.xml</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
修改为:(如果不修改,myeclipse导入后会有错误提示,不知道为什么。。。)
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<version>3.0</version>
<warName>cas</warName>
<overlays>
<overlay>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<excludes>
<exclude>WEB-INF/cas.properties</exclude>
<exclude>WEB-INF/classes/log4j2.xml</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
修改的pom文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd ">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-overlay</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>com.rimerosolutions.maven.plugins</groupId>
<artifactId>wrapper-maven-plugin</artifactId>
<version>0.0.4</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<version>3.0</version>
<warName>cas</warName>
<overlays>
<overlay>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<excludes>
<exclude>WEB-INF/cas.properties</exclude>
<exclude>WEB-INF/classes/log4j2.xml</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${maven-jetty-plugin.version}</version>
<configuration>
<jettyXml>${basedir}/etc/jetty/jetty.xml,${basedir}/etc/jetty/jetty-ssl.xml,${basedir}/etc/jetty/jetty-https.xml</jettyXml>
<systemProperties>
<systemProperty>
<name>org.eclipse.jetty.annotations.maxWait</name>
<value>240</value>
</systemProperty>
</systemProperties>
<webApp>
<contextPath>/cas</contextPath>
<overrideDescriptor>${basedir}/etc/jetty/web.xml</overrideDescriptor>
</webApp>
<webAppConfig>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
</webAppConfig>
<jvmArgs>-Dlog4j.configurationFile=${basedir}/etc/cas/log4j2.xml -Xdebug
-Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n</jvmArgs>
</configuration>
</plugin>
</plugins>
<finalName>cas</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<version>${cas.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-support-jdbc</artifactId>
<version>${cas.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
</dependencies>
<properties>
<cas.version>4.2.7</cas.version>
<maven-jetty-plugin.version>9.3.6.v20151106</maven-jetty-plugin.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>sonatype-releases</id>
<url>http://oss.sonatype.org/content/repositories/releases/</url>
</repository>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>shibboleth-releases</id>
<url>https://build.shibboleth.net/nexus/content/repositories/releases</url>
</repository>
</repositories>
</project>
5、生成证书
生成证书的方法就不写了,说一下配置
参考文献里有个哥们jetty的配置没搞定,用的tomcat,我发现把jetty-ssl.xml的路径按tomcat的路径修改就可以了。。。
cas-overlay上这个解释没用,按tomcat的路径和密码配置就可以。。。
jetty需要修改jetty-ssl.xml文件
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
<Set name="KeyStorePath"><Property name="jetty.ssl.keystore.path" default="D:\j2ee\apache-tomcat-7.0.55\key\.keystore" /></Set>
<Set name="KeyStorePassword"><Property name="jetty.ssl.keystore.password" default="123456" /></Set>
<Set name="KeyManagerPassword"><Property name="jetty.ssl.keymanager.password" default="123456" /></Set>
<Set name="TrustStorePath"><Property name="jetty.ssl.truststore.path" default="D:\j2ee\apache-tomcat-7.0.55\key\.keystore" /></Set>
<Set name="TrustStorePassword"><Property name="jetty.ssl.truststore.password" default="123456" /></Set>
</New>
tomcat的配置配置比较简单就不写了。
6、运行
通过jetty:
myeclipse中 maven build 执行 clean package 进行打包
然后执行jetty:run-forked运行
通过tomcat:
将cas-overlay部署到tomcat上就可以运行,jetty不会弄断点调试。。所以我用tomcat部署测试。。。
访问https://cas.server.com:8443/cas 就能进入登录页面(cas.server.com这个地址是我改的host文件,好像需要和证书上的一致)
登录密码在cas.properties中
用户名casuser 密码Mellon
7、通过数据库访问
修改cas.properties
# accept.authn.users=casuser::Mellon
cas.jdbc.authn.query.sql= select password from ti_user where user_name = ?
cas.authn.password.encoding.char=UTF-8
cas.authn.password.encoding.alg=MD5
修改deployerConfigContext.xml
<!-- <alias name="acceptUsersAuthenticationHandler" alias="primaryAuthenticationHandler" /> -->
<alias name="defaultPasswordEncoder" alias="passwordEncoder" />
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost:3306/cas?useUnicode=true&characterEncoding=utf8"
p:user="root"
p:password=""
p:initialPoolSize="6"
p:minPoolSize="6"
p:maxPoolSize="18"
p:maxIdleTimeExcessConnections="120"
p:checkoutTimeout="10000"
p:acquireIncrement="6"
p:acquireRetryAttempts="5"
p:acquireRetryDelay="2000"
p:idleConnectionTestPeriod="30"
p:preferredTestQuery="select 1" />
<alias name="queryDatabaseAuthenticationHandler" alias="primaryAuthenticationHandler" />
<alias name="dataSource" alias="queryDatabaseDataSource" />
基本上配置好这些就能运行了,不知道有没有遗漏。。。