0

我试图在成功登录后将用户重定向到上一页,但每次我都重定向到“/”。有我的配置:

<bean id="rememberMeFilter"     class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter">
    <constructor-arg name="rememberMeServices" ref="rememberMeServices"/>
    <constructor-arg name="authenticationManager" ref="authenticationManager" />
</bean>

<bean id="rememberMeServices" class="org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices" >
    <constructor-arg name="tokenRepository" ref="persistentTokenRepository" />
    <constructor-arg name="userDetailsService" ref="customUserDetailService"/>
    <constructor-arg name="key" value="token"/>
    <property name="cookieName" value="token" />
    <property name="tokenValiditySeconds" value="864000" />
</bean>

<bean id="rememberMeAuthenticationProvider" class="org.springframework.security.authentication.RememberMeAuthenticationProvider">
    <constructor-arg name="key" value="token"/>
</bean>

<bean id="persistentTokenRepository" class="com.youtasked.spring.auth.MongoPersistentTokenRepositoryImpl" />

<sec:http auto-config="true" use-expressions="true">
    <sec:session-management />
    <sec:form-login login-page="/login" default-target-url="/" always-use-default-target="true" authentication-failure-url="/login?error=true"
                    login-processing-url="/j_spring_security_check" authentication-success-handler-ref="successLoginHandler"/>
    <sec:logout logout-success-url="/logout" delete-cookies="true" invalidate-session="true" />
    <sec:remember-me services-ref="rememberMeServices" use-secure-cookie="true" />
</sec:http>

<bean id="successLoginHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
    <property name="useReferer" value="true" />
</bean>

<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder" />
<bean id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource">
    <property name="userPropertyToUse" value="email" />
</bean>
<bean id="customUserDetailService" class="com.youtasked.core.user.CustomUserDetailService" />

<sec:authentication-manager alias="authenticationManager">
    <sec:authentication-provider user-service-ref="customUserDetailService">
        <sec:password-encoder ref="passwordEncoder">
            <sec:salt-source ref="saltSource"></sec:salt-source>
        </sec:password-encoder>
    </sec:authentication-provider>
    <sec:authentication-provider ref="rememberMeAuthenticationProvider" />
</sec:authentication-manager>

SavedRequestAwareAuthenticationSuccessHandler每次我都从中得到空值requestCache但我认为这应该是以前的请求。我也在阅读ExceptionTranslationFilter和一些使用它来保存请求的神奇方法,但我找不到任何示例

4

0 回答 0