org.springframework.session.web.http.DefaultCookieSerializer Java Examples

The following examples show how to use org.springframework.session.web.http.DefaultCookieSerializer. 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: SpringHttpSessionConfigurationTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test
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");
}
 
Example #2
Source File: FixSpringSessionCookieSerializerConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean
	@ConditionalOnMissingBean(CookieSerializer.class)
	public CookieSerializer cookieSerializer(){
		DefaultCookieSerializer serializer = new DefaultCookieSerializer();
		CookieConfig cookieConfig = securityConfig.getCookie();
//		if(StringUtils.isNotBlank(cookieConfig.getPath())){
		serializer.setCookiePath(cookieConfig.getPath());
//		}
		if(StringUtils.isNotBlank(cookieConfig.getDomain())){
			serializer.setDomainName(cookieConfig.getDomain());
		}
		serializer.setCookieName(cookieConfig.getName());
		return serializer;
	}
 
Example #3
Source File: Config.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Bean
public CookieSerializer cookieSerializer() {
	DefaultCookieSerializer serializer = new DefaultCookieSerializer();
	serializer.setCookieName("JSESSIONID"); // <1>
	serializer.setCookiePath("/"); // <2>
	serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$"); // <3>
	return serializer;
}
 
Example #4
Source File: SpringHttpSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
private CookieSerializer createDefaultCookieSerializer() {
	DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
	if (this.servletContext != null) {
		SessionCookieConfig sessionCookieConfig = null;
		try {
			sessionCookieConfig = this.servletContext.getSessionCookieConfig();
		}
		catch (UnsupportedOperationException ex) {
			this.logger.warn("Unable to obtain SessionCookieConfig: " + ex.getMessage());
		}
		if (sessionCookieConfig != null) {
			if (sessionCookieConfig.getName() != null) {
				cookieSerializer.setCookieName(sessionCookieConfig.getName());
			}
			if (sessionCookieConfig.getDomain() != null) {
				cookieSerializer.setDomainName(sessionCookieConfig.getDomain());
			}
			if (sessionCookieConfig.getPath() != null) {
				cookieSerializer.setCookiePath(sessionCookieConfig.getPath());
			}
			if (sessionCookieConfig.getMaxAge() != -1) {
				cookieSerializer.setCookieMaxAge(sessionCookieConfig.getMaxAge());
			}
		}
	}
	if (this.usesSpringSessionRememberMeServices) {
		cookieSerializer.setRememberMeRequestAttribute(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR);
	}
	return cookieSerializer;
}
 
Example #5
Source File: SpringHttpSessionConfigurationTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
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);
}
 
Example #6
Source File: SessionConfig.java    From retro-game with GNU Affero General Public License v3.0 4 votes vote down vote up
@Bean
public CookieSerializer cookieSerializer() {
  DefaultCookieSerializer serializer = new DefaultCookieSerializer();
  serializer.setCookieName("s");
  return serializer;
}