|
|
|
@ -21,25 +21,27 @@ import org.apache.commons.logging.LogFactory; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.context.support.WebApplicationContextUtils; |
|
|
|
import org.springframework.web.context.support.WebApplicationContextUtils; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletContextEvent; |
|
|
|
import javax.servlet.ServletContextEvent; |
|
|
|
import javax.servlet.ServletContextListener; |
|
|
|
import javax.servlet.ServletContextListener; |
|
|
|
|
|
|
|
import javax.servlet.ServletContext; |
|
|
|
import javax.servlet.http.HttpSessionEvent; |
|
|
|
import javax.servlet.http.HttpSessionEvent; |
|
|
|
import javax.servlet.http.HttpSessionListener; |
|
|
|
import javax.servlet.http.HttpSessionListener; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Declared in web.xml as <br> |
|
|
|
* Declared in web.xml as <br> |
|
|
|
* <code> <listener><br> |
|
|
|
* <pre> |
|
|
|
* <listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class><br> |
|
|
|
* <listener> |
|
|
|
* </listener><br> |
|
|
|
* <listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class> |
|
|
|
* </code> Publishes <code>HttpSessionApplicationEvent</code>s to the Spring |
|
|
|
* </listener> |
|
|
|
* Root WebApplicationContext. <br> |
|
|
|
* </pre> |
|
|
|
|
|
|
|
* Publishes <code>HttpSessionApplicationEvent</code>s to the Spring |
|
|
|
|
|
|
|
* Root WebApplicationContext. |
|
|
|
* Maps javax.servlet.http.HttpSessionListener.sessionCreated() to {@link |
|
|
|
* Maps javax.servlet.http.HttpSessionListener.sessionCreated() to {@link |
|
|
|
* HttpSessionCreatedEvent}. <br> |
|
|
|
* HttpSessionCreatedEvent}. |
|
|
|
* Maps javax.servlet.http.HttpSessionListener.sessionDestroyed() to {@link |
|
|
|
* Maps javax.servlet.http.HttpSessionListener.sessionDestroyed() to {@link |
|
|
|
* HttpSessionDestroyedEvent}. <br> |
|
|
|
* HttpSessionDestroyedEvent}. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Ray Krueger |
|
|
|
* @author Ray Krueger |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -51,7 +53,8 @@ public class HttpSessionEventPublisher implements HttpSessionListener, |
|
|
|
|
|
|
|
|
|
|
|
//~ Instance fields ========================================================
|
|
|
|
//~ Instance fields ========================================================
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationContext context; |
|
|
|
private ApplicationContext appContext; |
|
|
|
|
|
|
|
private ServletContext servletContext = null; |
|
|
|
|
|
|
|
|
|
|
|
//~ Methods ================================================================
|
|
|
|
//~ Methods ================================================================
|
|
|
|
|
|
|
|
|
|
|
|
@ -64,22 +67,28 @@ public class HttpSessionEventPublisher implements HttpSessionListener, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Handled internally by a call to {@link |
|
|
|
* Handled internally by a call to {@link |
|
|
|
* org.springframework.web.context.support.WebApplicationContextUtils#getRequiredWebApplicationContext(javax.servlet.ServletContext)} |
|
|
|
* org.springframework.web.appContext.support.WebApplicationContextUtils#getRequiredWebApplicationContext(javax.servlet.ServletContext)} |
|
|
|
* |
|
|
|
* |
|
|
|
* @param event the ServletContextEvent passed in by the container, |
|
|
|
* @param event the ServletContextEvent passed in by the container, |
|
|
|
* event.getServletContext() will be used to get the |
|
|
|
* event.getServletContext() will be used to get the |
|
|
|
* WebApplicationContext |
|
|
|
* WebApplicationContext |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void contextInitialized(ServletContextEvent event) { |
|
|
|
public void contextInitialized(ServletContextEvent event) { |
|
|
|
if (log.isDebugEnabled()) |
|
|
|
log.debug("Received ServletContextEvent: " + event); |
|
|
|
log.debug("Received ServletContextEvent: " + event); |
|
|
|
|
|
|
|
setContext(WebApplicationContextUtils.getRequiredWebApplicationContext( |
|
|
|
appContext = WebApplicationContextUtils.getWebApplicationContext( |
|
|
|
event.getServletContext())); |
|
|
|
event.getServletContext()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(appContext == null) { |
|
|
|
|
|
|
|
log.warn("Web application context is null. Will delay initialization until it's first used."); |
|
|
|
|
|
|
|
servletContext = event.getServletContext(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Handles the HttpSessionEvent by publishing a {@link |
|
|
|
* Handles the HttpSessionEvent by publishing a {@link |
|
|
|
* HttpSessionCreatedEvent} to the application context. |
|
|
|
* HttpSessionCreatedEvent} to the application appContext. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param event HttpSessionEvent passed in by the container |
|
|
|
* @param event HttpSessionEvent passed in by the container |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -94,7 +103,7 @@ public class HttpSessionEventPublisher implements HttpSessionListener, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Handles the HttpSessionEvent by publishing a {@link |
|
|
|
* Handles the HttpSessionEvent by publishing a {@link |
|
|
|
* HttpSessionDestroyedEvent} to the application context. |
|
|
|
* HttpSessionDestroyedEvent} to the application appContext. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param event The HttpSessionEvent pass in by the container |
|
|
|
* @param event The HttpSessionEvent pass in by the container |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -107,19 +116,11 @@ public class HttpSessionEventPublisher implements HttpSessionListener, |
|
|
|
getContext().publishEvent(e); |
|
|
|
getContext().publishEvent(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Package level method for testing and internal usage |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param context The ApplicationContext this class will use to publish |
|
|
|
|
|
|
|
* events |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
void setContext(ApplicationContext context) { |
|
|
|
|
|
|
|
this.context = context; |
|
|
|
|
|
|
|
log.debug("Using context: " + context); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationContext getContext() { |
|
|
|
ApplicationContext getContext() { |
|
|
|
Assert.notNull(context, "setContext(...) never called, ApplicationContext must not be null"); |
|
|
|
if(appContext == null) { |
|
|
|
return context; |
|
|
|
appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return appContext; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|