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
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authentication/session-management.adoc
+4-90Lines changed: 4 additions & 90 deletions
Original file line number
Diff line number
Diff line change
@@ -3,49 +3,7 @@
3
3
4
4
Once you have got an application that is xref:servlet/authentication/index.adoc[authenticating requests], it is important to consider how that resulting authentication will be persisted and restored on future requests.
5
5
6
-
This is done automatically by default, so no additional code is necessary, though there are some steps you should consider. The first is setting the `requireExplicitSave` property in `HttpSecurity`.
7
-
You can do it like so:
8
-
9
-
====
10
-
.Java
11
-
[source,java,role="primary"]
12
-
----
13
-
@Bean
14
-
public SecurityFilterChain filterChain(HttpSecurity http) {
15
-
http
16
-
// ...
17
-
.securityContext((context) -> context
18
-
.requireExplicitSave(true)
19
-
);
20
-
return http.build();
21
-
}
22
-
----
23
-
24
-
.Kotlin
25
-
[source,kotlin,role="secondary"]
26
-
----
27
-
@Bean
28
-
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
29
-
http {
30
-
// ...
31
-
securityContext {
32
-
requireExplicitSave = true
33
-
}
34
-
}
35
-
return http.build()
36
-
}
37
-
----
38
-
39
-
.XML
40
-
[source,xml,role="secondary"]
41
-
----
42
-
<http security-context-explicit-save="true">
43
-
<!-- ... -->
44
-
</http>
45
-
----
46
-
====
47
-
48
-
The most straightforward reason for this is that it is xref:migration/servlet/session-management.adoc#_require_explicit_saving_of_securitycontextrepository[becoming the default value in 6.0], so this will make sure you are ready for that.
6
+
This is done automatically by default, so no additional code is necessary, though it is important to know what `requireExplicitSave` means in `HttpSecurity`.
49
7
50
8
If you like, <<how-it-works-requireexplicitsave,you can read more about what requireExplicitSave is doing>> or <<requireexplicitsave,why it's important>>. Otherwise, in most cases you are done with this section.
51
9
@@ -96,51 +54,9 @@ The problem with this is that it means that in a typical setup, the `HttpSession
96
54
In Spring Security 6, the default is that authentication mechanisms themselves must invoke the `SessionAuthenticationStrategy`.
97
55
This means that there is no need to detect when `Authentication` is done and thus the `HttpSession` does not need to be read for every request.
98
56
99
-
To opt into the new Spring Security 6 default, the following configuration should be used.
==== Things To Consider When Moving Away From `SessionManagementFilter`
142
58
143
-
When `requireExplicitAuthenticationStrategy = true`, it means that the `SessionManagementFilter` will not be used, therefore, some methods from the `sessionManagement` DSL will not have any effect.
59
+
In Spring Security 6, the `SessionManagementFilter` is not used by default, therefore, some methods from the `sessionManagement` DSL will not have any effect.
144
60
145
61
|===
146
62
|Method |Replacement
@@ -155,7 +71,7 @@ When `requireExplicitAuthenticationStrategy = true`, it means that the `SessionM
155
71
|Configure an `SessionAuthenticationStrategy` in your authentication mechanism as <<moving-away-from-sessionmanagementfilter,discussed above>>
156
72
|===
157
73
158
-
In Spring Security 6, if you try to use any of these methods when `requireExplicitAuthenticationStrategy = true` (the default), an exception will be thrown.
74
+
If you try to use any of these methods, an exception will be thrown.
159
75
160
76
161
77
[[customizing-where-authentication-is-stored]]
@@ -186,7 +102,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) {
186
102
http
187
103
// ...
188
104
.securityContext((context) -> context
189
-
.requireExplicitSave(true)
190
105
.securityContextRepository(repo)
191
106
);
192
107
return http.build();
@@ -202,7 +117,6 @@ open fun filterChain(http: HttpSecurity): SecurityFilterChain {
202
117
http {
203
118
// ...
204
119
securityContext {
205
-
requireExplicitSave = true
206
120
securityContextRepository = repo
207
121
}
208
122
}
@@ -213,7 +127,7 @@ open fun filterChain(http: HttpSecurity): SecurityFilterChain {
0 commit comments