1.下载cas的server和client包(cas-server-4.0.0-release.zip,cas-client-3.3.3-release.zip),https://www.apereo.org/projects/cas/download-cas,http://downloads.jasig.org/cas-clients/。。
2.自定义测试域名hosts,更改C:\Windows\System32\drivers\etc路径下的hosts文件
127.0.0.1 www.owenmoney.com 127.0.0.1 www.owensso.com 127.0.0.1 www.owenmall.com
3.使用keytool安装证书
keytool -genkey -alias owensso -keyalg RSA -keysize 2048 -keystore E:/temp/cas/keys/owensso.keystore #keystore密码:changeit,您的名字与姓氏是什么?www.owensso.com(否则会出现java.security.cert.CertificateException: No subject alternative DNS name matching <hostname> found) keytool -export -file E:/temp/cas/keys/owensso.crt -alias owensso -keystore E:/temp/cas/keys/owensso.keystore keytool -import -keystore D:\app\Java\jre6\lib\security\cacerts -file E:/temp/cas/keys/owensso.crt -alias owensso
4.客户端安装证书(不安装会出现PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target )
/* * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of Sun Microsystems nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * 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 OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.security.KeyStore; import java.security.MessageDigest; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLException; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; public class InstallCert { public static void main(String[] args) throws Exception { String host; int port; char[] passphrase; if ((args.length == 1) || (args.length == 2)) { String[] c = args[0].split(":"); host = c[0]; port = (c.length == 1) ? 443 : Integer.parseInt(c[1]); String p = (args.length == 1) ? "changeit" : args[1]; passphrase = p.toCharArray(); } else { System.out .println("Usage: java InstallCert <host>[:port] [passphrase]"); return; } File file = new File("jssecacerts"); if (file.isFile() == false) { char SEP = File.separatorChar; File dir = new File(System.getProperty("java.home") + SEP + "lib" + SEP + "security"); file = new File(dir, "jssecacerts"); if (file.isFile() == false) { file = new File(dir, "cacerts"); } } System.out.println("Loading KeyStore " + file + "..."); InputStream in = new FileInputStream(file); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(in, passphrase); in.close(); SSLContext context = SSLContext.getInstance("TLS"); TrustManagerFactory tmf = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(ks); X509TrustManager defaultTrustManager = (X509TrustManager) tmf .getTrustManagers()[0]; SavingTrustManager tm = new SavingTrustManager(defaultTrustManager); context.init(null, new TrustManager[] { tm }, null); SSLSocketFactory factory = context.getSocketFactory(); System.out .println("Opening connection to " + host + ":" + port + "..."); SSLSocket socket = (SSLSocket) factory.createSocket(host, port); socket.setSoTimeout(10000); try { System.out.println("Starting SSL handshake..."); socket.startHandshake(); socket.close(); System.out.println(); System.out.println("No errors, certificate is already trusted"); } catch (SSLException e) { System.out.println(); e.printStackTrace(System.out); } X509Certificate[] chain = tm.chain; if (chain == null) { System.out.println("Could not obtain server certificate chain"); return; } BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); System.out.println(); System.out.println("Server sent " + chain.length + " certificate(s):"); System.out.println(); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); MessageDigest md5 = MessageDigest.getInstance("MD5"); for (int i = 0; i < chain.length; i++) { X509Certificate cert = chain[i]; System.out.println(" " + (i + 1) + " Subject " + cert.getSubjectDN()); System.out.println(" Issuer " + cert.getIssuerDN()); sha1.update(cert.getEncoded()); System.out.println(" sha1 " + toHexString(sha1.digest())); md5.update(cert.getEncoded()); System.out.println(" md5 " + toHexString(md5.digest())); System.out.println(); } System.out .println("Enter certificate to add to trusted keystore or 'q' to quit: [1]"); String line = reader.readLine().trim(); int k; try { k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1; } catch (NumberFormatException e) { System.out.println("KeyStore not changed"); return; } X509Certificate cert = chain[k]; String alias = host + "-" + (k + 1); ks.setCertificateEntry(alias, cert); OutputStream out = new FileOutputStream("jssecacerts"); ks.store(out, passphrase); out.close(); System.out.println(); System.out.println(cert); System.out.println(); System.out .println("Added certificate to keystore 'jssecacerts' using alias '" + alias + "'"); } private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray(); private static String toHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(bytes.length * 3); for (int b : bytes) { b &= 0xff; sb.append(HEXDIGITS[b >> 4]); sb.append(HEXDIGITS[b & 15]); sb.append(' '); } return sb.toString(); } private static class SavingTrustManager implements X509TrustManager { private final X509TrustManager tm; private X509Certificate[] chain; SavingTrustManager(X509TrustManager tm) { this.tm = tm; } public X509Certificate[] getAcceptedIssuers() { throw new UnsupportedOperationException(); } public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { throw new UnsupportedOperationException(); } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { this.chain = chain; tm.checkServerTrusted(chain, authType); } } }
编译后,执行 java InstallCert www.owensso.com:8443
Enter certificate to add to trusted keystore or 'q' to quit: [1]
回复:1,回车。
将生成的jssecacerts文件copy到D:\app\Java\jdk1.6.0_23\jre\lib\security目录下,不确定运行的那一个jre,把java_home下的jre文件夹相同路径下也备一份
5.tomcat的https配置
解压3个tomcat,命名tomcat80,tomcat8080,tomcat8443,对应域名:www.owenmoney.com:80,www.owenmall.com:8080,www.owensso.com:8443,更改配置tomcat的server.xml文件,其他端口号都相应的+1,8443tomcat的server.xml如下,ciphers参数是解决高版本的chrome和firefox的弱权限问题
<Connector port="8443" ciphers= " TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA " protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="E:/temp/cas/keys/owensso.keystore" keystorePass="changeit" />
6.解压cas-server-4.0.0-release.zip,把modules/cas-server-webapp-4.0.0.war发布到tomcat8443下,启动tomcat,访问https://www.owensso.com:8443/cas/login,用户名:casuser密码:Mellon
7.解压cas-client-3.3.3-release.zip,复制cas-client-core-3.3.3.jar包到owenmall工程下,添加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 Filter</filter-name> <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> <init-param> <param-name>casServerLoginUrl</param-name> <param-value>https://www.owensso.com:8443/cas/login</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://www.owenmall.com:8080</param-value> </init-param> </filter> <!-- 该过滤器负责对Ticket的校验工作,必须启用它 --> <filter> <filter-name>CAS Validation Filter</filter-name> <filter-class> org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://www.owensso.com:8443/cas</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://www.owenmall.com:8080</param-value> </init-param> </filter> <!-- 该过滤器负责实现HttpServletRequest请求的包裹, 比如允许开发者通过HttpServletRequest的getRemoteUser()方法获得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 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> <!-- ======================== 单点登录结束 ======================== -->
7.启动tomcat8443,tomcat8080,访问www.owenmall.com:8080/sso-client,网页自动跳转到https://www.owensso.com:8443/cas/login输入用户名密码,成功后将会回跳开始页面!
学习笔记,参考知识资料皆来源于国内外的论坛博客,原网址浏览时未记录,若侵权请联系!
相关推荐
spring下使用shiro+cas配置单点登录,多个系统之间的访问,每次只需要登录一次 ## 系统模块说明 1. cas: 单点登录模块,这里直接拿的是cas的项目改了点样式而已 2. doc: 文档目录,里面有数据库生成语句,采用的...
"CAS实现sso单点登录原理" CAS(Central Authentication Service)是Yale大学发起的一个企业级的、开源的项目,旨在为Web应用系统提供一种可靠的单点登录解决方法(属于Web SSO)。CAS开始于2001年,并在2004年12月...
SSO(Single Sign-On)单点登录...总之,SSO单点登录为用户提供了便捷的访问体验,同时降低了管理多系统登录的复杂性。通过理解其原理和实现方式,我们可以根据具体需求选择合适的技术方案,构建高效且安全的SSO系统。
SSO单点登录技术是现代企业级应用架构中不可或缺的一部分,它通过统一的身份认证服务提升了用户体验,降低了运维复杂度。"Simple-SSO"项目为开发者提供了一个学习和实践SSO的平台,结合Maven的项目管理,使得分布式...
### 用CAS实现框架的SSO单点登录 #### SSO单点登录概念与原理 SSO(Single Sign-On)即单点登录技术,是一种让用户只需登录一次即可访问多个关联应用的技术。它不仅提升了用户体验,同时也加强了系统的安全性。...
### SSO单点登录原理及CAS Server配置详解 #### 一、SSO简介 SSO(Single Sign-On,单点登录)是身份管理领域的重要组成部分,它允许用户在一个应用程序中进行一次身份验证后,无需再次登录即可访问同一组织内其他...
Weblogic 使用 YALE CAS 实现 SSO 单点登录的方法 一、Yale CAS 简介 Yale CAS 是耶鲁大学开发的一种开源的单点登录(SSO)解决方案,提供了一个通用的身份验证框架,允许用户使用单个身份验证来访问多个应用程序。...
总的来说,SSO 单点登录通过 CAS 实现,需要正确配置 CAS 服务器与客户端,以及适配不同的认证策略。配置过程涉及到服务器环境搭建、应用部署、XML 配置文件修改和数据库连接设置。理解这些知识点有助于在实际项目中...
CAS(Central Authentication Service)是Java开发的一个开源的单点登录(Single Sign-On,简称SSO)框架,主要用于解决网络应用中的身份验证问题。本压缩包提供了CAS服务端自定义认证的实现,以及CAS客户端的配置...
总的来说,SSO单点登录技术是现代企业信息系统中不可或缺的一部分,它通过统一的身份认证机制,提高了用户的工作效率,同时也简化了系统的安全管理。理解和掌握SSO的工作原理及实现方式,对于IT专业人员来说至关重要...
这个“sso单点登录demo”是基于Shiro和CAS实现的一个示例,展示了如何在Java环境下构建一个完整的SSO解决方案。 Shiro是一个强大的、轻量级的Java安全框架,提供了认证、授权、加密和会话管理功能,使得开发者可以...
SSO(Single Sign-On)是单点登录的缩写,是一种网络用户认证的机制,它允许用户在一次登录后,可以访问多个相互信任的应用系统,而无需再次输入认证信息。本教程将通过“SSO之CAS单点登录详细图文教程.zip”这个...
单点登录(Single Sign-On,简称SSO)是一种网络身份验证技术,允许用户在一次登录后,无需再次输入凭证即可访问多个相互关联的应用系统。在IT领域,它极大地提升了用户体验和安全性,尤其对于大型企业或组织,管理...
在"SSO单点登录源码"这个主题中,我们主要关注的是如何实现这样一个系统。通过提供的链接(http://www.blogjava.net/xcp/archive/2010/04/13/318125.html),我们可以了解到SSO的基本原理和实现步骤。在这个样例中,...
【CAS_SSO单点登录实例详细步骤】 CAS(Central Authentication Service)是一种开源的单点登录(Single Sign-On,简称SSO)框架,它允许用户通过一个认证入口访问多个应用系统,而无需多次登录。以下是对CAS_SSO单...
以上是SSO单点登录在Java环境中的主要技术和知识点,理解并掌握这些内容,有助于构建高效且安全的多系统登录解决方案。对于各应用独立用户库的情况,可以通过用户同步、联合身份或联邦身份管理等方式来实现。在具体...
在SSO系统中,CAS服务器作为中心认证服务,处理用户的登录请求,验证凭证并返回一个服务票(Service Ticket)。客户端应用在接收到服务票后,会向CAS服务器验证该票的有效性,如果验证通过,则允许用户访问应用。 ...
本压缩包"集成cas实现单点登录认证.zip"显然包含了关于如何使用CAS(Central Authentication Service)框架集成SSO认证的资源。下面我们将详细探讨相关的知识点。 1. CAS简介:CAS是耶鲁大学开源的一个Web应用的...