You are on page 1of 3

Chapter 19.

CAS认证

19.1. 概述
JA-SIG开发了一个企业级的单点登录系统,叫做CAS。
与其他项目不同,JA-SIG的中心认证服务是开源的,广泛使用的,简单理解的,不依赖平台的,而且支持代理能力。

Spring
Security完全支持CAS,提供一个简单的整合方式,把使用Spring
Security的单应用发布,转换成使用企业级CAS服务器的多应用发布安全

你可以从http://www.ja-sig.org/products/cas/找到CAS的更多信息。
你还需要访问这个网站下载CAS服务器文件。

19.2. CAS是如何工作的
虽然CAS网站包含了CAS的架构文档,我们这里还是说一下使用Spring

Security环境的一般性概述,。
Spring Security 2.0支持CAS 3。
在写文档的时候,CAS服务器的版本是3.2。

你要在公司内部安装CAS服务器。
CAS服务器就是一个WAR文件,所以安装服务器没有什么难的。
在WAR文件里,你需要自定义登录和其他单点登录展示给用户的页面。

发布CAS
3.2的时候,你也需要指定一个CAS的deployerConfigContext.xml里包含的AuthenticationHandler。
AuthenticationHandler有一个简单的方法,返回布尔值,判断给出的证书集合是否有效。
你的AuthenticationHandler实现会需要链接到后台认证资源类型里,像是LDAP服务器或数据库。

CAS自己也包含非常多AuthenticationHandler帮助实现这些。
在你下载发布服务器war文件的时候,它会把用户名和密码匹配的用户成功验证,这对测试很有用。

除了CAS服务器,其他关键角色当然是你企业发布的其他安全web应用。

这些web应用被叫做"services"。
这儿有两种服务:标准服务和代理服务。
代理服务可以代表用户,从其他服务中请求资源。

后面会进行更详细的介绍。

19.3. 配置CAS客户端
CAS的web应用端通过Spring
Security使用起来很简单。
我们假设你已经知道Spring
Security的基本用法,所以下面都没有涉及这些。
我们会假设使用基于命名空间配置的方法,并且添加了CAS需要的bean。
你需要添加一个 ServiceProperties
bean,到你的application context里。
这表现你的服务:
<bean id="serviceProperties" class="org.springframework.security.ui.cas.ServiceProperties">
<property name="service" value="https://localhost:8443/cas-sample/j_spring_cas_security_check"/>
<property name="sendRenew" value="false"/>
</bean>

&#36825;&#37324;&#30340;service&#24517;&#39035;&#26159;&#19968;&#20010;&#30001;CasProcessingFilter&#30417;&#25511;&#30340;URL&#12290;
&#36825;&#20010;sendRenew&#40664;&#35748;&#26159;false&#65292;&#20294;&#22914;&#26524;&#20320;&#30340;&#31243;&#24207;&#29305;&#21035;&#25935;&#24863;&#23601;&#24212;&#35813;&#35774;&#32622;&#25104;true&#12290;
&#36825;&#20010;&#21442;&#25968;&#20316;&#29992;&#26159;&#65292;&#21578;&#35785;CAS&#30331;&#24405;&#26381;&#21153;&#65292;&#19968;&#20010;&#21333;&#28857;&#30331;&#24405;&#27809;&#26377;&#21040;&#36798;&#12290;
&#21542;&#21017;&#65292;&#29992;&#25143;&#38656;&#35201;&#37325;&#26032;&#36755;&#20837;&#20182;&#20204;&#30340;&#29992;&#25143;&#21517;&#21644;&#23494;&#30721;&#65292;&#26469;&#33719;&#24471;&#35775;&#38382;&#26381;&#21153;&#30340;&#26435;&#38480;&#12290;

&#19979;&#38754;&#37197;&#32622;&#30340;bean&#23601;&#26159;&#23637;&#24320;CAS&#35748;&#35777;&#30340;&#36807;&#31243;&#65306;

<security:authentication-manager alias="authenticationManager"/>

<bean id="casProcessingFilter" class="org.springframework.security.ui.cas.CasProcessingFilter">


<security:custom-filter after="CAS_PROCESSING_FILTER"/>
<property name="authenticationManager" ref="authenticationManager"/>
<property name="authenticationFailureUrl" value="/casfailed.jsp"/>
<property name="defaultTargetUrl" value="/"/>
</bean>

<bean id="casProcessingFilterEntryPoint"
class="org.springframework.security.ui.cas.CasProcessingFilterEntryPoint">
<property name="loginUrl" value="https://localhost:9443/cas/login"/>
<property name="serviceProperties" ref="serviceProperties"/>
</bean>

&#24212;&#35813;&#20351;&#29992;
entry-point-ref&#36873;&#25321;&#39537;&#21160;&#35748;&#35777;&#30340;CasProcessingFilterEntryPoint&#31867;&#12290;

CasProcessingFilter&#30340;&#23646;&#24615;&#19982;
AuthenticationProcessingFilter&#38750;&#24120;&#30456;&#20284;&#65288;&#22312;&#22522;&#20110;&#34920;&#21333;&#30331;&#24405;&#26102;&#29992;&#21040;&#65289;&#12290;
&#27599;&#20010;&#23646;&#24615;&#20174;&#23383;&#38754;&#19978;&#37117;&#24456;&#22909;&#29702;&#35299;&#12290;
&#27880;&#24847;&#25105;&#20204;&#20063;&#20351;&#29992;&#21629;&#21517;&#31354;&#38388;&#35821;&#27861;&#65292;&#20026;&#35748;&#35777;&#31649;&#29702;&#22120;&#35774;&#32622;&#19968;&#20010;&#21035;&#21517;&#65292;&#36825;&#26679;CasProcessingFilter&#38656;&#35201;&#23427;&#30340;&#19968;&#20010;&#24341;&#29992;&#12290;

&#20026;&#20102;CAS&#30340;&#25805;&#20316;&#65292;ExceptionTranslationFilter&#24517;&#39035;&#26377;&#23427;&#30340;authenticationEntryPoint&#65292;&#36825;&#37324;&#35774;&#32622;&#25104;CasProcessingFilterEntryPoint

bean&#12290;

CasProcessingFilterEntryPoint &#24517;&#39035;&#25351;&#21521;
ServiceProperties bean
&#65288;&#19978;&#38754;&#35752;&#35770;&#36807;&#20102;&#65289;&#65292;&#23427;&#20026;&#20225;&#19994;CAS&#30331;&#24405;&#26381;&#21153;&#22120;&#25552;&#20379;URL&#12290;
&#36825;&#26159;&#29992;&#25143;&#27983;&#35272;&#22120;&#23558;&#34987;&#37325;&#23450;&#21521;&#30340;&#20301;&#32622;&#12290;

&#19979;&#19968;&#27493;&#65292;&#20320;&#38656;&#35201;&#28155;&#21152;&#19968;&#20010;CasAuthenticationProvider
&#21644;&#23427;&#30340;&#21512;&#20316;&#20249;&#20276;&#65306;
<bean id="casAuthenticationProvider" class="org.springframework.security.providers.cas.CasAuthenticationProvider">
<security:custom-authentication-provider />
<property name="userDetailsService" ref="userService"/>
<property name="serviceProperties" ref="serviceProperties" />
<property name="ticketValidator">
<bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
<constructor-arg index="0" value="https://localhost:9443/cas" />
</bean>
</property>
<property name="key" value="an_id_for_this_auth_provider_only"/>
</bean>
<security:user-service id="userService">
<security:user name="joe" password="joe" authorities="ROLE_USER" />
...
</security:user-service>

&#19968;&#26086;&#36890;&#36807;&#20102;CAS&#30340;&#35748;&#35777;&#65292;CasAuthenticationProvider
&#20351;&#29992;&#19968;&#20010;
UserDetailsService&#23454;&#20363;&#65292;&#26469;&#21152;&#36733;&#29992;&#25143;&#30340;&#35748;&#35777;&#20449;&#24687;&#12290;
&#36825;&#37324;&#25105;&#20204;&#23637;&#31034;&#19968;&#20010;&#31616;&#21333;&#30340;&#22522;&#20110;&#20869;&#23384;&#30340;&#35774;&#32622;&#12290;

&#22914;&#26524;&#20320;&#32763;&#22238;&#22836;&#30475;&#19968;&#19979;"How CAS
Works"&#37027;&#33410;&#65292;&#36825;&#20123;beans&#37117;&#26159;&#20174;&#21517;&#23383;&#23601;&#21487;&#20197;&#30475;&#25026;&#30340;&#12290;

Prev Home Next


Chapter 18. X.509&#35748;&#35777; Sponsored Chapter 20. &#26367;&#25442;&#39564;&#35777;&#36523;&#20221;
by
SpringSource

You might also like