Skip to content

Commit ce222de

Browse files
Merge branch '5.8.x' into 6.0.x
Closes gh-12680
2 parents 8ab0bf7 + 4f3faa7 commit ce222de

File tree

2 files changed

+836
-183
lines changed

2 files changed

+836
-183
lines changed

docs/modules/ROOT/pages/servlet/architecture.adoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,60 @@ The code below demonstrates how to customize the `RequestCache` implementation t
271271

272272
include::partial$servlet/architecture/request-cache-continue.adoc[]
273273

274+
[[requestcache-prevent-saved-request]]
275+
==== Prevent the Request From Being Saved
276+
277+
There are a number of reasons you may want to not store the user's unauthenticated request in the session.
278+
You may want to offload that storage onto the user's browser or store it in a database.
279+
Or you may want to shut off this feature since you always want to redirect the user to the home page instead of the page they tried to visit before login.
280+
281+
To do that, you can use {security-api-url}org/springframework/security/web/savedrequest/NullRequestCache.html[the `NullRequestCache` implementation].
282+
283+
.Prevent the Request From Being Saved
284+
====
285+
.Java
286+
[source,java,role="primary"]
287+
----
288+
@Bean
289+
SecurityFilterChain springSecurity(HttpSecurity http) throws Exception {
290+
RequestCache nullRequestCache = new NullRequestCache();
291+
http
292+
// ...
293+
.requestCache((cache) -> cache
294+
.requestCache(nullRequestCache)
295+
);
296+
return http.build();
297+
}
298+
----
299+
300+
.Kotlin
301+
[source,kotlin,role="secondary"]
302+
----
303+
@Bean
304+
open fun springSecurity(http: HttpSecurity): SecurityFilterChain {
305+
val nullRequestCache = NullRequestCache()
306+
http {
307+
requestCache {
308+
requestCache = nullRequestCache
309+
}
310+
}
311+
return http.build()
312+
}
313+
----
314+
315+
.XML
316+
[source,xml,role="secondary"]
317+
----
318+
<http auto-config="true">
319+
<!-- ... -->
320+
<request-cache ref="nullRequestCache"/>
321+
</http>
322+
323+
<b:bean id="nullRequestCache" class="org.springframework.security.web.savedrequest.NullRequestCache"/>
324+
----
325+
====
326+
327+
274328
[[requestcacheawarefilter]]
275329
=== RequestCacheAwareFilter
276330

0 commit comments

Comments
 (0)