mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-26 05:42:31 +00:00
HttpSessionEventPublisher need not implement ServletContextListener any longer
This commit is contained in:
parent
74e8efc4e9
commit
1a486e584b
@ -38,7 +38,7 @@ import javax.servlet.http.HttpSessionListener;
|
|||||||
*
|
*
|
||||||
* @author Ray Krueger
|
* @author Ray Krueger
|
||||||
*/
|
*/
|
||||||
public class HttpSessionEventPublisher implements HttpSessionListener, ServletContextListener {
|
public class HttpSessionEventPublisher implements HttpSessionListener {
|
||||||
//~ Static fields/initializers =====================================================================================
|
//~ Static fields/initializers =====================================================================================
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(HttpSessionEventPublisher.class);
|
private static final Log log = LogFactory.getLog(HttpSessionEventPublisher.class);
|
||||||
@ -47,25 +47,6 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
|
|||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
/**
|
|
||||||
* Not implemented
|
|
||||||
*
|
|
||||||
* @param event
|
|
||||||
*/
|
|
||||||
public void contextDestroyed(ServletContextEvent event) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handled internally by a call to {@link WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)}.
|
|
||||||
*
|
|
||||||
* @param event the ServletContextEvent passed in by the container, event.getServletContext() will be used to get
|
|
||||||
* the WebApplicationContext
|
|
||||||
*/
|
|
||||||
public void contextInitialized(ServletContextEvent event) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Received ServletContextEvent: " + event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplicationContext getContext(ServletContext servletContext) {
|
ApplicationContext getContext(ServletContext servletContext) {
|
||||||
return WebApplicationContextUtils.getWebApplicationContext(servletContext);
|
return WebApplicationContextUtils.getWebApplicationContext(servletContext);
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,10 @@
|
|||||||
package org.acegisecurity.ui.session;
|
package org.acegisecurity.ui.session;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
import org.springframework.mock.web.MockServletContext;
|
import org.springframework.mock.web.MockServletContext;
|
||||||
|
|
||||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
import javax.servlet.http.HttpSessionEvent;
|
import javax.servlet.http.HttpSessionEvent;
|
||||||
|
|
||||||
|
|
||||||
@ -35,18 +32,7 @@ import javax.servlet.http.HttpSessionEvent;
|
|||||||
public class HttpSessionEventPublisherTests extends TestCase {
|
public class HttpSessionEventPublisherTests extends TestCase {
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
public void testDelayedContextInitializationSucceeds() {
|
/**
|
||||||
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
|
|
||||||
MockServletContext servletContext = new MockServletContext();
|
|
||||||
|
|
||||||
// shouldn't fail, even with null context
|
|
||||||
publisher.contextInitialized(new ServletContextEvent(servletContext));
|
|
||||||
|
|
||||||
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
|
||||||
context.setServletContext(servletContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
public void testPublisher() {
|
public void testPublisher() {
|
||||||
@ -61,13 +47,11 @@ public class HttpSessionEventPublisherTests extends TestCase {
|
|||||||
context.registerSingleton("listener", TestListener.class, null);
|
context.registerSingleton("listener", TestListener.class, null);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
|
|
||||||
publisher.contextInitialized(new ServletContextEvent(servletContext));
|
|
||||||
|
|
||||||
MockHttpSession session = new MockHttpSession(servletContext);
|
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());
|
||||||
@ -82,6 +66,5 @@ public class HttpSessionEventPublisherTests extends TestCase {
|
|||||||
assertNull(listener.getCreatedEvent());
|
assertNull(listener.getCreatedEvent());
|
||||||
assertEquals(session, listener.getDestroyedEvent().getSession());
|
assertEquals(session, listener.getDestroyedEvent().getSession());
|
||||||
|
|
||||||
publisher.contextDestroyed(new ServletContextEvent(servletContext));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user