mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-08 05:02:13 +00:00
SEC-3070: Logout invalidate-session=false and Spring Session doesn't
work
This commit is contained in:
parent
0284845289
commit
37aacc5e02
@ -304,7 +304,7 @@ public class HttpSessionSecurityContextRepository implements SecurityContextRepo
|
||||
logger.debug("SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.");
|
||||
}
|
||||
|
||||
if (httpSession != null && !contextObject.equals(contextBeforeExecution)) {
|
||||
if (httpSession != null && authBeforeExecution != null) {
|
||||
// SEC-1587 A non-anonymous context may still be in the session
|
||||
// SEC-1735 remove if the contextBeforeExecution was not anonymous
|
||||
httpSession.removeAttribute(springSecurityContextKey);
|
||||
|
@ -429,6 +429,25 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
assertSame(ctxInSession,request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY));
|
||||
}
|
||||
|
||||
|
||||
// SEC-3070
|
||||
@Test
|
||||
public void logoutInvalidateSessionFalseFails() throws Exception {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
SecurityContext ctxInSession = SecurityContextHolder.createEmptyContext();
|
||||
ctxInSession.setAuthentication(testToken);
|
||||
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, ctxInSession);
|
||||
|
||||
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, new MockHttpServletResponse());
|
||||
repo.loadContext(holder);
|
||||
|
||||
ctxInSession.setAuthentication(null);
|
||||
repo.saveContext(ctxInSession, holder.getRequest(), holder.getResponse());
|
||||
|
||||
assertNull(request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void sessionDisableUrlRewritingPreventsSessionIdBeingWrittenToUrl() throws Exception {
|
||||
|
Loading…
x
Reference in New Issue
Block a user