Search in sources :

Example 1 with SessionRepositoryFilter

use of org.springframework.session.web.http.SessionRepositoryFilter in project spring-session by spring-projects.

the class SpringHttpSessionConfigurationTests method sessionCookieConfigConfiguration.

@Test
public void sessionCookieConfigConfiguration() {
    registerAndRefresh(SessionCookieConfigConfiguration.class);
    SessionRepositoryFilter sessionRepositoryFilter = this.context.getBean(SessionRepositoryFilter.class);
    assertThat(sessionRepositoryFilter).isNotNull();
    CookieHttpSessionIdResolver httpSessionIdResolver = (CookieHttpSessionIdResolver) ReflectionTestUtils.getField(sessionRepositoryFilter, "httpSessionIdResolver");
    assertThat(httpSessionIdResolver).isNotNull();
    DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils.getField(httpSessionIdResolver, "cookieSerializer");
    assertThat(cookieSerializer).isNotNull();
    assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookieName")).isEqualTo("test-name");
    assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookiePath")).isEqualTo("test-path");
    assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookieMaxAge")).isEqualTo(600);
    assertThat(ReflectionTestUtils.getField(cookieSerializer, "domainName")).isEqualTo("test-domain");
}
Also used : CookieHttpSessionIdResolver(org.springframework.session.web.http.CookieHttpSessionIdResolver) SessionRepositoryFilter(org.springframework.session.web.http.SessionRepositoryFilter) DefaultCookieSerializer(org.springframework.session.web.http.DefaultCookieSerializer) Test(org.junit.Test)

Example 2 with SessionRepositoryFilter

use of org.springframework.session.web.http.SessionRepositoryFilter in project spring-session by spring-projects.

the class Initializer method contextInitialized.

@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, "/*");
}
Also used : Dynamic(javax.servlet.FilterRegistration.Dynamic) MapSessionRepository(org.springframework.session.MapSessionRepository) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) SessionRepositoryFilter(org.springframework.session.web.http.SessionRepositoryFilter)

Example 3 with SessionRepositoryFilter

use of org.springframework.session.web.http.SessionRepositoryFilter in project spring-session by spring-projects.

the class SpringHttpSessionConfigurationTests method rememberMeServicesConfiguration.

@Test
public void rememberMeServicesConfiguration() {
    registerAndRefresh(RememberMeServicesConfiguration.class);
    SessionRepositoryFilter sessionRepositoryFilter = this.context.getBean(SessionRepositoryFilter.class);
    assertThat(sessionRepositoryFilter).isNotNull();
    CookieHttpSessionIdResolver httpSessionIdResolver = (CookieHttpSessionIdResolver) ReflectionTestUtils.getField(sessionRepositoryFilter, "httpSessionIdResolver");
    assertThat(httpSessionIdResolver).isNotNull();
    DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils.getField(httpSessionIdResolver, "cookieSerializer");
    assertThat(cookieSerializer).isNotNull();
    assertThat(ReflectionTestUtils.getField(cookieSerializer, "rememberMeRequestAttribute")).isEqualTo(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR);
}
Also used : CookieHttpSessionIdResolver(org.springframework.session.web.http.CookieHttpSessionIdResolver) SessionRepositoryFilter(org.springframework.session.web.http.SessionRepositoryFilter) DefaultCookieSerializer(org.springframework.session.web.http.DefaultCookieSerializer) Test(org.junit.Test)

Aggregations

SessionRepositoryFilter (org.springframework.session.web.http.SessionRepositoryFilter)3 Test (org.junit.Test)2 CookieHttpSessionIdResolver (org.springframework.session.web.http.CookieHttpSessionIdResolver)2 DefaultCookieSerializer (org.springframework.session.web.http.DefaultCookieSerializer)2 Dynamic (javax.servlet.FilterRegistration.Dynamic)1 MapSession (org.springframework.session.MapSession)1 MapSessionRepository (org.springframework.session.MapSessionRepository)1 Session (org.springframework.session.Session)1