隨筆 - 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 汪長軍 閱讀(1201) 評論(0)  編輯  收藏 所屬分類: cas單點登錄


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 会宁县| 秀山| 洛浦县| 沙河市| 英超| 台南县| 樟树市| 天祝| 化州市| 台北县| 阳曲县| 密云县| 万荣县| 蒙自县| 鄯善县| 孝昌县| 桃园县| 尤溪县| 迁安市| 长葛市| 荃湾区| 专栏| 镇平县| 虞城县| 山阳县| 赞皇县| 阳信县| 镇巴县| 成武县| 双江| 大埔县| 灌南县| 集贤县| 张北县| 体育| 慈利县| 运城市| 象州县| 胶州市| 开封市| 科技|