cas4.2.7 maven cas-overlay myeclipse+tomcat部署

参考文献:
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、配置文件路径修改

Paste_Image.png

官网是这么写的,研究了半天原来他写的是linux路径。。。

注:下载的路径是linux的路径,如果是windows环境需要修改路径
我的etc目录如下


Paste_Image.png

(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的路径修改就可以了。。。

Paste_Image.png

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文件,好像需要和证书上的一致)

Paste_Image.png

登录密码在cas.properties中
用户名casuser 密码Mellon


Paste_Image.png

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


Paste_Image.png
 <!-- <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&amp;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" />    

基本上配置好这些就能运行了,不知道有没有遗漏。。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,040评论 6 342
  • 【环境说明】: 本文演示过程在同一个机器上的(也可以在三台实体机器或者三个的虚拟机上),环境如下: windows...
    yljava阅读 13,069评论 3 8
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,314评论 19 139
  • 从三月份找实习到现在,面了一些公司,挂了不少,但最终还是拿到小米、百度、阿里、京东、新浪、CVTE、乐视家的研发岗...
    时芥蓝阅读 42,429评论 11 349
  • 【环境说明】:本文演示过程在同一个机器上的(也可以在三台实体机器或者三个的虚拟机上),环境如下: windows7...
    黄海佳阅读 12,831评论 2 15