You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* image:{icondir}/number_1.png[] First, the `ExceptionTranslationFilter` invokes `FilterChain.doFilter(request, response)` to invoke the rest of the application.
214
214
* image:{icondir}/number_2.png[] If the user is not authenticated or it is an `AuthenticationException`, then __Start Authentication__.
215
215
** The xref:servlet/authentication/architecture.adoc#servlet-authentication-securitycontextholder[SecurityContextHolder] is cleared out
216
-
** The `HttpServletRequest` is saved in the {security-api-url}org/springframework/security/web/savedrequest/RequestCache.html[`RequestCache`].
217
-
When the user successfully authenticates, the `RequestCache` is used to replay the original request.
216
+
** The `HttpServletRequest` is <<savedrequests,saved>> so that it can be used to replay the original request once authentication is successful.
218
217
// FIXME: add link to authentication success
219
218
** The `AuthenticationEntryPoint` is used to request credentials from the client.
220
219
For example, it might redirect to a log in page or send a `WWW-Authenticate` header.
@@ -247,3 +246,26 @@ try {
247
246
This means that if another part of the application, (i.e. xref:servlet/authorization/authorize-requests.adoc#servlet-authorization-filtersecurityinterceptor[`FilterSecurityInterceptor`] or method security) throws an `AuthenticationException` or `AccessDeniedException` it will be caught and handled here.
248
247
<2> If the user is not authenticated or it is an `AuthenticationException`, then __Start Authentication__.
249
248
<3> Otherwise, __Access Denied__
249
+
250
+
[[savedrequests]]
251
+
== Saving Requests Between Authentication
252
+
253
+
As illustrated in <<servlet-exceptiontranslationfilter>>, when a request has no authentication and is for a resource that requires authentication, there is a need to save the request for the authenticated resource to re-request after authentication is successful.
254
+
In Spring Security this is done by saving the `HttpServletRequest` using a <<requestcache,`RequestCache`>> implementation.
255
+
256
+
[[requestcache]]
257
+
=== RequestCache
258
+
259
+
The `HttpServletRequest` is saved in the {security-api-url}org/springframework/security/web/savedrequest/RequestCache.html[`RequestCache`].
260
+
When the user successfully authenticates, the `RequestCache` is used to replay the original request.
261
+
The <<requestcacheawarefilter,`RequestCacheAwareFilter`>> is what uses the `RequestCache` to save the `HttpServletRequest`.
262
+
263
+
By default, an `HttpSessionRequestCache` is used.
264
+
The code below demonstrates how to customize the `RequestCache` implementation that is used to check the `HttpSession` for a saved request if the parameter named `continue` is present.
The {security-api-url}org/springframework/security/web/savedrequest/RequestCacheAwareFilter.html[`RequestCacheAwareFilter`] uses the <<requestcache,`RequestCache`>> to save the `HttpServletRequest`.
0 commit comments