org.springframework.session.events.SessionDestroyedEvent Java Examples

The following examples show how to use org.springframework.session.events.SessionDestroyedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SessionEventHttpSessionListenerAdapter.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(AbstractSessionEvent event) {
	if (this.listeners.isEmpty()) {
		return;
	}

	HttpSessionEvent httpSessionEvent = createHttpSessionEvent(event);

	for (HttpSessionListener listener : this.listeners) {
		if (event instanceof SessionDestroyedEvent) {
			listener.sessionDestroyed(httpSessionEvent);
		}
		else if (event instanceof SessionCreatedEvent) {
			listener.sessionCreated(httpSessionEvent);
		}
	}
}
 
Example #2
Source File: SessionEventHttpSessionListenerAdapterTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	MockitoAnnotations.initMocks(this);
	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);
}
 
Example #3
Source File: SessionEventHttpSessionListenerAdapterTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
/**
 * Make sure that we short circuit onApplicationEvent as early as possible if no
 * listeners
 */
@Test
void onApplicationEventEmptyListenersDoesNotUseEvent() {
	this.listener = new SessionEventHttpSessionListenerAdapter(Collections.emptyList());
	this.destroyed = mock(SessionDestroyedEvent.class);

	this.listener.onApplicationEvent(this.destroyed);

	verifyZeroInteractions(this.destroyed, this.listener1, this.listener2);
}
 
Example #4
Source File: SessionDestroyedListener.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onApplicationEvent(final SessionDestroyedEvent event)
{
	final String sessionId = event.getSessionId();
	userNotificationsService.disableForSession(sessionId);
}
 
Example #5
Source File: RedisIndexedSessionRepositoryITests.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Test
void saves() throws InterruptedException {
	String username = "saves-" + System.currentTimeMillis();

	String usernameSessionKey = "RedisIndexedSessionRepositoryITests:index:" + INDEX_NAME + ":" + username;

	RedisSession toSave = this.repository.createSession();
	String expectedAttributeName = "a";
	String expectedAttributeValue = "b";
	toSave.setAttribute(expectedAttributeName, expectedAttributeValue);
	Authentication toSaveToken = new UsernamePasswordAuthenticationToken(username, "password",
			AuthorityUtils.createAuthorityList("ROLE_USER"));
	SecurityContext toSaveContext = SecurityContextHolder.createEmptyContext();
	toSaveContext.setAuthentication(toSaveToken);
	toSave.setAttribute(SPRING_SECURITY_CONTEXT, toSaveContext);
	toSave.setAttribute(INDEX_NAME, username);
	this.registry.clear();

	this.repository.save(toSave);

	assertThat(this.registry.receivedEvent(toSave.getId())).isTrue();
	assertThat(this.registry.<SessionCreatedEvent>getEvent(toSave.getId())).isInstanceOf(SessionCreatedEvent.class);
	assertThat(this.redis.boundSetOps(usernameSessionKey).members()).contains(toSave.getId());

	Session session = this.repository.findById(toSave.getId());

	assertThat(session.getId()).isEqualTo(toSave.getId());
	assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
	assertThat(session.<String>getAttribute(expectedAttributeName))
			.isEqualTo(toSave.getAttribute(expectedAttributeName));

	this.registry.clear();

	this.repository.deleteById(toSave.getId());

	assertThat(this.repository.findById(toSave.getId())).isNull();
	assertThat(this.registry.<SessionDestroyedEvent>getEvent(toSave.getId()))
			.isInstanceOf(SessionDestroyedEvent.class);
	assertThat(this.redis.boundSetOps(usernameSessionKey).members()).doesNotContain(toSave.getId());

	assertThat(this.registry.getEvent(toSave.getId()).getSession().<String>getAttribute(expectedAttributeName))
			.isEqualTo(expectedAttributeValue);
}