Add DeferredSecurityContext
Issue gh-12023
This commit is contained in:
+26
-1
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user