0

login.jsp ページの非表示の値に基づいてページをリダイレクトしたいのですが、これが私のコードです

public class AuthenticationHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    private final String HASH_URL = "hashURL";

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
        super.onAuthenticationSuccess(request, response, authentication);

        String hashValue = request.getParameter(HASH_URL);
        if(hashValue != null){
            if(!hashValue.isEmpty()){
                setDefaultTargetUrl("/home/" + hashValue);
            }
        }
    }
}

hashValue が login.jsp ページから最新の値を取得していることがわかりますが、常にサイト /home/ ページを移動しています。これが私の構成です

<security:form-login
                login-page="/auth/login"
                default-target-url="/home/"
                authentication-success-handler-ref="customAuthenticationSuccessHandler"
                always-use-default-target="true"
                authentication-failure-url="/auth/login?error=true"/>
4

2 に答える 2

1

以前の問題Redirecting URL after user Logout to previous page opensでこれをすでに引用しました

認証が成功した後、SavedRequestAwareAuthenticationSuccessHandler:
alwaysUseDefaultTargetUrl プロパティが true に設定されている場合、defaultTargetUrl
宛先に使用されます。
セッションに保存されている DefaultSavedRequest はすべて削除されます。

したがって、always-use-default-target="false" を設定する必要があります。また、default-target-url 属性を削除することもできます。

お役に立てれば。

于 2013-07-12T11:48:40.900 に答える