org.springframework.session.SessionRepository Java Examples

The following examples show how to use org.springframework.session.SessionRepository. 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: AutoConfiguredSessionCachingIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Test
public void sessionRepositoryExists() {

	assertThat(this.applicationContext.containsBean("sessionRepository")).isTrue();

	SessionRepository<?> sessionRepository =
		this.applicationContext.getBean("sessionRepository", SessionRepository.class);

	assertThat(sessionRepository).isInstanceOf(GemFireOperationsSessionRepository.class);

	GemfireOperations gemfireOperations =
		((GemFireOperationsSessionRepository) sessionRepository).getSessionsTemplate();

	Region<?, ?> sessionRegion =
		this.applicationContext.getBean(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME, Region.class);

	GemfireTemplate sessionRegionTemplate =
		this.applicationContext.getBean("sessionRegionTemplate", GemfireTemplate.class);

	assertThat(gemfireOperations).isInstanceOf(GemfireAccessor.class);
	assertThat(gemfireOperations).isSameAs(sessionRegionTemplate);
	assertThat(((GemfireAccessor) gemfireOperations).getRegion()).isEqualTo(sessionRegion);
}
 
Example #2
Source File: ManuallyConfiguredSessionCachingIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Test
public void gemfireSessionRegionAndSessionRepositoryAreNotPresent() {

	assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
	assertThat(this.applicationContext.containsBean("sessionRepository")).isTrue();
	assertThat(this.applicationContext.containsBean(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME))
		.isFalse();

	GemFireCache gemfireCache = this.applicationContext.getBean(GemFireCache.class);

	assertThat(gemfireCache).isNotNull();
	assertThat(gemfireCache.rootRegions()).isEmpty();

	SessionRepository<?> sessionRepository = this.applicationContext.getBean(SessionRepository.class);

	assertThat(sessionRepository).isNotNull();
	assertThat(sessionRepository).isNotInstanceOf(GemFireOperationsSessionRepository.class);
	assertThat(sessionRepository.getClass().getName().toLowerCase()).doesNotContain("redis");
}
 
Example #3
Source File: ManuallyConfiguredWithPropertiesSessionCachingIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Test(expected = NoSuchBeanDefinitionException.class)
public void gemfireSessionRegionAndSessionRepositoryAreNotPresent() {

	String sessionsRegionName = GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME;

	assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
	assertThat(this.applicationContext.containsBean("sessionRepository")).isFalse();
	assertThat(this.applicationContext.containsBean(sessionsRegionName)).isFalse();
	assertThat(this.applicationContext.getBeansOfType(SessionRepository.class)).isEmpty();

	GemFireCache gemfireCache = this.applicationContext.getBean(GemFireCache.class);

	assertThat(gemfireCache).isNotNull();
	assertThat(gemfireCache.rootRegions()).isEmpty();

	this.applicationContext.getBean(SessionRepository.class);
}
 
Example #4
Source File: SessionRepositoryFilterTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test // gh-1229
void doFilterAdapterGetRequestedSessionIdForInvalidSession() throws Exception {
	SessionRepository<MapSession> sessionRepository = new MapSessionRepository(new HashMap<>());

	this.filter = new SessionRepositoryFilter<>(sessionRepository);
	this.filter.setHttpSessionIdResolver(this.strategy);
	final String expectedId = "HttpSessionIdResolver-requested-id1";
	final String otherId = "HttpSessionIdResolver-requested-id2";

	given(this.strategy.resolveSessionIds(any(HttpServletRequest.class)))
			.willReturn(Arrays.asList(expectedId, otherId));

	doFilter(new DoInFilter() {
		@Override
		public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) {
			assertThat(wrappedRequest.getRequestedSessionId()).isEqualTo(expectedId);
			assertThat(wrappedRequest.isRequestedSessionIdValid()).isFalse();
		}
	});
}
 
Example #5
Source File: SessionRepositoryFilterTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test
void doFilterAdapterGetRequestedSessionId() throws Exception {
	SessionRepository<MapSession> sessionRepository = spy(new MapSessionRepository(new ConcurrentHashMap<>()));

	this.filter = new SessionRepositoryFilter<>(sessionRepository);
	this.filter.setHttpSessionIdResolver(this.strategy);
	final String expectedId = "HttpSessionIdResolver-requested-id";

	given(this.strategy.resolveSessionIds(any(HttpServletRequest.class)))
			.willReturn(Collections.singletonList(expectedId));
	given(sessionRepository.findById(anyString())).willReturn(new MapSession(expectedId));

	doFilter(new DoInFilter() {
		@Override
		public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) {
			String actualId = wrappedRequest.getRequestedSessionId();
			assertThat(actualId).isEqualTo(expectedId);
		}
	});
}
 
Example #6
Source File: IndexDocTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
void newJdbcIndexedSessionRepository() {
	// tag::new-jdbcindexedsessionrepository[]
	JdbcTemplate jdbcTemplate = new JdbcTemplate();

	// ... configure jdbcTemplate ...

	TransactionTemplate transactionTemplate = new TransactionTemplate();

	// ... configure transactionTemplate ...

	SessionRepository<? extends Session> repository = new JdbcIndexedSessionRepository(jdbcTemplate,
			transactionTemplate);
	// end::new-jdbcindexedsessionrepository[]
}
 
Example #7
Source File: SessionRepositoryFilter.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance
 *
 * @param sessionRepository the <code>SessionRepository</code> to use. Cannot be null.
 */
public SessionRepositoryFilter(SessionRepository<S> sessionRepository) {
	if(sessionRepository == null) {
		throw new IllegalArgumentException("sessionRepository cannot be null");
	}
	this.sessionRepository = sessionRepository;
}
 
Example #8
Source File: SpringHttpSessionConfigurationTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void defaultConfiguration() {
	registerAndRefresh(DefaultConfiguration.class);

	assertThat(this.context.getBean(SessionEventHttpSessionListenerAdapter.class)).isNotNull();
	assertThat(this.context.getBean(SessionRepositoryFilter.class)).isNotNull();
	assertThat(this.context.getBean(SessionRepository.class)).isNotNull();
}
 
Example #9
Source File: SessionRepositoryFilterTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void doFilterLazySessionCreation() throws Exception {
	SessionRepository<MapSession> sessionRepository = spy(new MapSessionRepository(new ConcurrentHashMap<>()));

	this.filter = new SessionRepositoryFilter<>(sessionRepository);

	doFilter(new DoInFilter() {
		@Override
		public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) {
		}
	});

	verifyZeroInteractions(sessionRepository);
}
 
Example #10
Source File: SpringHttpSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Bean
public <S extends Session> SessionRepositoryFilter<? extends Session> springSessionRepositoryFilter(
		SessionRepository<S> sessionRepository) {
	SessionRepositoryFilter<S> sessionRepositoryFilter = new SessionRepositoryFilter<>(sessionRepository);
	sessionRepositoryFilter.setHttpSessionIdResolver(this.httpSessionIdResolver);
	return sessionRepositoryFilter;
}
 
Example #11
Source File: SpringSessionBackedSessionInformation.java    From spring-session with Apache License 2.0 5 votes vote down vote up
SpringSessionBackedSessionInformation(S session, SessionRepository<S> sessionRepository) {
	super(resolvePrincipal(session), session.getId(), Date.from(session.getLastAccessedTime()));
	this.sessionRepository = sessionRepository;
	Boolean expired = session.getAttribute(EXPIRED_ATTR);
	if (Boolean.TRUE.equals(expired)) {
		super.expireNow();
	}
}
 
Example #12
Source File: SessionRepositoryFilter.java    From spring-session with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 * @param sessionRepository the <code>SessionRepository</code> to use. Cannot be null.
 */
public SessionRepositoryFilter(SessionRepository<S> sessionRepository) {
	if (sessionRepository == null) {
		throw new IllegalArgumentException("sessionRepository cannot be null");
	}
	this.sessionRepository = sessionRepository;
}
 
Example #13
Source File: SessionRepositoryMessageInterceptor.java    From spring-session with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 * @param sessionRepository the {@link SessionRepository} to use. Cannot be null.
 */
public SessionRepositoryMessageInterceptor(SessionRepository<S> sessionRepository) {
	Assert.notNull(sessionRepository, "sessionRepository cannot be null");
	this.sessionRepository = sessionRepository;
	this.matchingMessageTypes = EnumSet.of(SimpMessageType.CONNECT, SimpMessageType.MESSAGE,
			SimpMessageType.SUBSCRIBE, SimpMessageType.UNSUBSCRIBE);
}
 
Example #14
Source File: IndexDocTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unused")
void mapRepository() {
	// tag::new-mapsessionrepository[]
	SessionRepository<? extends Session> repository = new MapSessionRepository(new ConcurrentHashMap<>());
	// end::new-mapsessionrepository[]
}
 
Example #15
Source File: IndexDocTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unused")
void newRedisIndexedSessionRepository() {
	// tag::new-redisindexedsessionrepository[]
	RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();

	// ... configure redisTemplate ...

	SessionRepository<? extends Session> repository = new RedisIndexedSessionRepository(redisTemplate);
	// end::new-redisindexedsessionrepository[]
}
 
Example #16
Source File: SpringSessionBackedSessionInformation.java    From spring-session-concurrent-session-control with Apache License 2.0 5 votes vote down vote up
public SpringSessionBackedSessionInformation(ExpiringSession session, SessionRepository<? extends ExpiringSession> sessionRepository) {
    super(resolvePrincipal(session), session.getId(), new Date(session.getLastAccessedTime()));
    this.sessionRepository = sessionRepository;
    if (session.isExpired()) {
        super.expireNow();
    }
}
 
Example #17
Source File: NoAutoConfigurationOfSessionCachingIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
@Test
public void noSessionRepositoryBeanIsPresent() {

	assertThat(this.applicationContext).isNotNull();
	assertThat(this.applicationContext.containsBean("sessionRepository")).isFalse();
	assertThat(this.applicationContext.getBeansOfType(SessionRepository.class)).isEmpty();
}
 
Example #18
Source File: ManuallyConfiguredSessionCachingIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Bean
SessionRepository<?> sessionRepository() {
	return mock(SessionRepository.class);
}
 
Example #19
Source File: EnableSpringHttpSessionCustomCookieSerializerTests.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
SessionRepository sessionRepository() {
	return mock(SessionRepository.class);
}
 
Example #20
Source File: BasicAuthSecurityConfiguration.java    From spring-cloud-dashboard with Apache License 2.0 4 votes vote down vote up
@Bean
public SessionRepository<ExpiringSession> sessionRepository() {
	return new MapSessionRepository();
}