Skip to content

Commit e59f71f

Browse files
Polish session-management.adoc
Remove default values from configuration Issue gh-12519
1 parent ce222de commit e59f71f

File tree

1 file changed

+4
-90
lines changed

1 file changed

+4
-90
lines changed

docs/modules/ROOT/pages/servlet/authentication/session-management.adoc

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,7 @@
33

44
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.
55

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`.
497

508
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.
519

@@ -96,51 +54,9 @@ The problem with this is that it means that in a typical setup, the `HttpSession
9654
In Spring Security 6, the default is that authentication mechanisms themselves must invoke the `SessionAuthenticationStrategy`.
9755
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.
9856

99-
To opt into the new Spring Security 6 default, the following configuration should be used.
100-
101-
.Require Explicit `SessionAuthenticationStrategy` Invocation
102-
====
103-
.Java
104-
[source,java,role="primary"]
105-
----
106-
@Bean
107-
SecurityFilterChain springSecurity(HttpSecurity http) throws Exception {
108-
http
109-
// ...
110-
.sessionManagement((sessions) -> sessions
111-
.requireExplicitAuthenticationStrategy(true)
112-
);
113-
return http.build();
114-
}
115-
----
116-
117-
.Kotlin
118-
[source,kotlin,role="secondary"]
119-
----
120-
@Bean
121-
open fun springSecurity(http: HttpSecurity): SecurityFilterChain {
122-
http {
123-
sessionManagement {
124-
requireExplicitAuthenticationStrategy = true
125-
}
126-
}
127-
return http.build()
128-
}
129-
----
130-
131-
.XML
132-
[source,xml,role="secondary"]
133-
----
134-
<http>
135-
<!-- ... -->
136-
<session-management authentication-strategy-explicit-invocation="true"/>
137-
</http>
138-
----
139-
====
140-
14157
==== Things To Consider When Moving Away From `SessionManagementFilter`
14258

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.
14460

14561
|===
14662
|Method |Replacement
@@ -155,7 +71,7 @@ When `requireExplicitAuthenticationStrategy = true`, it means that the `SessionM
15571
|Configure an `SessionAuthenticationStrategy` in your authentication mechanism as <<moving-away-from-sessionmanagementfilter,discussed above>>
15672
|===
15773

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.
15975

16076

16177
[[customizing-where-authentication-is-stored]]
@@ -186,7 +102,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) {
186102
http
187103
// ...
188104
.securityContext((context) -> context
189-
.requireExplicitSave(true)
190105
.securityContextRepository(repo)
191106
);
192107
return http.build();
@@ -202,7 +117,6 @@ open fun filterChain(http: HttpSecurity): SecurityFilterChain {
202117
http {
203118
// ...
204119
securityContext {
205-
requireExplicitSave = true
206120
securityContextRepository = repo
207121
}
208122
}
@@ -213,7 +127,7 @@ open fun filterChain(http: HttpSecurity): SecurityFilterChain {
213127
.XML
214128
[source,xml,role="secondary"]
215129
----
216-
<http security-context-explicit-save="true" security-context-repository-ref="repo">
130+
<http security-context-repository-ref="repo">
217131
<!-- ... -->
218132
</http>
219133
<bean name="repo" class="com.example.MyCustomSecurityContextRepository" />

0 commit comments

Comments
 (0)