1
0
mirror of synced 2026-05-22 13:23:17 +00:00

Add DeferredSecurityContext

Issue gh-12023
This commit is contained in:
Steve Riesenberg
2022-10-17 12:10:03 -05:00
parent cfb7c87dfd
commit c75ca10900
11 changed files with 190 additions and 23 deletions
@@ -75,6 +75,7 @@ import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.DeferredSecurityContext;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextHolderStrategy;
@@ -490,7 +491,8 @@ public class MiscHttpConfigTests {
this.spring.configLocations(xml("ExplicitSaveAndExplicitRepository")).autowire();
SecurityContextRepository repository = this.spring.getContext().getBean(SecurityContextRepository.class);
SecurityContext context = new SecurityContextImpl(new TestingAuthenticationToken("user", "password"));
given(repository.loadContext(any(HttpServletRequest.class))).willReturn(() -> context);
given(repository.loadDeferredContext(any(HttpServletRequest.class)))
.willReturn(new TestDeferredSecurityContext(context, false));
// @formatter:off
MvcResult result = this.mvc.perform(formLogin())
.andExpect(status().is3xxRedirection())
@@ -1044,4 +1046,27 @@ public class MiscHttpConfigTests {
}
static class TestDeferredSecurityContext implements DeferredSecurityContext {
private SecurityContext securityContext;
private boolean isGenerated;
TestDeferredSecurityContext(SecurityContext securityContext, boolean isGenerated) {
this.securityContext = securityContext;
this.isGenerated = isGenerated;
}
@Override
public SecurityContext get() {
return this.securityContext;
}
@Override
public boolean isGenerated() {
return this.isGenerated;
}
}
}