|
68 | 68 | import org.springframework.security.authentication.InsufficientAuthenticationException;
|
69 | 69 | import org.springframework.security.authentication.TestingAuthenticationToken;
|
70 | 70 | import org.springframework.security.authentication.jaas.AuthorityGranter;
|
| 71 | +import org.springframework.security.config.TestDeferredSecurityContext; |
71 | 72 | import org.springframework.security.config.test.SpringTestContext;
|
72 | 73 | import org.springframework.security.config.test.SpringTestContextExtension;
|
73 | 74 | import org.springframework.security.core.Authentication;
|
74 | 75 | import org.springframework.security.core.AuthenticationException;
|
75 | 76 | import org.springframework.security.core.GrantedAuthority;
|
76 | 77 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
77 | 78 | import org.springframework.security.core.authority.AuthorityUtils;
|
78 |
| -import org.springframework.security.core.context.DeferredSecurityContext; |
79 | 79 | import org.springframework.security.core.context.SecurityContext;
|
80 | 80 | import org.springframework.security.core.context.SecurityContextHolder;
|
81 | 81 | import org.springframework.security.core.context.SecurityContextHolderStrategy;
|
@@ -473,7 +473,8 @@ public void getWhenAuthenticatingThenConsultsCustomSecurityContextRepository() t
|
473 | 473 | this.spring.configLocations(xml("SecurityContextRepository")).autowire();
|
474 | 474 | SecurityContextRepository repository = this.spring.getContext().getBean(SecurityContextRepository.class);
|
475 | 475 | SecurityContext context = new SecurityContextImpl(new TestingAuthenticationToken("user", "password"));
|
476 |
| - given(repository.loadContext(any(HttpServletRequest.class))).willReturn(() -> context); |
| 476 | + given(repository.loadDeferredContext(any(HttpServletRequest.class))) |
| 477 | + .willReturn(new TestDeferredSecurityContext(context, false)); |
477 | 478 | // @formatter:off
|
478 | 479 | MvcResult result = this.mvc.perform(get("/protected").with(userCredentials()))
|
479 | 480 | .andExpect(status().isOk())
|
@@ -1039,27 +1040,4 @@ public String encodeRedirectUrl(String url) {
|
1039 | 1040 |
|
1040 | 1041 | }
|
1041 | 1042 |
|
1042 |
| - static class TestDeferredSecurityContext implements DeferredSecurityContext { |
1043 |
| - |
1044 |
| - private SecurityContext securityContext; |
1045 |
| - |
1046 |
| - private boolean isGenerated; |
1047 |
| - |
1048 |
| - TestDeferredSecurityContext(SecurityContext securityContext, boolean isGenerated) { |
1049 |
| - this.securityContext = securityContext; |
1050 |
| - this.isGenerated = isGenerated; |
1051 |
| - } |
1052 |
| - |
1053 |
| - @Override |
1054 |
| - public SecurityContext get() { |
1055 |
| - return this.securityContext; |
1056 |
| - } |
1057 |
| - |
1058 |
| - @Override |
1059 |
| - public boolean isGenerated() { |
1060 |
| - return this.isGenerated; |
1061 |
| - } |
1062 |
| - |
1063 |
| - } |
1064 |
| - |
1065 | 1043 | }
|
0 commit comments