use of org.springframework.session.web.http.DefaultCookieSerializer 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");
}
use of org.springframework.session.web.http.DefaultCookieSerializer 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);
}
use of org.springframework.session.web.http.DefaultCookieSerializer in project spring-session by spring-projects.
the class Config method cookieSerializer.
// tag::cookie-serializer[]
@Bean
public CookieSerializer cookieSerializer() {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
// <1>
serializer.setCookieName("JSESSIONID");
// <2>
serializer.setCookiePath("/");
// <3>
serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
return serializer;
}
use of org.springframework.session.web.http.DefaultCookieSerializer in project spring-boot by spring-projects.
the class SessionAutoConfigurationWithoutSecurityTests method sessionCookieConfigurationIsAppliedToAutoConfiguredCookieSerializer.
@Test
void sessionCookieConfigurationIsAppliedToAutoConfiguredCookieSerializer() {
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class).run((context) -> {
DefaultCookieSerializer cookieSerializer = context.getBean(DefaultCookieSerializer.class);
assertThat(cookieSerializer).hasFieldOrPropertyWithValue("rememberMeRequestAttribute", null);
});
}
use of org.springframework.session.web.http.DefaultCookieSerializer in project spring-boot by spring-projects.
the class SessionAutoConfigurationTests method sessionCookieConfigurationIsAppliedToAutoConfiguredCookieSerializer.
@Test
void sessionCookieConfigurationIsAppliedToAutoConfiguredCookieSerializer() {
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class).withPropertyValues("server.servlet.session.cookie.name=sid", "server.servlet.session.cookie.domain=spring", "server.servlet.session.cookie.path=/test", "server.servlet.session.cookie.httpOnly=false", "server.servlet.session.cookie.secure=false", "server.servlet.session.cookie.maxAge=10s", "server.servlet.session.cookie.sameSite=strict").run((context) -> {
DefaultCookieSerializer cookieSerializer = context.getBean(DefaultCookieSerializer.class);
assertThat(cookieSerializer).hasFieldOrPropertyWithValue("cookieName", "sid");
assertThat(cookieSerializer).hasFieldOrPropertyWithValue("domainName", "spring");
assertThat(cookieSerializer).hasFieldOrPropertyWithValue("cookiePath", "/test");
assertThat(cookieSerializer).hasFieldOrPropertyWithValue("useHttpOnlyCookie", false);
assertThat(cookieSerializer).hasFieldOrPropertyWithValue("useSecureCookie", false);
assertThat(cookieSerializer).hasFieldOrPropertyWithValue("cookieMaxAge", 10);
assertThat(cookieSerializer).hasFieldOrPropertyWithValue("sameSite", "Strict");
});
}
Aggregations