Spring Security - Retaining URL parameters on redirect to login

后端 未结 4 846
攒了一身酷
攒了一身酷 2020-12-08 20:23

ok.

lets say I have a secure url pattern

/secure/link-profile

optionally, there can be url paramaters appended.

/se         


        
4条回答
  •  庸人自扰
    2020-12-08 21:02

    as per @zagyi's response I just overrode a method in my existing extension of AuthenticationProcessingFilterEntryPoint

    the method to override is protected String determineUrlToUseForThisRequest(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) which is called by buildRedirectUrlToLoginPage(..

    @Override
    protected String determineUrlToUseForThisRequest(HttpServletRequest request, HttpServletResponse response,
            AuthenticationException exception) {
        String url = super.determineUrlToUseForThisRequest(request, response, exception);
        return url + "?" + request.getQueryString();
    }
    

    obviously that could be improved to also use a builder of sorts, catering for an existing query string on the url, but at this time I know my login url is always /login/, so this is fine for my purposes

提交回复
热议问题