Spring使用DelegatingFilterProxy进行集成cas过滤器

来源: 易习特达网 www.easytd.com 时间: 2016-10-17 15:35:14

cas客户端使用3.3.2,依赖cas-client-core.3.3.2.jar

客户端配置文件:

spring-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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"

    xmlns:sec="http://www.springframework.org/schema/security"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd

       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd

       http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">

    <!-- 读取配置文件 -->

    <context:property-placeholder location="classpath*:cas.properties" ignore-unresolvable="true" />


    <bean name="singleSignOutFilter" class='fix_imgof_html' "org.jasig.cas.client.session.SingleSignOutFilter" />


    <bean name="authenticationFilter" class='fix_imgof_html' "org.jasig.cas.client.authentication.AuthenticationFilter" p:renew="false"

        p:gateway="false" p:casServerLoginUrl="${cas.server.login.url}" p:serverName="${server.name}" />


    <bean name="ticketValidationFilter" class='fix_imgof_html' "org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter"

        p:redirectAfterValidation="true" p:serverName="${server.name}">

        <property name="ticketValidator">

            <bean class='fix_imgof_html' "org.jasig.cas.client.validation.Cas20ServiceTicketValidator">

                <constructor-arg index="0" value="${cas.server.url}" />

            </bean>

        </property>

    </bean>


    <bean name="httpServletRequestWrapperFilter" class='fix_imgof_html' "org.jasig.cas.client.util.HttpServletRequestWrapperFilter" />


    <bean name="assertionThreadLocalFilter" class='fix_imgof_html' "org.jasig.cas.client.util.AssertionThreadLocalFilter" />


</beans>


web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

    metadata-complete="true">

    <display-name>Archetype Created Web Application</display-name>


    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>

            classpath*:/applicationContext-cas.xml

        </param-value>

    </context-param>


    <listener>

        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>


    <!-- 用于单点退出,该过滤器用于实现单点登出功能,可选配置 The SingleSignOutFilter can affect character 

        encoding. -->

    <listener>

        <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>

    </listener>


    <!-- Filter 定义 -->

    <!-- Character Encoding filter -->

    <filter>

        <filter-name>encodingFilter</filter-name>

        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

        <init-param>

            <param-name>encoding</param-name>

            <param-value>UTF-8</param-value>

        </init-param>

        <init-param>

            <param-name>forceEncoding</param-name>

            <param-value>true</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>encodingFilter</filter-name>

        <url-pattern>/*</url-pattern>

        <dispatcher>REQUEST</dispatcher>

        <dispatcher>FORWARD</dispatcher>

    </filter-mapping>

    

    <!-- Spring mvc -->

    <servlet>

        <servlet-name>springServlet</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>/WEB-INF/spring-mvc.xml</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>

        <servlet-name>springServlet</servlet-name>

        <url-pattern>/</url-pattern>

    </servlet-mapping>


    <servlet>

        <servlet-name>cas oss info</servlet-name>

        <servlet-class>com.gqshao.cas.servlet.InfoServlet</servlet-class>

    </servlet>

    <servlet-mapping>

        <servlet-name>cas oss info</servlet-name>

        <url-pattern>/info</url-pattern>

    </servlet-mapping>


    <servlet>

        <servlet-name>cas oss logout</servlet-name>

        <servlet-class>com.gqshao.cas.servlet.LogoutServlet</servlet-class>

    </servlet>

    <servlet-mapping>

        <servlet-name>cas oss logout</servlet-name>

        <url-pattern>/logout</url-pattern>

    </servlet-mapping>


    <!--1.用于单点退出 -->

    <filter>

        <filter-name>CAS Single Sign Out Filter</filter-name>

        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

        <init-param>

            <param-name>targetBeanName</param-name>

            <param-value>singleSignOutFilter</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>CAS Single Sign Out Filter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>


    <!--2.负责Ticket校验 -->

    <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>ticketValidationFilter</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>CAS Validation Filter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>


    <!-- 3. 单点登录验证 -->

    <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>authenticationFilter</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>CAS Authentication Filter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>


    <!--4. CAS HttpServletRequest Wrapper Filter 这个是HttpServletRequet的包裹类,让他支持getUserPrincipal,getRemoteUser方法来取得用户信息 -->

    <filter>

        <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>

        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

        <init-param>

            <param-name>targetBeanName</param-name>

            <param-value>httpServletRequestWrapperFilter</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

    <!--5. CAS Assertion Thread Local Filter 这个类把Assertion信息放在ThreadLocal变量中,这样应用程序不在web层也能够获取到当前登录信息 -->

    <filter>

        <filter-name>CAS Assertion Thread Local Filter</filter-name>

        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

        <init-param>

            <param-name>targetBeanName</param-name>

            <param-value>assertionThreadLocalFilter</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>CAS Assertion Thread Local Filter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

</web-app>

本页地址:http://www.easytd.com/chengxudaima/d_16101715919.html

常用工具