Skip to content

Commit 4f3faa7

Browse files
Revisit Session Management docs
Closes gh-12519
1 parent ca1961d commit 4f3faa7

File tree

2 files changed

+825
-171
lines changed

2 files changed

+825
-171
lines changed

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

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

266266
include::partial$servlet/architecture/request-cache-continue.adoc[]
267267

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

0 commit comments

Comments
 (0)