`

单点登录 - CAS【九】CAS支持HTTP协议

阅读更多

我们知道CAS SSO 是基于HTTPS协议的单点登陆,如果要用HTTP协议进行传输,那么就需要修改CAS的相关的配置文件,图了方便,但是安全性大打折扣,对于单点登录,一旦被攻击,那么你的所有属于CAS管理的业务系统都可以被自由访问了。个人并不赞成使用HTTP协议,牺牲一点性能换取更好的安全性是值得的。

 

一、软件环境

  1、cas-client:cas-client-3.2.1-release

  2、cas-server:cas-server-3.5.2-release

 

二、修改步骤

  1、文件warnCookieGenerator.xml

     

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

 

 

  2、文件ticketGrantingTicketCookieGenerator.xml

    

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

 

 

   将bean中的p:cookieSecure="true "修改为p:cookieSecure="false"

 

  3、文件deployerConfigContext.xml

    

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

 添加p:requireSecure="false"

 

 

 如果我们使用的是基于Filter在web.xml中的方式,至此使用HTTP协议就可以单点登录了。

 如果我们使用的Java Core Object的方式,那么还需要进行的下面的步骤

   

  4、文件SecureURL.java

  

/*
 *  Copyright (c) 2000-2003 Yale University. All rights reserved.
 *
 *  THIS SOFTWARE IS PROVIDED "AS IS," AND ANY EXPRESS OR IMPLIED
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE EXPRESSLY
 *  DISCLAIMED. IN NO EVENT SHALL YALE UNIVERSITY OR ITS EMPLOYEES BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED, THE COSTS OF
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR
 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH
 *  DAMAGE.
 *
 *  Redistribution and use of this software in source or binary forms,
 *  with or without modification, are permitted, provided that the
 *  following conditions are met:
 *
 *  1. Any redistribution must include the above copyright notice and
 *  disclaimer and this list of conditions in any related documentation
 *  and, if feasible, in the redistributed software.
 *
 *  2. Any redistribution must include the acknowledgment, "This product
 *  includes software developed by Yale University," in any related
 *  documentation and, if feasible, in the redistributed software.
 *
 *  3. The names "Yale" and "Yale University" must not be used to endorse
 *  or promote products derived from this software.
 */

package org.jasig.cas.client.corejavaobject.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * A class housing some utility functions exposing secure URL validation
 * and content retrieval.  The rules are intended to be about as restrictive
 * as a common browser with respect to server-certificate validation.
 */
public class SecureURL {

		private static Log log = LogFactory.getLog(SecureURL.class);
	
    /**
     * For testing only...
     */
    public static void main(String args[]) throws IOException {
        System.setProperty(
            "java.protocol.handler.pkgs",
            "com.sun.net.ssl.internal.www.protocol");
        System.out.println(SecureURL.retrieve(args[0]));
    }

    /** 
     * Retrieve the contents from the given URL as a String, assuming the
     * URL's server matches what we expect it to match.
     */
    public static String retrieve(String url) throws IOException {
    	if (log.isTraceEnabled()){
    		log.trace("entering retrieve(" + url + ")");
    	}
        BufferedReader r = null;
        try {
            URL u = new URL(url);
            if (!u.getProtocol().equals("https")){
            	// IOException may not be the best exception we could throw here
            	// since the problem is with the URL argument we were passed, not
            	// IO. -awp9
            	log.error("retrieve(" + url + ") on an illegal URL since protocol was not https.");
							throw new IOException("only 'https' URLs are valid for this method");
            }
                
            URLConnection uc = u.openConnection();
            uc.setRequestProperty("Connection", "close");
            r = new BufferedReader(new InputStreamReader(uc.getInputStream()));
            String line;
            StringBuffer buf = new StringBuffer();
            while ((line = r.readLine()) != null)
                buf.append(line + "\n");
            return buf.toString();
        } finally {
            try {
                if (r != null)
                    r.close();
            } catch (IOException ex) {
                // ignore
            }
        }
    }
}

 

找到下面的部分

 

if (!u.getProtocol().equals("https")){
            	// IOException may not be the best exception we could throw here
            	// since the problem is with the URL argument we were passed, not
            	// IO. -awp9
            	log.error("retrieve(" + url + ") on an illegal URL since protocol was not https.");
							throw new IOException("only 'https' URLs are valid for this method");
            }

 相信大家应该明白了吧,只需要将此部分注释掉即可。

 

备注:cookieSecure都修改false,我们来看下其作用是什么?

   Secure是Cookie的一个属性。

   属性值

         如果客户端仅在使用安全超文本传输协议 (HTTPS) 的后继请求中返回 Cookie,则为 true;否则为 false。默认为 false。 

 

实际上,当此属性为 true 时,该 Cookie 只能通过 https:// 请求来发送。即使用http协议是无法传递Cookie的。

 

 

分享到:
评论

相关推荐

    java-cas单点登录服务端

    CAS(Central Authentication Service)是一款不错的针对 Web 应用的单点登录框架,本文介绍了 CAS 的原理、协议、在 Tomcat 中的配置和使用,研究如何采用 CAS 实现轻量级单点登录解决方案。 CAS 是 Yale 大学发起的...

    CAS单点登录HTTP协议版本配置指南

    CAS 单点登录 HTTP协议 配置指南 SSO CAS 单点登录 HTTP协议 配置指南 SSO CAS 单点登录 HTTP协议 配置指南 SSO

    django-mama-cas, Django 中央身份验证服务( CAS ) 单点登录(Single Sign-On) 服务器.zip

    django-mama-cas, Django 中央身份验证服务( CAS ) 单点登录(Single Sign-On) 服务器 MamaCAS MamaCAS是 Django 中央认证服务( CAS ) 单一登录和单一注销服务器。 它实现了 CAS 1.0.2.0和 3.0协议,包括一些可选的...

    落雨博客基于CAS框架的单点登录技术讲解(ppt+code实例+doc)配套资料

    [置顶] SSO单点登录系列2:cas客户端和cas服务端交互原理动画图解,cas协议终极分析 http://blog.csdn.net/ae6623/article/details/8848107 目 录 1 引言 4 1.1 摘要 4 1.2 范围 4 1.3 读者对象 4 1.4 关键词 4 2 ...

    java-cas-client-3.2.0

    Java 实现的服务,该服务以一个 Java Web Application 单独部署在与 servlet2.3 兼容的 Web 服务器上,另外,由于 Client 与 CAS Server 之间的交互采用 Https 协议,因此部署 CAS Server 的服务器还需要支持 ...

    cas单点登录技术

    1 单点登录总体解决方案 2 CAS原理和协议 3 CAS安全性 4 CAS工作模式 5 系统设计方案 6 CAS关键技术 6.1 域名规范 6.2 中文用户登录提交时乱码 ...7 单点登录风险 ...9.3 TOMCAT中使用CAS实现单点登录LDAP方式

    CAS单点登录服务端部署包

    CAS 是 Central Authentication Service 的缩写 —— 中央认证服务,一种独立开放指令协议,是 Yale 大学发起的一个企业级开源项目,旨在为 Web 应用系统提供一种可靠的 SSO 解决方案。 CAS 支持以下特性: CAS v1, ...

    connect-cas2:CAS(中央身份验证服务)客户端的NodeJS实现

    CAS(中央身份验证服务)是Web的单点登录/单点退出协议。 我们假设您已经熟悉CAS协议,如果不熟悉,请在使用前阅读本。 安装 npm install connect-cas2 特征 非代理模式CAS登录/注销 代理模式CAS登录/注销,获取...

    CAS单点登录系统.doc

    • CAS Client 支持非常多的客户端(这里指单点登录系统中的各个 Web 应用),包括 Java, .Net, PHP, Perl, Apache, uPortal, Ruby 等。 CAS 原理和协议 从 结构上看,CAS 包含两个部分: CAS Server 和 CAS Client。...

    使用CAS在Tomcat中实现单点登录

    CAS(Central Authentication Service)是一款不错的针对 Web 应用的单点登录框架,本文介绍了 CAS 的原理、协议、在 Tomcat 中的配置和使用,对于采用 CAS 实现轻量级单点登录解决方案的入门读者具有一定指导作用。

    CAS单点登录(SSO)教程

    CAS(Central Authentication Service)是一款不错的针对 Web 应用的单点登录框架,本文介绍了 CAS 的原理、协议、在 Tomcat 中的配置和使用,对于采用 CAS 实现轻量级单点登录解决方案的入门读者具有一定指导作用。

    cas-client:适用于Node.js的CAS客户端中间件的完整实现,支持CAS 1.0、2.0 +,3.0 +协议

    CAS(中央身份验证服务)是Web的单点登录/单点退出协议。 我们假设您已经熟悉CAS协议,如果不熟悉,请在使用前阅读本。安装$ npm install http-cas-client特征唱歌登录(SSO) 带有axios api的CAS代理,用于POST,...

    cas 单点登录修改https为http

    cas 单点登录 修改https访问协议为http

    cas单点登录系统

    cas单点登录系统,带源码,可定制开发;CASServer负责完成对用户的认证工作,CASServer需要独立部署,CASServer处理用户名/密码等凭证(Credentials)验证,它可能会到数据库检索一条用户帐号信息,也可能在XML文件中...

    cas-server-3.1.1-release.zip_CAS SSO_CAS-server_Cas Server RDBMS

    CAS(Central Authentication Service)是一款不错的针对 Web 应用的单点登录框架,本文介绍了 CAS 的原理、协议、在 Tomcat 中的配置和使用,对于采用 CAS 实现轻量级单点登录解决方案的入门读者具有一定指导作用。

    SSO单点登录Spring-Security+CAS+使用手册

    单点登录(Single Sign On , 简称 SSO )是目前...CAS(Central Authentication Service)是一款不错的针对 Web 应用的单点登录框架。 本文介绍了 CAS 的原理、协议、以及配合Spring-Security在 Tomcat 中的配置和使用。

    django-cas-server:实施CAS协议3.0规范的Django Central Authentication Service服务器

    特征支持CAS版本1.0、2.0、3.0 支持单点退出通过Django Admin应用程序配置服务精细控制将哪些用户的属性传递给哪个服务可以按服务重命名/重写属性每个服务可能需要一些属性值多个CAS之间的联合模式支持Django 1.11、...

    cas-server-4.0.0

    CAS是Central Authentication Service的缩写,中央认证服务,一种独立开放...CAS 是 Yale 大学发起的一个开源项目,旨在为 Web 应用系统提供一种可靠的单点登录方法,CAS 在 2004 年 12 月正式成为 JA-SIG 的一个项目。

    cas-overlay-template-master.zip

    CAS协议的服务端解压的软件,下载后解压开即可直接放在tomcat里面使用的,非常方便。对于研究cas认证技术的人员有帮助。

    cas3.5.0集成oauth2.0协议

    cas3.5.0集成oauth2.0协议,模拟cas3.5.0通过oauth2.0协议与集成了coauth2.0的cas进行模拟通信。可以实现 与新浪微博等第三方身份验证平台对接,实现单点登录。

Global site tag (gtag.js) - Google Analytics