SEC-539: Refactored if (httpSession == null) block in storeSecurityContextInSession()

This commit is contained in:
Luke Taylor 2007-08-28 21:25:17 +00:00
parent ce3eb599ed
commit fa63d8ecfb
1 changed files with 31 additions and 30 deletions

View File

@ -331,21 +331,22 @@ public class HttpSessionContextIntegrationFilter implements InitializingBean, Fi
boolean httpSessionExistedAtStartOfRequest, boolean httpSessionExistedAtStartOfRequest,
int contextWhenChainProceeded) { int contextWhenChainProceeded) {
HttpSession httpSession = null; HttpSession httpSession = null;
try { try {
httpSession = ((HttpServletRequest) request).getSession(false); httpSession = ((HttpServletRequest) request).getSession(false);
} }
catch (IllegalStateException ignored) { catch (IllegalStateException ignored) {
} }
if ((httpSession == null) && httpSessionExistedAtStartOfRequest) { if (httpSession == null) {
if (httpSessionExistedAtStartOfRequest) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("HttpSession is now null, but was not null at start of request; " logger.debug("HttpSession is now null, but was not null at start of request; "
+ "session was invalidated, so do not create a new session"); + "session was invalidated, so do not create a new session");
} }
} } else {
// Generate a HttpSession only if we need to // Generate a HttpSession only if we need to
if ((httpSession == null) && !httpSessionExistedAtStartOfRequest) {
if (!allowSessionCreation) { if (!allowSessionCreation) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger logger
@ -366,13 +367,13 @@ public class HttpSessionContextIntegrationFilter implements InitializingBean, Fi
} }
} else { } else {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger logger.debug("HttpSession is null, but SecurityContextHolder has not changed from default: ' "
.debug("HttpSession is null, but SecurityContextHolder has not changed from default: ' "
+ SecurityContextHolder.getContext() + SecurityContextHolder.getContext()
+ "'; not creating HttpSession or storing SecurityContextHolder contents"); + "'; not creating HttpSession or storing SecurityContextHolder contents");
} }
} }
} }
}
// If HttpSession exists, store current // If HttpSession exists, store current
// SecurityContextHolder contents but only if // SecurityContextHolder contents but only if