use of javax.servlet.http.HttpSessionEvent in project spring-security by spring-projects.
the class HttpSessionEventPublisherTests method sessionCreatedNullApplicationContext.
// 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);
}
use of javax.servlet.http.HttpSessionEvent in project wildfly by wildfly.
the class UndertowContextTestCase method addSessionListener.
@Test
public void addSessionListener() throws ServletException {
HttpSessionListener listener = mock(HttpSessionListener.class);
ServletContext context = mock(ServletContext.class);
HttpSession session = mock(HttpSession.class);
ApplicationListeners listeners = new ApplicationListeners(Collections.<ManagedListener>emptyList(), context);
ArgumentCaptor<HttpSessionEvent> event = ArgumentCaptor.forClass(HttpSessionEvent.class);
when(this.deployment.getApplicationListeners()).thenReturn(listeners);
this.context.addSessionListener(listener);
listeners.start();
listeners.sessionCreated(session);
verify(listener).sessionCreated(event.capture());
assertSame(session, event.getValue().getSession());
event = ArgumentCaptor.forClass(HttpSessionEvent.class);
listeners.sessionDestroyed(session);
verify(listener).sessionDestroyed(event.capture());
assertSame(session, event.getValue().getSession());
}
use of javax.servlet.http.HttpSessionEvent in project undertow by undertow-io.
the class ApplicationListeners method sessionDestroyed.
public void sessionDestroyed(final HttpSession session) {
if (!started) {
return;
}
final HttpSessionEvent sre = new HttpSessionEvent(session);
for (int i = httpSessionListeners.length - 1; i >= 0; --i) {
ManagedListener listener = httpSessionListeners[i];
this.<HttpSessionListener>get(listener).sessionDestroyed(sre);
}
}
use of javax.servlet.http.HttpSessionEvent in project undertow by undertow-io.
the class SessionRestoringHandler method stop.
public void stop() {
ClassLoader old = getTccl();
try {
setTccl(servletContext.getClassLoader());
this.started = false;
final Map<String, SessionPersistenceManager.PersistentSession> objectData = new HashMap<>();
for (String sessionId : sessionManager.getTransientSessions()) {
Session session = sessionManager.getSession(sessionId);
if (session != null) {
final HttpSessionEvent event = new HttpSessionEvent(SecurityActions.forSession(session, servletContext, false));
final Map<String, Object> sessionData = new HashMap<>();
for (String attr : session.getAttributeNames()) {
final Object attribute = session.getAttribute(attr);
sessionData.put(attr, attribute);
if (attribute instanceof HttpSessionActivationListener) {
((HttpSessionActivationListener) attribute).sessionWillPassivate(event);
}
}
objectData.put(sessionId, new PersistentSession(new Date(session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000)), sessionData));
}
}
sessionPersistenceManager.persistSessions(deploymentName, objectData);
this.data.clear();
} finally {
setTccl(old);
}
}
use of javax.servlet.http.HttpSessionEvent in project undertow by undertow-io.
the class SessionRestoringHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
final String incomingSessionId = servletContext.getSessionConfig().findSessionId(exchange);
if (incomingSessionId == null || !data.containsKey(incomingSessionId)) {
next.handleRequest(exchange);
return;
}
//we have some old data
PersistentSession result = data.remove(incomingSessionId);
if (result != null) {
long time = System.currentTimeMillis();
if (time < result.getExpiration().getTime()) {
final HttpSessionImpl session = servletContext.getSession(exchange, true);
final HttpSessionEvent event = new HttpSessionEvent(session);
for (Map.Entry<String, Object> entry : result.getSessionData().entrySet()) {
if (entry.getValue() instanceof HttpSessionActivationListener) {
((HttpSessionActivationListener) entry.getValue()).sessionDidActivate(event);
}
if (entry.getKey().startsWith(HttpSessionImpl.IO_UNDERTOW)) {
session.getSession().setAttribute(entry.getKey(), entry.getValue());
} else {
session.setAttribute(entry.getKey(), entry.getValue());
}
}
}
}
next.handleRequest(exchange);
}
Aggregations