mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-27 14:22:47 +00:00
Fixed SEC-395
This commit is contained in:
parent
9d2fe0e037
commit
74e8efc4e9
@ -45,9 +45,6 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
|
|||||||
|
|
||||||
//~ Instance fields ================================================================================================
|
//~ Instance fields ================================================================================================
|
||||||
|
|
||||||
private ApplicationContext appContext;
|
|
||||||
private ServletContext servletContext = null;
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,21 +64,10 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Received ServletContextEvent: " + event);
|
log.debug("Received ServletContextEvent: " + event);
|
||||||
}
|
}
|
||||||
|
|
||||||
appContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
|
|
||||||
|
|
||||||
if (appContext == null) {
|
|
||||||
log.warn("Web application context is null. Will delay initialization until it's first used.");
|
|
||||||
servletContext = event.getServletContext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationContext getContext() {
|
ApplicationContext getContext(ServletContext servletContext) {
|
||||||
if (appContext == null) {
|
return WebApplicationContextUtils.getWebApplicationContext(servletContext);
|
||||||
appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
return appContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,7 +83,7 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
|
|||||||
log.debug("Publishing event: " + e);
|
log.debug("Publishing event: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
getContext().publishEvent(e);
|
getContext(event.getSession().getServletContext()).publishEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,6 +99,6 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
|
|||||||
log.debug("Publishing event: " + e);
|
log.debug("Publishing event: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
getContext().publishEvent(e);
|
getContext(event.getSession().getServletContext()).publishEvent(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,16 +46,6 @@ public class HttpSessionEventPublisherTests extends TestCase {
|
|||||||
context.setServletContext(servletContext);
|
context.setServletContext(servletContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetContextThrowsExceptionIfContextNotSet() {
|
|
||||||
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
|
|
||||||
publisher.contextInitialized(new ServletContextEvent(new MockServletContext()));
|
|
||||||
|
|
||||||
try {
|
|
||||||
publisher.getContext();
|
|
||||||
fail("IllegalStateException expected when no context set");
|
|
||||||
} catch (IllegalStateException expected) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It's not that complicated so we'll just run it straight through here.
|
* It's not that complicated so we'll just run it straight through here.
|
||||||
*/
|
*/
|
||||||
@ -73,10 +63,11 @@ public class HttpSessionEventPublisherTests extends TestCase {
|
|||||||
|
|
||||||
publisher.contextInitialized(new ServletContextEvent(servletContext));
|
publisher.contextInitialized(new ServletContextEvent(servletContext));
|
||||||
|
|
||||||
MockHttpSession session = new MockHttpSession();
|
MockHttpSession session = new MockHttpSession(servletContext);
|
||||||
TestListener listener = (TestListener) context.getBean("listener");
|
TestListener listener = (TestListener) context.getBean("listener");
|
||||||
|
|
||||||
HttpSessionEvent event = new HttpSessionEvent(session);
|
HttpSessionEvent event = new HttpSessionEvent(session);
|
||||||
|
|
||||||
publisher.sessionCreated(event);
|
publisher.sessionCreated(event);
|
||||||
|
|
||||||
assertNotNull(listener.getCreatedEvent());
|
assertNotNull(listener.getCreatedEvent());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user