我的代码地址:https://gitee.com/mac_paas/cas-server-webapp-4.0.7

u=1828005992,167256379&fm=26&gp=0.jpg

1、首先说为什么要使用这个版本

其一、5.0以后的版本要使用JDK8; 其二、4.2.x开始是gradle构建,不太熟; 其三、4.1.x和4.2.x启动后360浏览器急速和兼容模式登录状态不共享(原因不知,未深究); 其四、4.0.x及以下版本我熟悉,版本越高变化越大;

2、下载cas-server-webapp-4.0.7

https://github.com/apereo/cas/releases/tag/v4.0.7

下载源码:并拿出cas-server-webapp

image.png

3、项目导入IDEA

image.png

3.1、POM文件修改

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.maven.plugins</groupId>
  5. <artifactId>maven-war-plugin</artifactId>
  6. <configuration>
  7. <warName>cas</warName>
  8. <webResources>
  9. <resource>
  10. <directory>${basedir}/src/main/webapp/WEB-INF</directory>
  11. <filtering>true</filtering>
  12. <targetPath>WEB-INF</targetPath>
  13. <includes>
  14. <include>**/web.xml</include>
  15. </includes>
  16. </resource>
  17. </webResources>
  18. </configuration>
  19. </plugin>
  20. <!--增加跳过代码检查,或者添加checkstyle文件-->
  21. <plugin>
  22. <groupId>org.apache.maven.plugins</groupId>
  23. <artifactId>maven-checkstyle-plugin</artifactId>
  24. <configuration>
  25. <skip>true</skip>
  26. </configuration>
  27. </plugin>
  28. </plugins>
  29. </build>
  30. <!--删除下面配置-->
  31. <!--<properties>
  32. <cs.dir>${project.parent.basedir}</cs.dir>
  33. </properties>-->

3.2、添加licensing文件

WHY?不添加打包报错

Failed to execute goal com.mycila.maven-license-plugin:maven-license-plugin:1.9.0:check (default) on project cas-server-webapp: Resource E:\IDEAWork\test\hxyFrame\frame-casServer/src/licensing/header.txt not found in file system, classpath or URL: unknown protocol: e -> [Help 1]

获取方式自行百度,或从我分享的代码获取

3.3、中文修改

cas-servlet.xml中设置

<!--设置默认语言为中文 -->
  <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" p:defaultLocale="zh_CN" />

3.4、修改支持HTTP

修改:deployerConfigContext.xml

< bean class = "org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref = "httpClient" />

增加参数 p:requireSecure=”false” ,是否需要安全验证,即 HTTPS , false 为不采用 如下:

< bean class = "org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref = "httpClient" p:requireSecure= "false" />

修改:ticketGrantingTicketCookieGenerator.xml

修改 p:cookieSecure=”true” 为 p:cookieSecure=” false “, 即不需要安全 cookie 如下部分:

< bean id = "ticketGrantingTicketCookieGenerator" class = "org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
       p:cookieSecure = "false"
       p:cookieMaxAge = "-1"
       p:cookieName = "CASTGC"
       p:cookiePath = "/cas" />

修改:warnCookieGenerator.xml

修改 p:cookieSecure=”true” 为 p:cookieSecure=” false “,即不需要安全 cookie 结果如下:

< bean id = "warnCookieGenerator" class = "org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
       p:cookieSecure = "false"
       p:cookieMaxAge = "-1"
       p:cookieName = "CASPRIVACY"
       p:cookiePath = "/cas" />

4、项目启动

项目默认密码

用户名:casuser 密码:Mellon

配置路径(deployerConfigContext.xml)

<bean id="primaryAuthenticationHandler"
      class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler">
  <property name="users">
    <map>
      <entry key="casuser" value="Mellon"/>
    </map>
  </property>
</bean>

访问地址及登录效果

http://localhost:8080/login

image.png
image.png