參考文獻(xiàn):
cas官網(wǎng):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導(dǎo)入maven項(xiàng)目
如果網(wǎng)慢可以把下邊的注釋掉,用阿里的倉(cāng)庫(kù)
<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>
阿里倉(cāng)庫(kù)中沒有
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<version>${cas.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
我是自己下的war包放到本地倉(cāng)庫(kù)。。。
4、配置文件路徑修改
官網(wǎng)是這么寫的,研究了半天原來他寫的是linux路徑。。。
注:下載的路徑是linux的路徑,如果是windows環(huán)境需要修改路徑
我的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導(dǎo)入后會(huì)有錯(cuò)誤提示,不知道為什么。。。)
<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、生成證書
生成證書的方法就不寫了,說一下配置
參考文獻(xiàn)里有個(gè)哥們jetty的配置沒搞定,用的tomcat,我發(fā)現(xiàn)把jetty-ssl.xml的路徑按tomcat的路徑修改就可以了。。。
cas-overlay上這個(gè)解釋沒用,按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的配置配置比較簡(jiǎn)單就不寫了。
6、運(yùn)行
通過jetty:
myeclipse中 maven build 執(zhí)行 clean package 進(jìn)行打包
然后執(zhí)行jetty:run-forked運(yùn)行
通過tomcat:
將cas-overlay部署到tomcat上就可以運(yùn)行,jetty不會(huì)弄斷點(diǎn)調(diào)試。。所以我用tomcat部署測(cè)試。。。
訪問https://cas.server.com:8443/cas 就能進(jìn)入登錄頁(yè)面(cas.server.com這個(gè)地址是我改的host文件,好像需要和證書上的一致)
登錄密碼在cas.properties中
用戶名casuser 密碼Mellon
7、通過數(shù)據(jù)庫(kù)訪問
修改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" />
基本上配置好這些就能運(yùn)行了,不知道有沒有遺漏。。。