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();
}
You need to extract SavedRequest
from the session, not to create a new one:
SavedRequest savedRequest =
new HttpSessionRequestCache().getRequest(request, response);
SavedRequest savedRequest =
(SavedRequest)session.getAttribute("SPRING_SECURITY_SAVED_REQUEST");
// ...check for null...
String targetUrl = savedRequest.getRedirectUrl();
Ugly but working, if you don't have the HttpServletResponse available (e.g. in case you use org.springframework.social.connect.web.SignInAdapter
).
Tested with Spring Security 3.1.0.RC2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With