简体   繁体   English

将查询参数传递给下一页

[英]Pass on query param to next page

<beans:bean id="successHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
    <beans:property name="defaultTargetUrl" value="/order.htm"/>
    <beans:property name="alwaysUseDefaultTargetUrl" value="true"/>         
</beans:bean>

Hi, i have a success handler like above.嗨,我有一个像上面那样的成功处理程序。 When the user lands on login page with query param, i need to retain the query param on post login pages.当用户登陆带有查询参数的登录页面时,我需要在登录后页面上保留查询参数。 how can i achieve that?我怎样才能做到这一点? I managed to see the request params in successfulAuthentication method which authenticates the user.我设法在对用户进行身份验证的successfulAuthentication方法中看到了请求参数。 the only challenge is how to pass on the same query params to next page some thing like below?唯一的挑战是如何将相同的查询参数传递到下一页,如下所示? or any other better way?或任何其他更好的方法?

<beans:property name="defaultTargetUrl" value="/order.htm?paramTest=pp1"/>

Edit SavedRequestAwareAuthenticationSuccessHandler has the capability to retain the previous url(here url with query param in this case), but i have defaultTargetUrl set to new url, which is why its not effective.编辑SavedRequestAwareAuthenticationSuccessHandler 能够保留以前的 url(在本例中为 url 和查询参数),但我将 defaultTargetUrl 设置为新的 url,这就是它无效的原因。 any possibilities to build the new defaultTargetUrl with query params from the previous login page?是否有可能使用先前登录页面的查询参数构建新的 defaultTargetUrl?

I managed to override SavedRequestAwareAuthenticationSuccessHandler to achieve the same我设法覆盖 SavedRequestAwareAuthenticationSuccessHandler 以实现相同的目的

public class CustomSavedRequestAwareAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

private final Logger logger = ResmedLogger.getInstance().getTraceLogger();

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    HttpSession session = request.getSession();
    if (session != null) {
        String paramTest = (String) session.getAttribute("paramTest");
        logger.info("paramTest="+paramTest);
        if (paramTest != null) {
            // we do not forget to clean this attribute from session
            session.removeAttribute("paramTest");
            // then we redirect
            getRedirectStrategy().sendRedirect(request, response, "/order.htm?paramTest="+paramTest);
        } else {
            super.onAuthenticationSuccess(request, response, authentication);
        }
    } else {
        super.onAuthenticationSuccess(request, response, authentication);
    }
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM