Cas的基本过程(笔记)
Cas基本流程功能图
1.访问web-one应用
2.是否有ticket?
3.没有就重定向到登录界面。在Client中的web.xml文件配置
<filter>
<filter-name>CASFilter</filter-name>
<filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name>
<param-value>https://cas.my.com:8443/cas/login</param-value>
<!--这里的server是服务端的IP-->
</init-param>
</filter>
<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
4.输入用户名以及密码验证(采用查询数据库,并且加密存储),在Server中 的WEB-INF下的deployerConfigContext.xml中配置,并且添加mysql和c3p0的jar包
- 数据库查询
<bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager">
<constructor-arg>
<map>
<entry key-ref="proxyAuthenticationHandler" valu ref="proxyPrincipalResolver" />
<!-- 注释这个-->
<!-- <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" /> -->
<!-- key-ref指定自己的本地数据库访问 -->
<entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver"/>
</map>
</constructor-arg>
<property name="authenticationPolicy">
<bean class="org.jasig.cas.authentication.AnyAuthenticationPolicy" />
</property>
</bean>
<!-- 访问本地数据库 并且采用自己的密码加密 -->
<bean id="dbAuthHandler"
class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"
p:dataSource-ref="dataSource"
p:sql="SELECT u.`password` FROM `tb_user` u WHERE u.`username` = ?"
p:passwordEncoder-ref="myPasswordEncoder" />
<!-- 密码加密 -->
<bean id="myPasswordEncoder" class="org.jasig.cas.authentication.handler.MyPasswordEncoder" />
<!-- 指定c3p0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://192.168.1.210:3306/sso_test?useUnicode=true&characterEncoding=UTF-8" />
<property name="user" value="root" />
<property name="password" value="123456" />
</bean>
6.客户端校验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://demo.micmiu.com:8080/cas</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://app1.micmiu.com:18080</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>