It appears that when CSRF protection is enabled, Spring Security only puts your original request in requestCacheif the request used the method GET. To have cache POSTrequests, I created a custom one requestCache.
I am not 100% sure that this will not weaken the protection of CSRF, but it seems to me safe.
Add the bean request cache to the XML configuration:
<bean id="requestCache" class="a.b.c.AlwaysSaveRequestCache" />
<http>
<csrf />
<request-cache ref="requestCache" />
</http>
Implement custom query cache by extending and borrowing code from HttpSessionRequestCache:
public class AlwaysSaveRequestCache extends HttpSessionRequestCache
{
@Override
public void saveRequest(HttpServletRequest request, HttpServletResponse response)
{
final String SAVED_REQUEST = "SPRING_SECURITY_SAVED_REQUEST";
DefaultSavedRequest savedRequest = new DefaultSavedRequest(request, new PortResolverImpl());
request.getSession().setAttribute(SAVED_REQUEST, savedRequest);
logger.debug("DefaultSavedRequest added to Session: " + savedRequest);
}
}
Your requests POSTshould now be cached and resubmitted after the login form is interrupted.
source
share