@Test public void springSessionDestroyedTranslatedToSpringSecurityDestroyed() { Session session = new MapSession(); this.publisher.publishEvent( new org.springframework.session.events.SessionDestroyedEvent(this, session)); assertThat(this.listener.getEvent().getId()).isEqualTo(session.getId()); }
@Test public void onApplicationEventDestroyed() { this.listener.onApplicationEvent(this.destroyed); verify(this.listener1).sessionDestroyed(this.sessionEvent.capture()); verify(this.listener2).sessionDestroyed(this.sessionEvent.capture()); assertThat(this.sessionEvent.getValue().getSession().getId()) .isEqualTo(this.destroyed.getSessionId()); }
@Before public void setup() { this.listener = new SessionEventHttpSessionListenerAdapter( Arrays.asList(this.listener1, this.listener2)); this.listener.setServletContext(new MockServletContext()); Session session = new MapSession(); this.destroyed = new SessionDestroyedEvent(this, session); this.created = new SessionCreatedEvent(this, session); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof SessionDestroyedEvent) { SessionDestroyedEvent e = (SessionDestroyedEvent) event; closeWsSessions(e.getSessionId()); } else if (event instanceof SessionConnectEvent) { SessionConnectEvent e = (SessionConnectEvent) event; afterConnectionEstablished(e.getWebSocketSession()); } else if (event instanceof SessionDisconnectEvent) { SessionDisconnectEvent e = (SessionDisconnectEvent) event; Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor .getSessionAttributes(e.getMessage().getHeaders()); String httpSessionId = (sessionAttributes != null) ? SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes) : null; afterConnectionClosed(httpSessionId, e.getSessionId()); } }
protected void emitSessionDestroyedEvent(String sessionId) { logger.debugf("Emitting session destroyed %s", sessionId); springEventsPublisher.ifPresent(p -> p.publishEvent(new SessionDestroyedEvent(eventSource, sessionId))); }
/** * Constructs a new {@link SessionDestroyedEvent} initialized with the given {@link Session}, * using the {@link #getSessionRepository() SessionRepository} as the event source. * * @param session {@link Session} that is the subject of the {@link AbstractSessionEvent event}. * @return a new {@link SessionDestroyedEvent}. * @see org.springframework.session.events.SessionDestroyedEvent * @see org.springframework.session.Session * @see #getSessionRepository() */ protected SessionDestroyedEvent newSessionDestroyedEvent(Session session) { return new SessionDestroyedEvent(getSessionRepository(), session); }