3获取初始请求的URL

3获取初始请求的URL

本文介绍了Spring Security 3获取初始请求的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据用户的来源来修改spring安全性登录页面.我的客户希望两者之间的样式不同.如果您来自appcontextroot/testappcontextroot/choose.我尝试执行以下操作,但String url=savedRequest.getRedirectUrl();已经等于spring登录页面,而不是用户请求的初始页面.有什么想法吗?

I need to modify my spring security login page based on where the user came from. My client wants the styles different between the two. If you come from appcontextroot/test vs appcontextroot/choose. I tried to do the below but the String url=savedRequest.getRedirectUrl(); is equal to the spring login page already and not the initial page requested by the user. Any ideas?

ExternalContext externalContext = FacesUtils.getExternalContext();
    HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
    HttpSession session = request.getSession(false);
    if(session != null) {
        SavedRequest savedRequest = new DefaultSavedRequest(request, new PortResolverImpl());
        String url=savedRequest.getRedirectUrl();
    }

推荐答案

您需要从会话中提取SavedRequest,而不是创建新会话:

You need to extract SavedRequest from the session, not to create a new one:

SavedRequest savedRequest =
    new HttpSessionRequestCache().getRequest(request, response);

这篇关于Spring Security 3获取初始请求的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:43