Skip to content

Commit 03b407a

Browse files
author
Steve Riesenberg
committed
Polish migration doc
Issue gh-12023
1 parent 2a6123a commit 03b407a

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

Diff for: docs/modules/ROOT/pages/migration.adoc

+7-18
Original file line numberDiff line numberDiff line change
@@ -373,32 +373,25 @@ With the addition of xref:servlet/authentication/persistence.adoc#delegatingsecu
373373
In Spring Security 6, the deprecated method was removed.
374374
If you have implemented `SecurityContextRepository` yourself and added an implementation of the `loadContext(request)` method, you can prepare for Spring Security 6 by removing the implementation of that method and implementing the new method instead.
375375

376-
To get started implementing the new method, use the following example that adapts a `Supplier<SecurityContext>` to provide a `DeferredSecurityContext`:
376+
To get started implementing the new method, use the following example to provide a `DeferredSecurityContext`:
377377

378-
[NOTE]
379-
====
380-
The adapted `Supplier` should return `null` when no `SecurityContext` is available, which was not the case with the `Supplier` returned from `loadContext(request)`.
381-
====
382-
383-
.Adapt `Supplier<SecurityContext>` to `DeferredSecurityContext`
378+
.Provide `DeferredSecurityContext`
384379
====
385380
.Java
386381
[source,java,role="primary"]
387382
----
388383
@Override
389384
public DeferredSecurityContext loadDeferredContext(HttpServletRequest request) {
390-
// Adapt a supplier that returns null when the context is not available
391-
Supplier<SecurityContext> supplier = () -> getContextOrNull(request);
392-
SecurityContextHolderStrategy strategy = SecurityContextHolder.getContextHolderStrategy();
393385
return new DeferredSecurityContext() {
394386
private SecurityContext securityContext;
395387
private boolean isGenerated;
396388
397389
@Override
398390
public SecurityContext get() {
399391
if (this.securityContext == null) {
400-
this.securityContext = supplier.get();
392+
this.securityContext = getContextOrNull(request);
401393
if (this.securityContext == null) {
394+
SecurityContextHolderStrategy strategy = SecurityContextHolder.getContextHolderStrategy();
402395
this.securityContext = strategy.createEmptyContext();
403396
this.isGenerated = true;
404397
}
@@ -419,19 +412,15 @@ public DeferredSecurityContext loadDeferredContext(HttpServletRequest request) {
419412
[source,kotlin,role="secondary"]
420413
----
421414
override fun loadDeferredContext(request: HttpServletRequest): DeferredSecurityContext {
422-
// Adapt a supplier that returns null when the context is not available
423-
val supplier: Supplier<SecurityContext?> = SingletonSupplier.of {
424-
getContextOrNull(request)
425-
}
426-
val strategy = SecurityContextHolder.getContextHolderStrategy()
427415
return object : DeferredSecurityContext {
428416
private var securityContext: SecurityContext? = null
429417
private var isGenerated = false
430418
431419
override fun get(): SecurityContext {
432420
if (securityContext == null) {
433-
securityContext = supplier.get()
434-
?: strategy.createEmptyContext().also { isGenerated = true }
421+
securityContext = getContextOrNull(request)
422+
?: SecurityContextHolder.getContextHolderStrategy().createEmptyContext()
423+
.also { isGenerated = true }
435424
}
436425
return securityContext!!
437426
}

0 commit comments

Comments
 (0)