Java Code Examples for org.springframework.session.web.http.CookieSerializer

The following examples show how to use org.springframework.session.web.http.CookieSerializer. These examples are extracted from open source projects. 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
@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 2
Source Project: spring-session   Source File: Config.java    License: 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 3
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 4
@Bean
public CookieSerializer cookieSerializer() {
  DefaultCookieSerializer serializer = new DefaultCookieSerializer();
  serializer.setCookieName("s");
  return serializer;
}
 
Example 5
@PostConstruct
public void init() {
	CookieSerializer cookieSerializer = (this.cookieSerializer != null) ? this.cookieSerializer
			: createDefaultCookieSerializer();
	this.defaultHttpSessionIdResolver.setCookieSerializer(cookieSerializer);
}
 
Example 6
@Autowired(required = false)
public void setCookieSerializer(CookieSerializer cookieSerializer) {
	this.cookieSerializer = cookieSerializer;
}
 
Example 7
@Bean
CookieSerializer cookieSerializer() {
	return mock(CookieSerializer.class);
}