Browse Source

SEC-1587: Add explicit call to removeAttribute() to remove the context from the session if the current context is empty or anonymous.

Allows for the situation where a user is logged out without invalidating the session.
3.0.x
Luke Taylor 15 years ago
parent
commit
82d105cbc3
  1. 15
      web/src/main/java/org/springframework/security/web/context/HttpSessionSecurityContextRepository.java

15
web/src/main/java/org/springframework/security/web/context/HttpSessionSecurityContextRepository.java

@ -10,6 +10,7 @@ import org.apache.commons.logging.Log; @@ -10,6 +10,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.authentication.AuthenticationTrustResolver;
import org.springframework.security.authentication.AuthenticationTrustResolverImpl;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextHolderStrategy;
@ -328,16 +329,22 @@ public class HttpSessionSecurityContextRepository implements SecurityContextRepo @@ -328,16 +329,22 @@ public class HttpSessionSecurityContextRepository implements SecurityContextRepo
*/
@Override
protected void saveContext(SecurityContext context) {
final Authentication authentication = context.getAuthentication();
HttpSession httpSession = request.getSession(false);
// See SEC-776
if (authenticationTrustResolver.isAnonymous(context.getAuthentication())) {
if (authentication == null || authenticationTrustResolver.isAnonymous(authentication)) {
if (logger.isDebugEnabled()) {
logger.debug("SecurityContext contents are anonymous - context will not be stored in HttpSession. ");
logger.debug("SecurityContext is empty or anonymous - context will not be stored in HttpSession. ");
}
if (httpSession != null) {
// SEC-1587 A non-anonymous context may still be in the session
httpSession.removeAttribute(SPRING_SECURITY_CONTEXT_KEY);
}
return;
}
HttpSession httpSession = request.getSession(false);
if (httpSession == null) {
httpSession = createNewSessionIfAllowed(context);
}

Loading…
Cancel
Save