- 浏览: 188907 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (153)
- 小技巧 (14)
- spring (3)
- struts2 (20)
- hibernate (0)
- java api (2)
- java se (8)
- jsp/servlet (4)
- oracle (0)
- mysql (1)
- ms sqlserver (1)
- js (30)
- jquery (8)
- ajax (2)
- .net (1)
- 软件 (1)
- j2ee (25)
- 网址收藏 (3)
- web综合 (9)
- web打印控件 (3)
- fckeditor (2)
- Groovy (1)
- PHP (5)
- 项目管理 (1)
- SEO (1)
- PostgreSQL (5)
- CKeditor (1)
- Fusion chart (1)
- 网页播放器 (1)
- 曾遇bug (3)
- java日志 (1)
- linux/Unix/CentOs (5)
- VBA (1)
- C# (0)
- 日期控件 (1)
- tomcat (2)
- cookies (1)
- java7 (1)
- JAVA文件操作 (2)
- hibernate;ehcache (2)
- 缓存 (1)
- dd (0)
- DB (1)
- android (2)
最新评论
-
flyingbin:
沙发,不过从头到尾没怎么看懂~
Windows密码本地破解通用方法 -
jfeimao:
credentialsToPrincipalResolvers ...
CAS(单点登陆)---总结一 -
haige18:
这两张图片引用的是网易的地址,现在资源有可能被删除了,所以就显 ...
Struts2中的Value Stack/Stack Context -
fengzhisha0914:
我的图片也不显示了..为何...
Struts2中的Value Stack/Stack Context -
greatwqs:
java.lang.IllegalStateException ...
java.lang.IllegalStateException:Cannot forward after response has been committed
下面的讲解基于CAS Server 3.3.5版本。
CAS Server 配置文件
login-webflow.xml:其中内容指定了当访问cas/login时的程序流程,初始“initialFlowSetup”
cas-servlet.xml:servlet与class对应关系
deployerConfigContext.xml:认证管理器相关
cas.properties:系统属性设置
applicationContext.xml:系统属性相关
argumentExtractorsConfiguration.xml:不是很了解它的用途
ticketExpirationPolicies.xml:ticket过期时间设置
ticketGrantingTicketCookieGenerator.xml:TGT cookie属性相关,是否支持http也在这儿修改
ticketRegistry.xml:保存ticket的类相关设置
uniqueIdGenerators.xml:ticket自动生成类设置
warnCookieGenerator.xml:同ticketGrantingTicketCookieGenerator.xml,生成的 cookie名为CASPRIVACY
/login :
当访问/login时,会调用login-webflow.xml中的流程图:
/serviceValidate:
对应的处理类是org.jasig.cas.web.ServiceValidateController,主要负责对service ticket的验证,失败返回casServiceValidationFailure.jsp,成功返回casServiceValidationSuccess.jsp
对service ticket的验证是通过client端向server端发送http(或https)实现的
逻辑:
1.通过由client端传来的ticket到DefaultTicketRegistry中获取缓存的ServiceTicketImpl对象,并判断其是否已经过期(ST过期时间默认是5分钟,TGT默认是2个小时,可以在ticketExpirationPolicies.xml中进行修改)以及与当前service的id是否相一,以上都满足则表示验证通过。
2.通过ServiceTicketImpl对象获取到登录之后的Authentication对象,借助于它生成ImmutableAssertionImpl对象并返回
3.成功返回
CAS数据流程
Credentials-->Principal-->Authentication
定义自己的AuthenticationHandler
在中心认证进行认证的过程中会调用deployerConfigContext.xml中设置的AuthenticationHandler来进行认证工作。
- <property name="authenticationHandlers">
- <list>
- <!--
- This is the authentication handler that authenticates services by means of callback via SSL, thereby validating
- a server side SSL certificate.
- -->
- <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
- p:httpClient-ref="httpClient" />
- <!--
- This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS
- into production. The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials
- where the username equals the password. You will need to replace this with an AuthenticationHandler that implements your
- local authentication strategy. You might accomplish this by coding a new such handler and declaring
- edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules.
- -->
- <bean
- class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />
- <bean class="com.goldarmor.live800.cas.Live800CasAuthenticationHandler">
- <property name="dataSource" ref="casDataSource" />
- </bean>
- </list
- </property>
<property name="authenticationHandlers"> <list> <!-- This is the authentication handler that authenticates services by means of callback via SSL, thereby validating a server side SSL certificate. --> <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref="httpClient" /> <!-- This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS into production. The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials where the username equals the password. You will need to replace this with an AuthenticationHandler that implements your local authentication strategy. You might accomplish this by coding a new such handler and declaring edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules. --> <bean class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" /> <bean class="com.goldarmor.live800.cas.Live800CasAuthenticationHandler"> <property name="dataSource" ref="casDataSource" /> </bean> </list </property>
如上,我们定义了3个AuthenticationHandler,这正是CAS的一个 ,通过配置,我们可以实现针对不同的应用提供不同的认证方式,这样可以实现任意的中心认证。再来看看AuthenticationHandler的代码
- /**
- * Method to determine if the credentials supplied are valid.
- *
- * @param credentials The credentials to validate.
- * @return true if valid, return false otherwise.
- * @throws AuthenticationException An AuthenticationException can contain
- * details about why a particular authentication request failed.
- */
- boolean authenticate(Credentials credentials)
- throws AuthenticationException;
- /**
- * Method to check if the handler knows how to handle the credentials
- * provided. It may be a simple check of the Credentials class or something
- * more complicated such as scanning the information contained in the
- * Credentials object.
- *
- * @param credentials The credentials to check.
- * @return true if the handler supports the Credentials, false othewrise.
- */
- boolean supports(Credentials credentials);
/** * Method to determine if the credentials supplied are valid. * * @param credentials The credentials to validate. * @return true if valid, return false otherwise. * @throws AuthenticationException An AuthenticationException can contain * details about why a particular authentication request failed. */ boolean authenticate(Credentials credentials) throws AuthenticationException; /** * Method to check if the handler knows how to handle the credentials * provided. It may be a simple check of the Credentials class or something * more complicated such as scanning the information contained in the * Credentials object. * * @param credentials The credentials to check. * @return true if the handler supports the Credentials, false othewrise. */ boolean supports(Credentials credentials);
我们要做的就是实现这俩个方法而已,特别提醒:可以在cas-servlet.xml中设置你所使用的Credentials,如下:(其中的p:formObjectClass值,如果不指定默认使用UsernamePasswordCredentials)
- <bean id="authenticationViaFormAction" class="org.jasig.cas.web.flow.AuthenticationViaFormAction"
- p:formObjectClass="com.goldarmor.live800.cas.Live800CasCredentials"
- p:centralAuthenticationService-ref="centralAuthenticationService"
- p:warnCookieGenerator-ref="warnCookieGenerator" />
<bean id="authenticationViaFormAction" class="org.jasig.cas.web.flow.AuthenticationViaFormAction" p:formObjectClass="com.goldarmor.live800.cas.Live800CasCredentials" p:centralAuthenticationService-ref="centralAuthenticationService" p:warnCookieGenerator-ref="warnCookieGenerator" />
定义自己的credentialsToPrincipalResolvers
通过AuthenticationHandler的认证后,会调用在deployerConfigContext.xml中配置的credentialsToPrincipalResolvers来处理Credentials,生成Principal对象:
- <property name="credentialsToPrincipalResolvers">
- <list>
- <!--
- UsernamePasswordCredentialsToPrincipalResolver supports the UsernamePasswordCredentials that we use for /login
- by default and produces SimplePrincipal instances conveying the username from the credentials.
- If you've changed your LoginFormAction to use credentials other than UsernamePasswordCredentials then you will also
- need to change this bean declaration (or add additional declarations) to declare a CredentialsToPrincipalResolver that supports the
- Credentials you are using.
- --> <bean
- class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" />
- <!--
- HttpBasedServiceCredentialsToPrincipalResolver supports HttpBasedCredentials. It supports the CAS 2.0 approach of
- authenticating services by SSL callback, extracting the callback URL from the Credentials and representing it as a
- SimpleService identified by that callback URL.
- If you are representing services by something more or other than an HTTPS URL whereat they are able to
- receive a proxy callback, you will need to change this bean declaration (or add additional declarations).
- -->
- <bean
- class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" />
- <bean class="com.goldarmor.live800.cas.Live800CasCredentialsToPrincipalResolver"/>
- </list>
- </property>
<property name="credentialsToPrincipalResolvers"> <list> <!-- UsernamePasswordCredentialsToPrincipalResolver supports the UsernamePasswordCredentials that we use for /login by default and produces SimplePrincipal instances conveying the username from the credentials. If you've changed your LoginFormAction to use credentials other than UsernamePasswordCredentials then you will also need to change this bean declaration (or add additional declarations) to declare a CredentialsToPrincipalResolver that supports the Credentials you are using. --> <bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" /> <!-- HttpBasedServiceCredentialsToPrincipalResolver supports HttpBasedCredentials. It supports the CAS 2.0 approach of authenticating services by SSL callback, extracting the callback URL from the Credentials and representing it as a SimpleService identified by that callback URL. If you are representing services by something more or other than an HTTPS URL whereat they are able to receive a proxy callback, you will need to change this bean declaration (or add additional declarations). --> <bean class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" /> <bean class="com.goldarmor.live800.cas.Live800CasCredentialsToPrincipalResolver"/> </list> </property>
如上:我们也可以像定义AuthenticationHandler一样,可以定义多个credentialsToPrincipalResolvers来处理Credentials,返回你所需要的Principal对象,下面来看看credentialsToPrincipalResolvers的方法:
- /**
- * Turn Credentials into a Principal object by analyzing the information
- * provided in the Credentials and constructing a Principal object based on
- * that information or information derived from the Credentials object.
- *
- * @param credentials from which to resolve Principal
- * @return resolved Principal, or null if the principal could not be resolved.
- */
- Principal resolvePrincipal(Credentials credentials);
- /**
- * Determine if a credentials type is supported by this resolver. This is
- * checked before calling resolve principal.
- *
- * @param credentials The credentials to check if we support.
- * @return true if we support these credentials, false otherwise.
- */
- boolean supports(Credentials credentials);
/** * Turn Credentials into a Principal object by analyzing the information * provided in the Credentials and constructing a Principal object based on * that information or information derived from the Credentials object. * * @param credentials from which to resolve Principal * @return resolved Principal, or null if the principal could not be resolved. */ Principal resolvePrincipal(Credentials credentials); /** * Determine if a credentials type is supported by this resolver. This is * checked before calling resolve principal. * * @param credentials The credentials to check if we support. * @return true if we support these credentials, false otherwise. */ boolean supports(Credentials credentials);
在CAS验证的时候,通过访问/serviceValidate可知:验证成功之后返回的casServiceValidationSuccess.jsp中的数据来源于Assertion,下面来看看它的代码:
- List<Authentication> getChainedAuthentications();
- /**
- * True if the validated ticket was granted in the same transaction as that
- * in which its grantor GrantingTicket was originally issued.
- *
- * @return true if validated ticket was granted simultaneous with its
- * grantor's issuance
- */
- boolean isFromNewLogin();
- /**
- * Method to obtain the service for which we are asserting this ticket is
- * valid for.
- *
- * @return the service for which we are asserting this ticket is valid for.
- */
- Service getService();
List<Authentication> getChainedAuthentications(); /** * True if the validated ticket was granted in the same transaction as that * in which its grantor GrantingTicket was originally issued. * * @return true if validated ticket was granted simultaneous with its * grantor's issuance */ boolean isFromNewLogin(); /** * Method to obtain the service for which we are asserting this ticket is * valid for. * * @return the service for which we are asserting this ticket is valid for. */ Service getService();
通过getChainedAuthentications()方法,我们可以得到Authentication对象列表,再看看Authentication的代码:
- /**
- * Method to obtain the Principal.
- *
- * @return a Principal implementation
- */
- Principal getPrincipal();
- /**
- * Method to retrieve the timestamp of when this Authentication object was
- * created.
- *
- * @return the date/time the authentication occurred.
- */
- Date getAuthenticatedDate();
- /**
- * Attributes of the authentication (not the Principal).
- * @return the map of attributes.
- */
- Map<String, Object> getAttributes();
/** * Method to obtain the Principal. * * @return a Principal implementation */ Principal getPrincipal(); /** * Method to retrieve the timestamp of when this Authentication object was * created. * * @return the date/time the authentication occurred. */ Date getAuthenticatedDate(); /** * Attributes of the authentication (not the Principal). * @return the map of attributes. */ Map<String, Object> getAttributes();
而这其中的Principal就来源于上面提到的由credentialsToPrincipalResolvers处理得到的Principal对象,最后看一下Principal的代码,我们只要再做一个实现他的代码,整个CAS Server就可以信手拈来了,呵呵
- /**
- * Returns the unique id for the Principal
- * @return the unique id for the Principal.
- */
- String getId();
- /**
- *
- * @return
- */
- Map<String, Object> getAttributes();
/** * Returns the unique id for the Principal * @return the unique id for the Principal. */ String getId(); /** * * @return */ Map<String, Object> getAttributes();
我们还可以自定义自己的casServiceValidationSuccess.jsp和casLoginView.jsp页面等,具体的操作办法也是最简单的办法就是备份以前的页面之后修改成自己需要的页面。
来自:http://www.iteye.com/topic/650595
发表评论
-
Java 连接access 使用access文件 不用配置
2012-05-23 09:43 901String url = "jdbc:od ... -
在Java 7里如何对文件进行操作
2012-04-25 16:53 739下面的代码片段是由经过验证的程序修改而来。观察这些代码片段你会 ... -
Java将中文转换成拼音,用于字母的模糊查询
2012-04-23 15:05 1869/** * 将汉字转换为拼音 * ... -
JSON+Jquery实现页面动态加载
2011-12-09 18:10 805看附件 -
轻松实现Apache,Tomcat集群和负载均衡
2011-04-29 09:42 728作者:罗代均 ldj_work#126.com,转载请保 ... -
Java或web中解决所有路径问题
2011-04-28 21:48 703Java中使用的路径, ... -
基于jquery的上传插件Uploadify
2010-11-26 17:24 976无论是做Web产品还是Web项目,文件上传是经常要用到的功 ... -
JSP中的两种包含页面的方法
2010-11-09 11:47 756写道 第一种:include指令:当JSP转换成Servle ... -
pager-taglib 使用说明
2010-11-03 22:10 930http://www.iteye.com/topic/6265 ... -
jFreeChart 在jsp页上实现简单的折线图、柱状图
2010-10-31 13:57 1990可参考资料与网址 官方网站 http://www ... -
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎
2010-10-31 11:22 901SSH + Lucene + 分页 + 排序 + 高亮 ... -
【原创】CAS调研总结
2010-10-31 11:13 951本篇文章是对JA-SIG CAS(v3.3)的初步调研总结。 ... -
CAS客户端证书认证登录
2010-10-31 11:09 1907前端时间需要实现公司内网证书自动登录CAS. 由于对CAS的 ... -
CAS(单点登陆)---总结一
2010-10-31 11:05 1359单点登录(sso)是指基 ... -
CAS(单点登陆)---总结二
2010-10-31 11:01 832返回更多用户信息继... 配置ssoAuth/WEB-INF ... -
java 防sql注入
2010-10-27 21:29 837package com.cssweb.webcall.util ... -
防止未登录进行操作 解决登录页面内嵌问题
2010-10-27 21:28 1404防止未登录进行操作 解决登录页面内嵌问题 1.进入登录的 ... -
fckeditor的使用
2010-10-27 21:17 753先根据上一篇博文下载FckEditor的工具 1.简单的例子 ... -
网页在线编辑器 fckeditor
2010-10-27 21:16 1034几种常见的网页在线编 ... -
解决地址栏传输中文问题
2010-10-27 21:10 808一、传统的方法,修改tomcat/conf/server.xm ...
相关推荐
单点登录服务端项目cas-server单点登录服务端项目cas-server 单点登录服务端项目cas-server 单点登录服务端项目cas-server 单点登录服务端项目cas-server 单点登录服务端项目cas-server 单点登录服务端项目cas-...
CAS(Central Authentication Service)是基于Java的开源身份验证框架,主要功能是实现单点登录(Single Sign-On,简称SSO)。SSO允许用户通过一次登录,就能访问多个应用系统,无需再次输入凭证,大大提升了用户...
本文将详细介绍如何利用 CAS(Central Authentication Service)协议来实现 Mantis 的单点登录和登出功能。 #### 实现步骤 ##### 第一步:环境准备 1. **安装 CAS 服务器**:确保 CAS 服务器已经部署完成,并且...
【耶鲁CasServer单点登录教程】 一、Yale CAS简介 Yale Central Authentication Service (CAS) 是一个开源的身份验证框架,由耶鲁大学开发,主要用于实现单点登录(Single Sign-On, SSO)。SSO允许用户在一个系统上...
单点登录的核心在于一个中心认证服务器(CAS Server)和各个需要认证的应用系统。当用户首次尝试访问受保护的应用时,会被重定向到CAS Server进行身份验证。如果用户通过验证,CAS Server会生成一个服务票据...
总结起来,这个"单点登录cas服务器demo及springboot客户端demo"项目提供了一个实践单点登录概念的实例,涵盖了CAS服务器的搭建、Spring Boot应用的CAS客户端集成,以及Shiro或Pac4j的使用。对于想要学习和理解SSO...
cas server 5.2 版 war包。直接丢在tomcat的webapps下面,重启tomcat即可。
CAS(Central Authentication Service)单点登录系统是一种网络身份验证协议,它允许用户通过单一的身份验证过程访问多个应用系统。在本“CAS单点登录demo”中,我们将深入探讨CAS的工作原理、配置步骤以及如何实现...
本文将详细介绍开源ITSM工具iTop接入开源单点登录框架CAS的实现方法。该方法经过实践验证,已经在作者的单位中应用。 CAS框架简介 CAS(Central Authentication Service)是一种开源的单点登录框架,旨在提供一个...
CAS单点登录操作文档 CAS 是 Yale 大学发起的一个开源项目,旨在为 Web 应用系统提供一种可靠的单点登录方法,CAS 在 2004 年 12 月正式成为 JA-SIG 的一个项目。CAS 具有以下特点: • 开源的企业级单点登录解决...
在这个"CAS-Server-Client单点登录demo"中,我们将深入探讨CAS服务器与客户端的整合以及如何在Apache Tomcat上进行测试。 首先,CAS服务器是整个SSO机制的核心,它负责处理用户的认证请求和验证用户的身份。在"cas-...
CAS(Central Authentication Service)是 Yale 大学开源的一个基于 Java 的单点登录系统,它提供了一种安全、便捷的身份验证机制。本文档将深入探讨如何使用 CAS 实现 Java 应用中的单点登录功能。 一、CAS 概述 ...
springmvc+spring+shiro+cas单点登录实例 加入了登录验证码认证,修改了下首页样式,不过样式没有弄好,很丑的,有空自己再弄下 说明:cas-server是单点登录服务端,用的是maven项目,但是WEB-INF里面的lib目录下面...
通过以上详细步骤,你可以成功配置并实现基于CAS的SSO单点登录系统。在配置过程中,可能会遇到各种问题,如网络连接、证书验证、配置错误等,解决这些问题后,即可享受到SSO带来的便捷性。如果有任何疑问,可以查阅...
本课程主要通过CAS来实现SSO,本教程会从最基本的基础知识讲起,由浅入深再到实战,完成多应用的单点登录功能。 本课程内容如下: 1、 什么是SSO和CAS 2、 CAS Server服务端和客户端的搭建和配置 3、 单点登录和单...
CAS 5.3 及 Windows AD 域实现单点登录免身份认证 CAS(Central Authentication Service)是一种流行的开源身份验证系统,旨在提供单点登录(SSO)解决方案。Windows AD(Active Directory)则是微软公司推出的目录...
本文在已有的禅道集成CAS单点登录的客户端插件基础上进行的修改,因原有插件在我们的系统上调试无法成功,做了一些定制,环境如下: 1. CAS server 版本:4.0.0 2. 禅道开源版本: 9.6.3 3. 禅道CAS client 插件版本...
3. **验证成功**:验证成功后,CAS Server将web2应用加入到单点登录范围内,用户即可在web2应用中进行业务操作。同时,web2应用会在session中记录此令牌凭证,完成单点登录功能。 #### CAS相关源码概述 ##### ...
CAS(Central Authentication Service)是一款不错的针对 Web 应用的单点登录框架,本文介绍了 CAS 的原理、协议、在 Tomcat 中的配置和使用,研究如何采用 CAS 实现轻量级单点登录解决方案。 CAS 是 Yale 大学发起的...