use of javax.servlet.http.HttpSessionEvent in project spring-security by spring-projects.
the class HttpSessionEventPublisherTests method sessionDestroyedNullApplicationContext.
// 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);
}
use of javax.servlet.http.HttpSessionEvent in project spring-security by spring-projects.
the class HttpSessionEventPublisherTests method publishedEventIsReceivedbyListenerChildContext.
@Test
public void publishedEventIsReceivedbyListenerChildContext() {
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
StaticWebApplicationContext context = new StaticWebApplicationContext();
MockServletContext servletContext = new MockServletContext();
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", context);
context.setServletContext(servletContext);
context.registerSingleton("listener", MockApplicationListener.class, null);
context.refresh();
MockHttpSession session = new MockHttpSession(servletContext);
MockApplicationListener listener = (MockApplicationListener) context.getBean("listener");
HttpSessionEvent event = new HttpSessionEvent(session);
publisher.sessionCreated(event);
assertThat(listener.getCreatedEvent()).isNotNull();
assertThat(listener.getDestroyedEvent()).isNull();
assertThat(listener.getCreatedEvent().getSession()).isEqualTo(session);
listener.setCreatedEvent(null);
listener.setDestroyedEvent(null);
publisher.sessionDestroyed(event);
assertThat(listener.getDestroyedEvent()).isNotNull();
assertThat(listener.getCreatedEvent()).isNull();
assertThat(listener.getDestroyedEvent().getSession()).isEqualTo(session);
}
use of javax.servlet.http.HttpSessionEvent in project drill by apache.
the class WebServer method createSessionHandler.
/**
* @return A {@link SessionHandler} which contains a {@link HashSessionManager}
*/
private SessionHandler createSessionHandler(final SecurityHandler securityHandler) {
SessionManager sessionManager = new HashSessionManager();
sessionManager.setMaxInactiveInterval(config.getInt(ExecConstants.HTTP_SESSION_MAX_IDLE_SECS));
sessionManager.addEventListener(new HttpSessionListener() {
@Override
public void sessionCreated(HttpSessionEvent se) {
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
final HttpSession session = se.getSession();
if (session == null) {
return;
}
final Object authCreds = session.getAttribute(SessionAuthentication.__J_AUTHENTICATED);
if (authCreds != null) {
final SessionAuthentication sessionAuth = (SessionAuthentication) authCreds;
securityHandler.logout(sessionAuth);
session.removeAttribute(SessionAuthentication.__J_AUTHENTICATED);
}
// Clear all the resources allocated for this session
final WebSessionResources webSessionResources = (WebSessionResources) session.getAttribute(WebSessionResources.class.getSimpleName());
if (webSessionResources != null) {
webSessionResources.close();
session.removeAttribute(WebSessionResources.class.getSimpleName());
}
}
});
return new SessionHandler(sessionManager);
}
use of javax.servlet.http.HttpSessionEvent in project tomee by apache.
the class HttpSessionImpl method getSessionContext.
@Override
public HttpSessionContext getSessionContext() {
touch();
final SessionManager component = SystemInstance.get().getComponent(SessionManager.class);
return new HttpSessionContext() {
@Override
public javax.servlet.http.HttpSession getSession(final String sessionId) {
final HttpSessionEvent event = component.findSession(sessionId);
return event == null ? null : event.getSession();
}
@Override
public Enumeration<String> getIds() {
return Collections.enumeration(component.findSessionIds());
}
};
}
use of javax.servlet.http.HttpSessionEvent in project tomee by apache.
the class HttpSessionImplTest method run.
@Test
public void run() throws URISyntaxException {
final HttpRequest req = new HttpRequestImpl(new URI("http://localhost:1234/foo"));
final javax.servlet.http.HttpSession session = req.getSession();
Reflections.set(session, "listeners", Collections.<Object>singletonList(new HttpSessionListener() {
private int count = 0;
@Override
public void sessionCreated(final HttpSessionEvent se) {
// no-op
}
@Override
public void sessionDestroyed(final HttpSessionEvent se) {
se.getSession().setAttribute("seen", ++count);
}
}));
session.invalidate();
final long c1 = Integer.class.cast(session.getAttribute("seen"));
session.invalidate();
final long c2 = Integer.class.cast(session.getAttribute("seen"));
assertEquals(c1, c2);
}
Aggregations