随笔 - 0, 文章 - 2, 评论 - 0, 引用 - 0
数据加载中……

cas3.4.3.1客户端使用

下面介绍用http协议使用cas单点登录系统。
一,前提条件
    1,cas服务器部署测试成功。
    2,下载cas-client-core-3.1.10.jar到你的应用lib目录下。
二,客户端配置(这里使用spring的方式来配置,spring本身的配置这里就不描述了)
    1,配置web.xml文件,cas有4个filter需要配置,配置顺序不能改变,

         <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 Authentication Filter</filter-name>
             <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
             <init-param>
                  <param-name>targetBeanName</param-name>
                  <param-value>casAuthenticationFilter</param-value>
             </init-param>
        </filter>

<filter>
 <filter-name>CAS Validation Filter</filter-name>
 <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 <init-param>
  <param-name>targetBeanName</param-name>
  <param-value>casValidationFilter</param-value>
 </init-param>
</filter>

<filter>
 <filter-name>CAS HttpServletRequestWrapperFilter</filter-name>
 <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 <init-param>
  <param-name>targetBeanName</param-name>
  <param-value>casHttpServletRequestWrapperFilter</param-value>
 </init-param>
</filter>

<filter-mapping>
 <filter-name>CAS Single Sign Out Filter</filter-name>
 <url-pattern>*.do</url-pattern>
</filter-mapping>

<filter-mapping>
 <filter-name>CAS Authentication Filter</filter-name>
 <url-pattern>*.do</url-pattern>
</filter-mapping>

<filter-mapping>
 <filter-name>CAS Validation Filter</filter-name>
 <url-pattern>*.do</url-pattern>
</filter-mapping>

<filter-mapping>
 <filter-name>CAS HttpServletRequestWrapperFilter</filter-name>
 <url-pattern>*.do</url-pattern>
</filter-mapping>

        2,spring文件的配置,新增一个spring配置文件,文件名随意,我这里叫做applicationContext-cas.xml,文件内容为

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util"
 xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
 default-autowire="byName" default-lazy-init="false">

 <bean id="casAuthenticationFilter"
  class="org.jasig.cas.client.authentication.AuthenticationFilter">
  <property name="casServerLoginUrl" value="${cas.url}/login" />
  <property name="serverName" value="${project.url}" />
  <property name="renew" value="false" />
  <property name="gateway" value="false" />
  
 </bean>

 <bean id="casValidationFilter"
  class="org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter">
  <property name="ticketValidator">
   <ref bean="Cas20ServiceTicketValidator" />
  </property>
  <property name="useSession" value="true" />
  <property name="serverName" value="${project.url}" />
  <property name="redirectAfterValidation" value="true" />
 </bean>

 <bean id="Cas20ServiceTicketValidator"
  class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
  <constructor-arg index="0" value="${cas.url}" />
 </bean>

 <bean id="casHttpServletRequestWrapperFilter"
  class="org.jasig.cas.client.util.HttpServletRequestWrapperFilter" />
</beans>

 上面红色部分的意思是: cas.url是你cas服务器的地址,project.url是你客户端应用的地址。下面是我本地的配置

    #cas服务器地址
    cas.url=http://127.0.0.1:8080/cas
    #客户端url地址
    project.url=http://127.0.0.1:8080

3,客户端数据库的配置

    建议cas服务器和客户端公用同一个数据库,如果分开,就会涉及到数据同步问题。

posted on 2011-04-11 10:30 汪长军 阅读(1195) 评论(0)  编辑  收藏 所属分类: cas单点登录


只有注册用户登录后才能发表评论。


网站导航: