CAS 4.0 配置开发手册

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

1    下载

地址http://downloads.jasig.org/

cas-server-4.0.0-release.tar.gz

cas-client-3.3.3-release.tar.gz

2    配置

解压cas-server-4.0.0,将其中module/cas-server-webapp-4.0.0.war复制到Tomcat的webapps目录下,重命名为cas.war,启动Tomcat解开压缩。

2.1 CAS的HTTP模式与HTTPS设置

1)cas\WEB-INF\deployerConfigContext.xml,新增p:requireSecure="false"

    <bean id="proxyAuthenticationHandler"          class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"

          p:httpClient-ref="httpClient" p:requireSecure="false"/>

      2)cas\WEB-INF\spring-configuration

     ticketGrantingTicketCookieGenerator.xml设置p:cookieSecure="false"

warnCookieGenerator.xml设置p:cookieSecure="false"

http://localhost:8080/cas,进入登录页面。

默认用户为casuser/Mellon,登录成功即配置完成。

2.2 设置利用数据库来验证用户

需依赖:c3p0-0.9.1.2.jar,mysql-connector-java-5.1.21.jar,cas-server-support-jdbc-4.0.0.jar

cas\WEB-INF\deployerConfigContext.xml

  1)更换验证方式 

<!--

   <bean id="primaryAuthenticationHandler"

          class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler">

        <property name="users">

            <map>

                <entry key="casuser" value="Mellon"/>

            </map>

        </property>

    </bean>

    -->

   <!-- Define the DB Connection -->

   <bean id="dataSource"

     class="com.mchange.v2.c3p0.ComboPooledDataSource"

     p:driverClass="com.mysql.jdbc.Driver"

     p:jdbcUrl="jdbc:mysql://127.0.0.1:3306/hztraffic?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull"

     p:user="root"

     p:password="root" />

 

     <!-- Define the encode method-->

     <!--<bean id="passwordEncoder" 

       class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder" autowire="byName">     

      <constructor-arg value="MD5"/> 

     </bean> -->

    <bean id="passwordEncoder"

      class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"

      c:encodingAlgorithm="MD5"

      p:characterEncoding="UTF-8" />

 

     <bean id="dbAuthHandler"

      class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"

      p:dataSource-ref="dataSource"

      p:sql="select password from hztraffic.user_data where name=? and used=1"

     p:passwordEncoder-ref="passwordEncoder"/>

     <!-- p:passwordEncoder-ref="passwordEncoder" -->

    2)更换验证Handle

<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="dbAuthHandler" value-ref="primaryPrincipalResolver" />

           <!-- <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" /> -->

            </map>

        </constructor-arg>

http://localhost:8080/cas,进入登录页面。

默认用户为casuser/Mellon,登录成功即配置完成。

3    编译

3.1 Eclipse导入工程

 

3.2 License文件设置

 

Failed goal com.mycila.maven-license-plugin

注意src目录与cas-server-webapp平级,此外,任何关于Sever文件的修改,文件头的License声明需要添加。JSP/JS/CSS,否则编译检测通过不了。

<%--

 

    Licensed to Jasig under one or more contributor license

    agreements. See the NOTICE file distributed with this work

    for additional information regarding copyright ownership.

    Jasig licenses this file to you under the Apache License,

    Version 2.0 (the "License"); you may not use this file

    except in compliance with the License.  You may obtain a

    copy of the License at the following location:

 

      http://www.apache.org/licenses/LICENSE-2.0

 

    Unless required by applicable law or agreed to in writing,

    software distributed under the License is distributed on an

    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

    KIND, either express or implied.  See the License for the

    specific language governing permissions and limitations

    under the License.

 

--%>

4    定制

4.1 登录/登出页面

 

4.2 允许退出后重定向

 

5    接入

5.1 WEB接入

5.1.1 非Spring模式

在Client工程WEB-INF/lib下添加cas-client-core-3.2.1.jar包。

修改web.xml如下:

<!-- ======================== 单点登录/登出 ======================== -->

 

<!-- 该过滤器用于实现单点登出功能,可选配置。 -->

<filter>

   <filter-name>CAS Single Sign Out Filter</filter-name>

   <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>

</filter>

 

<!-- 该过滤器负责用户的认证工作,必须启用它 -->

<filter>

  <filter-name>CAS Authentication Filter</filter-name>

  <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>

  <init-param>

    <param-name>casServerLoginUrl</param-name>

    <param-value>https://localhost:8443/cas/login</param-value>

  </init-param>

  <init-param>

    <param-name>serverName</param-name>

    <param-value>http://localhost:8080</param-value>

  </init-param>

</filter>

 

<!-- 该过滤器负责对Ticket的校验工作,必须启用它 -->

<filter>

    <filter-name>CAS Validation Filter</filter-name>

    <filter-class>org.jasig.cas.client.validation.Cas10TicketValidationFilter</filter-class>

    <init-param>

        <param-name>casServerUrlPrefix</param-name>

        <param-value>https://localhost:8443/cas</param-value>

    </init-param>

    <init-param>

        <param-name>serverName</param-name>

        <param-value>http://localhost:8080</param-value>

    </init-param>

    <init-param>

        <param-name>redirectAfterValidation</param-name>

        <param-value>true</param-value>

    </init-param>

</filter>

 

<!-- 该过滤器负责实现HttpServletRequest请求的包裹,

比如允许开发者通过HttpServletRequestgetRemoteUser()方法获得SSO登录用户的登录名,可选配置。 -->

<filter>

  <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>

  <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>

</filter>

 

<!-- 该过滤器使得开发者可以通过org.jasig.cas.client.util.AssertionHolder来获取用户的登录名。

 比如AssertionHolder.getAssertion().getPrincipal().getName()-->

<filter>

  <filter-name>CAS Assertion Thread Local Filter</filter-name>

  <filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>

</filter>

 

<filter-mapping>

   <filter-name>CAS Single Sign Out Filter</filter-name>

   <url-pattern>/*</url-pattern>

</filter-mapping>

<filter-mapping>

    <filter-name>CAS Authentication Filter</filter-name>

    <url-pattern>/*</url-pattern>

</filter-mapping>

<filter-mapping>

    <filter-name>CAS Validation Filter</filter-name>

    <url-pattern>/*</url-pattern>

</filter-mapping>

<filter-mapping>

    <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>

    <url-pattern>/*</url-pattern>

</filter-mapping>

<filter-mapping>

    <filter-name>CAS Assertion Thread Local Filter</filter-name>

    <url-pattern>/*</url-pattern>

</filter-mapping>

 

<listener>

    <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>

</listener>

<!-- ======================== 单点登录/登出结束 ======================== -->

现在运行Client工程,首次访问任一页面就会跳转到https://localhost:8443/cas/login进行认证。同时,把你的退出链接设置为:https://sso.wsria.com/cas/logout 即可实现单点推出。

5.1.2 Spring方式

引用cas-client-core.jar

Web.xml,注意casSingleSignOutFilter必须位于最前面

<listener>        <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>

    </listener>

<!-- ======================== 单点登录/登出 ======================== -->

    <filter>

        <filter-name>casSingleSignOutFilter</filter-name>

        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

    </filter>

    <filter-mapping>

        <filter-name>casSingleSignOutFilter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

    <filter>

       <filter-name>casAuthenticationFilter</filter-name>

       <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

    </filter>

    <filter-mapping>

       <filter-name>casAuthenticationFilter</filter-name>

       <url-pattern>/*</url-pattern>

    </filter-mapping>

    <filter>

       <filter-name>casTicketValidationFilter</filter-name>

       <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

    </filter>

    <filter-mapping>

       <filter-name>casTicketValidationFilter</filter-name>

       <url-pattern>/*</url-pattern>

    </filter-mapping>

   

    <filter>

       <filter-name>casHttpServletRequestWrapperFilter</filter-name>

       <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

    </filter>

    <filter-mapping>

       <filter-name>casHttpServletRequestWrapperFilter</filter-name>

       <url-pattern>/*</url-pattern>

    </filter-mapping>

   

    <filter>

       <filter-name>casAssertionThreadLocalFilter</filter-name>

       <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

    </filter>

    <filter-mapping>

       <filter-name>casAssertionThreadLocalFilter</filter-name>

       <url-pattern>/*</url-pattern>

    </filter-mapping>

    <!-- ======================== 单点登录/登出结束 ======================== -->

 

appliationContext.xml

<bean id="casSingleSignOutFilter"

        class="org.jasig.cas.client.session.SingleSignOutFilter" />

   

    <bean name="casAuthenticationFilter"

       class="org.jasig.cas.client.authentication.AuthenticationFilter"

       p:casServerLoginUrl="http://localhost:9000/uq-w-cas/login"

       p:renew="false"

       p:gateway="false" p:serverName="http://localhost:8080" />

 

    <bean name="casTicketValidationFilter"

       class="org.jasig.cas.client.validation.Cas10TicketValidationFilter"

       p:serverName="http://localhost:8080"

       p:redirectAfterValidation="true">

       <property name="ticketValidator">

           <bean class="org.jasig.cas.client.validation.Cas10TicketValidator">

              <!-- 对应于casServerUrlPrefix -->

              <constructor-arg index="0" value="http://localhost:9000/uq-w-cas" />

           </bean>

       </property>

    </bean>

 

    <bean id="casHttpServletRequestWrapperFilter"

       class="org.jasig.cas.client.util.HttpServletRequestWrapperFilter" />

   

    <bean id="casAssertionThreadLocalFilter"

        class="org.jasig.cas.client.util.AssertionThreadLocalFilter" />

   页面

<%

   AttributePrincipal  principal= (AttributePrincipal)request.getUserPrincipal();   

   String username = "i am username";

   if(null!=principal){

      username=principal.getName();

   %>

   <h1>登录成功,这是客户端1啊</h1><br/>

   用户名:<%=username %><br/>

   <a href="http://localhost:8989/Casclient2/index.jsp">进入客户端2</a><br/>

  

   <a href="http://localhost:9000/uq-w-cas/logout?service=http://localhost:9000/uq-w-cas/">退出</a><br/

   <%

   }

   %>

5.2 客户端

工程依赖如下:

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

 

import org.apache.http.HttpEntity;

import org.apache.http.HttpResponse;

import org.apache.http.NameValuePair;

import org.apache.http.client.entity.UrlEncodedFormEntity;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.cookie.Cookie;

import org.apache.http.impl.client.DefaultHttpClient;

import org.apache.http.message.BasicNameValuePair;

import org.apache.http.protocol.HTTP;

 

public class CasUtil {

 

    //Cas server address

    static final String server = "http://localhost:9000/cas/login";

 

    public static void main(String[] args) throws IOException {

       //Login and get the cookie

       Cookie cookie = getTicketGrantingTicket(server, "13888888888",

              "13888888888");

       if (cookie != null) {

           System.out.println(cookie);

       }

    }

 

    private static Cookie getTicketGrantingTicket(String server,

           String username, String password) throws IOException {

       DefaultHttpClient client = new DefaultHttpClient();

       HttpPost post = new HttpPost(server);

 

       //Login parameters

       List<NameValuePair> nvps = new ArrayList<NameValuePair>();

       nvps.add(new BasicNameValuePair("username", username));

       nvps.add(new BasicNameValuePair("password", password));

       String[] dynamicPara = doCasLoginRequest(client, server);

       nvps.add(new BasicNameValuePair("lt", dynamicPara[0]));

       nvps.add(new BasicNameValuePair("execution", dynamicPara[1]));

       nvps.add(new BasicNameValuePair("_eventId", "submit"));

       //Font Code

       post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

       try {

           HttpResponse response = client.execute(post);

           HttpEntity entity = response.getEntity();

           if (entity != null) {

              //CASTGC: the default cookie name

              Cookie cookie = getCookieValue(client, "CASTGC");

              entity.consumeContent();

              return cookie;

           }

       } catch (Exception e) {

           e.printStackTrace();

       }

       return null;

    }

 

    private static Cookie getCookieValue(DefaultHttpClient httpclient,

           String name) {

       List<Cookie> cookies = httpclient.getCookieStore().getCookies();

       if (cookies.isEmpty()) {

           return null;

       } else {

           for (int i = 0; i < cookies.size(); i++) {

              Cookie cookie = cookies.get(i);

              if (cookie.getName().equalsIgnoreCase(name)) {

                  return cookie;

              }

           }

       }

       return null;

    }

 

    //Simulate the login action and get the dynamic parameters lt and execution

    private static String[] doCasLoginRequest(DefaultHttpClient httpclient,

           String url) throws IOException {

       String[] result = new String[2];

       HttpGet httpget = new HttpGet(url);

       HttpResponse response = httpclient.execute(httpget);

       HttpEntity entity = response.getEntity();

       BufferedReader rd = new BufferedReader(new InputStreamReader(

              entity.getContent(), "UTF-8"));

       String tempLine = rd.readLine();

       String sLt = "<input type=\"hidden\" name=\"lt\" value=\"";

       String sEx = "<input type=\"hidden\" name=\"execution\" value=\"";

       while (tempLine != null) {

           int iLt = tempLine.indexOf(sLt);

           int iEx = tempLine.indexOf(sEx);

           if (iLt != -1) {

              String s1 = tempLine.substring(iLt + sLt.length());

              int index1 = s1.indexOf("\"");

              if (index1 != -1)

                  result[0] = s1.substring(0, index1);

           }

           if (iEx != -1) {

              String s1 = tempLine.substring(iEx + sEx.length());

              int index1 = s1.indexOf("\"");

              if (index1 != -1)

                  result[1] = s1.substring(0, index1);

           }

           tempLine = rd.readLine();

       }

 

       if (entity != null) {

           entity.consumeContent();

       }

       return result;

    }

 

    //Cookie convert

    private javax.servlet.http.Cookie convertToServletCookie(Cookie cookie) {

       javax.servlet.http.Cookie retCookie = new javax.servlet.http.Cookie(

              cookie.getName(), cookie.getValue());

       retCookie.setComment(cookie.getComment());

       retCookie.setDomain(cookie.getDomain());

       retCookie.setHttpOnly(false);

       retCookie.setSecure(false);

       retCookie.setPath(cookie.getPath());

       retCookie.setVersion(cookie.getVersion());

       retCookie.setMaxAge((int) ((cookie.getExpiryDate().getTime() - System

              .currentTimeMillis()) / 1000));

       return retCookie;

    }

 

}

 

 

部分图片未上传,如有需要,请给我留言。

安装 CAS 服务器 目录[-] 1 CAS 简介2 下载 CAS 服务器3 创建密钥库3.1 生成 keypair3.2 从 keystore 中导出证书3.3 导入证书到 JVM 中4 使 Tomcat 支持 HTTPS5 运行 CAS 服务器 6 部署CAS-Client7 测试验证SSO 1 CAS 简介 CAS 全称为 Central Authentication Service(中央认证服务) 阅读详情

相关推荐

Moodle3.10配置CAS单点登录

有关Moodle的CAS配置以及遇到的bug解决方案。

m0_48978227的博客 1456

cas-server-4.0.0-release与依赖包.zip

cas-server-4.0.0-release与依赖包,CAS实现SSO单点登录-CAS Server搭建,cas-server-4.0.0源码及部署包下载

给硬件工程师的DDR4时序配置避坑指南:从MR0到MR6,手把手教你避开那些手册里没明说的坑

本文为硬件工程师提供DDR4时序配置的实战指南,从MR0到MR6详细解析模式寄存器的关键设置,揭示数据手册未明确说明的陷阱。涵盖CAS延迟、写恢复、ODT配置等核心时序参数,帮助工程师避开常见误区,确保系统稳定性与信号完整性。特别针对DDR4标准规范中的复杂场景提供实用解决方案。

weixin_38168322的博客 695

cas-server-4.0.0-release单点登录源码和war包-原版

原版cas单点登录源码和wa包,原版sso,官网下载太慢,所以特地放到csdn

CAS环境搭建-证书方式(https连接)

一、教程前言   1 教程目的:从头到尾细细道来单点登录服务器及客户端应用的每个步骤  2 单点登录(SSO):请看《CAS简介》  3 本教程使用的SSO服务器是Yelu大学研发的CAS(Central Authentication Server),  4 官网:http://www.jasig.org/cas  5 本教程环境:    .Tomcat7.0.35    .JDK8 ...

a7412605567的博客 466

CAS实现SSO单点登录-CAS Server搭建

&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;最近公司连续接了三四个单点登录集成的项目,由我们公司提供CAS Server端的,也有需要我们把Client与其他公司提供的Server端对接的,我负责把我们公司的一个Client与另外一个公司提供的Server端对接,由于

高级项目经理、专注于技术架构、分享项目管理及职场心得 3万+

cas 4.0 配置mysql_CAS 4.0 配置开发手冊

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.List;import org.apache.http.HttpEntity;import org.apache.http.Http...

weixin_42314399的博客 146

CAS 4.0 配置开发手冊

1下载 地址http://downloads.jasig.org/ cas-server-4.0.0-release.tar.gz cas-client-3.3.3-release.tar.gz 2配置 解压cas-server-4.0.0。将当中module/cas-server-webapp-4.0.0.war拷贝到Tomcat的webapps文件夹下,重命名...

weixin_30624825的博客 141

cas 4.0 配置mysql_CAS 4.0 配置开发手册(转)

CAS Single Sign Out Filterorg.jasig.cas.client.session.SingleSignOutFilterCAS Authentication Filterorg.jasig.cas.client.authentication.AuthenticationFiltercasServerLoginUrlhttps://localhost:8443/cas/l...

weixin_36212135的博客 108

CAS4.0集成restlet手册

最近公司需求要搞单点登录,所以毋庸置疑 就选择了CAS4.0,因为有CS客户端需要调用登录接口,而CAS项目中已经集成好了restlet接口,需要配置一下即可。 1.首先在web.xml文件中加入 如下代码:    CAS配置(一)-集成RESTFul --> restlet org.restlet.ext.spring.RestletFrameworkServlet 1  

liyonggang1988的专栏 1548

cas-server-4.0.0服务端

下面连接:基础环境搭建 http://blog.csdn.net/zangguangtian/article/details/79454500 下面连接:配置数据库支持 http://blog.csdn.net/zangguangtian/article/details/79454349

柯尼卡美能达色彩分析软件 CA-S40/SDK

版本1.80 Display Color Analyzer CA-410探头或Data Processor CA-DP40的客户可以免费下载组合软件包,其中包含Color Analyzer CA-S40的PC软件和Color Analyzer CA-SDK2的最新版本。提供Windows和macOS的软件包。 可用语言: 软件/SDK:英语

CAS4.0 自定义客服端登陆界面,客服端与服务端

cas4.0版本的 单点登录 自定义页面。希望对你有用,最低资源分,辛苦分。有问题可以交流学习。谢谢

springmvc cas maven cas-server-4.0.0 下载

cas-server-4.0.0-release.tar.gz springmvc cas maven 详解 http://knight-black-bob.iteye.com/blog/2342088

CAS 4.0

1.CAS 4.0 配置开发手册 http://blog.csdn.net/ahpo/article/details/46412859

gjq2267787274的专栏 538

Zynq UltraScale+ MPSoC配置DDR4参数

Zynq UltraScale+ MPSoC配置DDR4参数 前言 自己做自己的嵌入式产品一般要选择合适的DDR,而这里开发板给的是4GB的UIMM的DDR4,也就是电脑上用的,所以用不了,只能自己挂载Component,这里说一下配置的过程,如何从PDF中拿出参数来 开始 Zynq DDR控制器 1、首先看一下Zynq MPSoC支持的DDR,这里的手册是UG1085,首先是最大支持多少 可以...

weixin_43873379的博客 1万+

LifeRay6.0+Cas3.4集成手册

  开源门户技术LifeRay6.0+Cas3.4集成手册 1 LifeRay介绍 1.1 简单介绍 Liferay(又称Liferay Portal)是一个开源门户项目,该项目包含了一个完整的J2EE应用。该项目使用了Web、EJB以及JMS等技术,特别是其前台界面部分使用Struts 框架技术,基于XML的port...

yanzhijun1985的专栏 228

Xilinx UltraScale+DDR4项目开发(三)——DDR4器件选型与MIG IP的配置

数据在时钟的双边沿采样,故有效数据传输频率为时钟频率的两倍,数据传送频率(等效频率),实际应用中测试时关注的时钟频率,下图中的3200MHz/2666MHz/2400MHz。DDR4器件选型,需要根据项目中内存的容量需求,读写速率,成本等各方面考虑,对于FPGA开发者,需要根据DDR4 MIG的IP控制器的性能进行选型,并配置。这个跟硬件上DDR4的颗粒有关系了,在上面IP配置中,数据位宽选择64,也就是4 * 16,硬件上使用了4个DDR4颗粒,故4 * 1GB=4GB,是DDR4的内存总容量。

小灰灰的FPGA的博客 4164
上一篇: 弱网络下通讯研究
下一篇: 基于业务模拟的自动化测试实践
ahpo
博客等级 码龄24年 76粉丝 211原创
评论 41
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值