How can i redirect to the originally requested page after login?

1 message Options
Embed this post
Permalink
aiya

How can i redirect to the originally requested page after login?

Reply Threaded More More options
Print post
Permalink
dear every one:
i use spring security and CAS to do my job ,i found it cannot redirect to the originally requested page, i read the reference book of ss,get some tip on SavedRequestAwareAuthenticationSuccessHandler,Exce ptionTranslationFilter
but i get no idea on how to config them
i post my config file as below ,i hope some one can help me out,thanks a lot!

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
        xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/security 
           http://www.springframework.org/schema/security/spring-security-3.0.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
        <http auto-config="true" entry-point-ref="casProcessingFilterEntryPoint"
                session-fixation-protection="migrateSession" servlet-api-provision="true"
                   
                access-denied-page="/accessDenied.html">
                <!-- 注销控制 -->
                <logout invalidate-session="true"
                        logout-success-url="http://10.200.250.222:3030/cas/logout" logout-url="/j_spring_security_logout" />
                <!-- 同步session控制过滤器 -->
                <concurrent-session-control />
                <!-- 默认用户名称 -->
                <anonymous username="Guest" />
        </http>
        <!--
                <http auto-config='true'
                entry-point-ref="casProcessingFilterEntryPoint"> <intercept-url
                pattern="/index.html" access="ROLE_USER" /> <intercept-url
                pattern="/bin/EconomicEvaluationDataEdit.html" access="ROLE_ADMIN" />
                <intercept-url pattern="/bin/EconomicEvaluationIndex.html"
                access="ROLE_USER" /> <intercept-url pattern="/" access="ROLE_USER" />
                <logout logout-success-url="/cas-logout.jsp" />
                <concurrent-session-control /> </http>
        -->
        <authentication-manager alias="authenticationManager" />
        <beans:bean id="casProcessingFilter"
                class="org.springframework.security.cas.web.CasProcessingFilter">
                <custom-filter after="CAS_PROCESSING_FILTER" />
                <beans:property name="authenticationManager" ref="authenticationManager" />
                 <beans:property name="authenticationSuccessHandler"
                        ref="authenticationSuccessHandlerBean"></beans:property>
                       
                <beans:property name="authenticationFailureHandler"
                        ref="authenticationFailureHandlerBean"></beans:property>
        </beans:bean>
       
       
        <beans:bean id="exceptionTranslationFilter"
class="org.springframework.security.web.access.ExceptionTranslationFilter">
<beans:property name="authenticationEntryPoint" ref="casProcessingFilterEntryPoint"/>
</beans:bean>



        <beans:bean id="casProcessingFilterEntryPoint"
                class="org.springframework.security.cas.web.CasProcessingFilterEntryPoint">
                <beans:property name="loginUrl"
                        value="http://10.200.250.222:3030/cas/login" />
                <beans:property name="serviceProperties" ref="casServiceProperties" />
        </beans:bean>
        <beans:bean id="casServiceProperties"
                class="org.springframework.security.cas.ServiceProperties">
                <beans:property name="service"
                        value="http://10.200.250.222:3030/EconomicEvaluation/j_spring_cas_security_check" />
                <beans:property name="sendRenew" value="false" />
        </beans:bean>
        <beans:bean id="casAuthenticationProvider"
                class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
                <custom-authentication-provider />
                <beans:property name="userDetailsService" ref="userService" />
                <beans:property name="serviceProperties" ref="casServiceProperties" />
                <beans:property name="ticketValidator">
                        <beans:bean
                                class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
                                <beans:constructor-arg index="0"
                                        value="http://10.200.250.222:3030/cas" />
                        </beans:bean>
                </beans:property>
                <beans:property name="key"
                        value="an_id_for_this_auth_provider_only" />
        </beans:bean>
        <!-- 登录成功Handler-->
        <beans:bean id="authenticationSuccessHandlerBean"
                class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
               
        </beans:bean>
       
        <!-- 登录失败Handler -->
        <beans:bean id="authenticationFailureHandlerBean"
                class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
                <beans:property name="defaultFailureUrl" value="/accessDenied.html"></beans:property>
        </beans:bean>
        <!-- 替换系统原来创建的那个过滤器 -->
        <beans:bean id="filterSecurityInterceptor"
                class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"
                autowire="byType">
                <custom-filter before="FILTER_SECURITY_INTERCEPTOR" />
                <beans:property name="objectDefinitionSource" ref="filterInvocationDefinitionSource" />
        </beans:bean>
        <beans:bean id="filterSecurityInterceptorAfter"
                class="com.yyhy.sso.web.access.intercepter.FilterSecurityInterceptor"
                autowire="byType">
                <custom-filter after="FILTER_SECURITY_INTERCEPTOR" />
                <beans:property name="sessionFactory" ref="sessionFactory" />
                <beans:property name="globeUserinfo" ref="globeUserinfoBean" />
        </beans:bean>
        <!--
                old one <authentication-provider> <jdbc-user-service id="userService"
                data-source-ref="DB" cache-ref="userCache"
                users-by-username-query="select username,password,status as enabled
                from users where username=?" authorities-by-username-query="select
                u.username,r.name as authority from user_user u join user_roles ur on
                u.id=ur.user_id join role r on r.id=ur.role_id where u.username=?" />
                </authentication-provider>
        -->
        <authentication-provider>
                <jdbc-user-service id="userService" data-source-ref="DB"
                        cache-ref="userCache"
                        users-by-username-query="select username,password,status as enabled from USER_USER where username=? and status='1'"
                        authorities-by-username-query="select U.username,UR.NAME as authority from USER_USER U join USER_RELATION_UG RUG on U.id= RUG.USER_ID join USER_GROUP UG on RUG.GROUP_ID = UG.ID join USER_RELATION_GR RGR on RUG.GROUP_ID = RGR.GROUP_ID join USER_ROLE UR on RGR.ROLE_ID = UR.ID where U.USERNAME = ? and U.STATUS='1' and UG.STATUS='1' and UR.STATUS='1'" />
        </authentication-provider>
        <!--
                old one <beans:bean id="filterInvocationDefinitionSource"
                class="com.yyhy.sso.JdbcFilterInvocationDefinitionSourceFactoryBean">
                <beans:property name="dataSource" ref="DB" /> <beans:property
                name="resourceQuery" value="select re.res_string,r.name from role r
                join resc_role rr on r.id=rr.role_id join resc re on re.id=rr.resc_id
                where website='1' order by re.priority desc" /> </beans:bean>
        -->
        <beans:bean id="filterInvocationDefinitionSource"
                class="com.yyhy.sso.JdbcFilterInvocationDefinitionSourceFactoryBean">
                <beans:property name="dataSource" ref="DB" />
                <beans:property name="resourceQuery"
                        value="select RE.resc_string,R.name from USER_ROLE R join USER_RELATION_RR URR on R.ID=URR.ROLE_ID join USER_RESC RE on RE.ID = URR.RESC_ID and RE.WEBSITE = 'EconomicEvaluation' and R.STATUS = '1' and RE.STATUS = '1' order by RE.PRIORITY asc" />
        </beans:bean>
        <!-- 用户信息缓存 -->
        <beans:bean id="userCache"
                class="org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache">
                <beans:property name="cache" ref="userEhCache" />
        </beans:bean>
        <beans:bean id="userEhCache"
                class="org.springframework.cache.ehcache.EhCacheFactoryBean">
                <beans:property name="cacheManager" ref="cacheManager" />
                <beans:property name="cacheName" value="userCache" />
        </beans:bean>
        <beans:bean id="cacheManager"
                class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
        <beans:bean id="globeUserinfoBean" class="com.yyhy.sso.privilege.bean.Userinfo"
                scope="session">
                <aop:scoped-proxy />
        </beans:bean>
</beans:beans>