mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-25 13:32:30 +00:00
SEC-2599: HttpSessionEventPublisher get required ApplicationContext
In order to get better error messages (avoid NullPointerException) the HttpSessionEventPublisher now gets the required ApplicationContext which throws an IllegalStateException with a good error message.
This commit is contained in:
parent
47acf17323
commit
89c5c56849
@ -49,7 +49,7 @@ public class HttpSessionEventPublisher implements HttpSessionListener {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
ApplicationContext getContext(ServletContext servletContext) {
|
||||
return WebApplicationContextUtils.getWebApplicationContext(servletContext);
|
||||
return WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,4 +69,26 @@ public class HttpSessionEventPublisherTests {
|
||||
assertNull(listener.getCreatedEvent());
|
||||
assertEquals(session, listener.getDestroyedEvent().getSession());
|
||||
}
|
||||
|
||||
// SEC-2599
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void sessionCreatedNullApplicationContext() {
|
||||
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
MockHttpSession session = new MockHttpSession(servletContext);
|
||||
HttpSessionEvent event = new HttpSessionEvent(session);
|
||||
|
||||
publisher.sessionCreated(event);
|
||||
}
|
||||
|
||||
// SEC-2599
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void sessionDestroyedNullApplicationContext() {
|
||||
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
MockHttpSession session = new MockHttpSession(servletContext);
|
||||
HttpSessionEvent event = new HttpSessionEvent(session);
|
||||
|
||||
publisher.sessionDestroyed(event);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user