org.springframework.session.MapSessionRepository Java Examples

The following examples show how to use org.springframework.session.MapSessionRepository. 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: 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 #2
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 #3
Source File: IndexDocTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void repositoryDemo() {
	RepositoryDemo<MapSession> demo = new RepositoryDemo<>();
	demo.repository = new MapSessionRepository(new ConcurrentHashMap<>());

	demo.demo();
}
 
Example #4
Source File: IndexDocTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void expireRepositoryDemo() {
	ExpiringRepositoryDemo<MapSession> demo = new ExpiringRepositoryDemo<>();
	demo.repository = new MapSessionRepository(new ConcurrentHashMap<>());

	demo.demo();
}
 
Example #5
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 #6
Source File: Initializer.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public void contextInitialized(ServletContextEvent sce) {
	this.instance = createHazelcastInstance();
	Map<String, Session> sessions = this.instance.getMap(SESSION_MAP_NAME);

	MapSessionRepository sessionRepository = new MapSessionRepository(sessions);
	SessionRepositoryFilter<? extends Session> filter = new SessionRepositoryFilter<>(sessionRepository);

	Dynamic fr = sce.getServletContext().addFilter("springSessionFilter", filter);
	fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}
 
Example #7
Source File: SessionRepositoryFilterTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	MockitoAnnotations.initMocks(this);
	this.sessions = new HashMap<>();
	this.sessionRepository = new MapSessionRepository(this.sessions);
	this.filter = new SessionRepositoryFilter<>(this.sessionRepository);
	setupRequest();
}
 
Example #8
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 #9
Source File: LogSearchSessionConfig.java    From ambari-logsearch with Apache License 2.0 4 votes vote down vote up
@Bean
public MapSessionRepository sessionRepository() {
  return new MapSessionRepository();
}
 
Example #10
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();
}
 
Example #11
Source File: RememberMeSecurityConfiguration.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
MapSessionRepository sessionRepository() {
	return new MapSessionRepository(new ConcurrentHashMap<>());
}
 
Example #12
Source File: SpringHttpSessionConfig.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
public MapSessionRepository sessionRepository() {
	return new MapSessionRepository(new ConcurrentHashMap<>());
}
 
Example #13
Source File: SpringHttpSessionConfigurationTests.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
MapSessionRepository sessionRepository() {
	return new MapSessionRepository(new ConcurrentHashMap<>());
}
 
Example #14
Source File: MockServerConfig.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
@Bean(name = "springSessionRepositoryFilter")
public SessionRepositoryFilter sessionRepositoryFilter() {
    return new SessionRepositoryFilter(new MapSessionRepository());
}