Remove deprecated loadContext(request)

Closes gh-12048
This commit is contained in:
Steve Riesenberg 2022-10-17 20:13:51 -05:00
parent 33b492df54
commit 8554e70c09
No known key found for this signature in database
GPG Key ID: 5F311AB48A55D521
4 changed files with 6 additions and 23 deletions

View File

@ -46,7 +46,7 @@ public final class DelegatingSecurityContextRepository implements SecurityContex
@Override @Override
public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) { public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {
return loadContext(requestResponseHolder.getRequest()).get(); return loadDeferredContext(requestResponseHolder.getRequest()).get();
} }
@Override @Override

View File

@ -68,23 +68,6 @@ public interface SecurityContextRepository {
@Deprecated @Deprecated
SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder); SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder);
/**
* Obtains the security context for the supplied request. For an unauthenticated user,
* an empty context implementation should be returned. This method should not return
* null.
* @param request the {@link HttpServletRequest} to load the {@link SecurityContext}
* from
* @return a {@link Supplier} that returns the {@link SecurityContext} which cannot be
* null.
* @since 5.7
* @deprecated Use
* {@link SecurityContextRepository#loadDeferredContext(HttpServletRequest)} instead
*/
@Deprecated
default Supplier<SecurityContext> loadContext(HttpServletRequest request) {
return loadDeferredContext(request);
}
/** /**
* Defers loading the {@link SecurityContext} using the {@link HttpServletRequest} * Defers loading the {@link SecurityContext} using the {@link HttpServletRequest}
* until it is needed by the application. * until it is needed by the application.

View File

@ -146,7 +146,7 @@ public class HttpSessionSecurityContextRepositoryTests {
public void loadContextHttpServletRequestWhenNotSavedThenEmptyContextReturned() { public void loadContextHttpServletRequestWhenNotSavedThenEmptyContextReturned() {
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository(); HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
assertThat(repo.loadContext(request).get()).isEqualTo(SecurityContextHolder.createEmptyContext()); assertThat(repo.loadDeferredContext(request).get()).isEqualTo(SecurityContextHolder.createEmptyContext());
} }
@Test @Test
@ -156,7 +156,7 @@ public class HttpSessionSecurityContextRepositoryTests {
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository(); HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
repo.saveContext(expectedContext, request, response); repo.saveContext(expectedContext, request, response);
assertThat(repo.loadContext(request).get()).isEqualTo(expectedContext); assertThat(repo.loadDeferredContext(request).get()).isEqualTo(expectedContext);
} }
@Test @Test
@ -165,7 +165,7 @@ public class HttpSessionSecurityContextRepositoryTests {
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository(); HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session); request.setSession(session);
repo.loadContext(request); repo.loadDeferredContext(request);
verifyNoInteractions(session); verifyNoInteractions(session);
} }

View File

@ -86,7 +86,7 @@ class RequestAttributeSecurityContextRepositoryTests {
@Test @Test
void loadDeferredContextWhenNotPresentThenEmptyContext() { void loadDeferredContextWhenNotPresentThenEmptyContext() {
Supplier<SecurityContext> deferredContext = this.repository.loadContext(this.request); Supplier<SecurityContext> deferredContext = this.repository.loadDeferredContext(this.request);
assertThat(deferredContext.get()).isEqualTo(SecurityContextHolder.createEmptyContext()); assertThat(deferredContext.get()).isEqualTo(SecurityContextHolder.createEmptyContext());
} }
@ -103,7 +103,7 @@ class RequestAttributeSecurityContextRepositoryTests {
given(securityContextHolderStrategy.createEmptyContext()).willReturn(new SecurityContextImpl()); given(securityContextHolderStrategy.createEmptyContext()).willReturn(new SecurityContextImpl());
this.repository.setSecurityContextHolderStrategy(securityContextHolderStrategy); this.repository.setSecurityContextHolderStrategy(securityContextHolderStrategy);
Supplier<SecurityContext> deferredContext = this.repository.loadContext(this.request); Supplier<SecurityContext> deferredContext = this.repository.loadDeferredContext(this.request);
assertThat(deferredContext.get()).isNotNull(); assertThat(deferredContext.get()).isNotNull();
verify(securityContextHolderStrategy).createEmptyContext(); verify(securityContextHolderStrategy).createEmptyContext();
verifyNoMoreInteractions(securityContextHolderStrategy); verifyNoMoreInteractions(securityContextHolderStrategy);