parent
33b492df54
commit
8554e70c09
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue