| 
35 | 35 | import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;  | 
36 | 36 | import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration.SessionRepositoryConfiguration;  | 
37 | 37 | import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration.SessionRepositoryValidator;  | 
 | 38 | +import org.springframework.boot.autoconfigure.web.ServerProperties;  | 
38 | 39 | import org.springframework.boot.context.properties.EnableConfigurationProperties;  | 
39 | 40 | import org.springframework.context.ApplicationContext;  | 
 | 41 | +import org.springframework.context.annotation.Bean;  | 
40 | 42 | import org.springframework.context.annotation.Configuration;  | 
41 | 43 | import org.springframework.context.annotation.Import;  | 
42 | 44 | import org.springframework.context.annotation.ImportSelector;  | 
43 | 45 | import org.springframework.core.type.AnnotationMetadata;  | 
44 | 46 | import org.springframework.session.Session;  | 
45 | 47 | import org.springframework.session.SessionRepository;  | 
 | 48 | +import org.springframework.session.web.http.CookieSerializer;  | 
 | 49 | +import org.springframework.session.web.http.DefaultCookieSerializer;  | 
 | 50 | +import org.springframework.session.web.http.HeaderHttpSessionStrategy;  | 
46 | 51 | 
 
  | 
47 | 52 | /**  | 
48 | 53 |  * {@link EnableAutoConfiguration Auto-configuration} for Spring Session.  | 
 | 
57 | 62 | @Configuration  | 
58 | 63 | @ConditionalOnClass(Session.class)  | 
59 | 64 | @ConditionalOnWebApplication(type = Type.SERVLET)  | 
60 |  | -@EnableConfigurationProperties(SessionProperties.class)  | 
 | 65 | +@EnableConfigurationProperties({ ServerProperties.class, SessionProperties.class })  | 
61 | 66 | @AutoConfigureAfter({ DataSourceAutoConfiguration.class, HazelcastAutoConfiguration.class,  | 
62 | 67 | 		JdbcTemplateAutoConfiguration.class, MongoAutoConfiguration.class,  | 
63 | 68 | 		RedisAutoConfiguration.class })  | 
64 | 69 | @Import({ SessionRepositoryConfiguration.class, SessionRepositoryValidator.class,  | 
65 | 70 | 		SessionRepositoryFilterConfiguration.class })  | 
66 | 71 | public class SessionAutoConfiguration {  | 
67 | 72 | 
 
  | 
 | 73 | +	private final ServerProperties serverProperties;  | 
 | 74 | + | 
 | 75 | +	public SessionAutoConfiguration(ServerProperties serverProperties) {  | 
 | 76 | +		this.serverProperties = serverProperties;  | 
 | 77 | +	}  | 
 | 78 | + | 
 | 79 | +	@Bean  | 
 | 80 | +	@ConditionalOnMissingBean({ CookieSerializer.class, HeaderHttpSessionStrategy.class })  | 
 | 81 | +	public DefaultCookieSerializer cookieSerializer() {  | 
 | 82 | +		ServerProperties.Session.Cookie cookie = this.serverProperties.getSession()  | 
 | 83 | +				.getCookie();  | 
 | 84 | +		DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();  | 
 | 85 | +		if (cookie.getName() != null) {  | 
 | 86 | +			cookieSerializer.setCookieName(cookie.getName());  | 
 | 87 | +		}  | 
 | 88 | +		if (cookie.getDomain() != null) {  | 
 | 89 | +			cookieSerializer.setDomainName(cookie.getDomain());  | 
 | 90 | +		}  | 
 | 91 | +		if (cookie.getPath() != null) {  | 
 | 92 | +			cookieSerializer.setCookiePath(cookie.getPath());  | 
 | 93 | +		}  | 
 | 94 | +		if (cookie.getHttpOnly() != null) {  | 
 | 95 | +			cookieSerializer.setUseHttpOnlyCookie(cookie.getHttpOnly());  | 
 | 96 | +		}  | 
 | 97 | +		if (cookie.getSecure() != null) {  | 
 | 98 | +			cookieSerializer.setUseSecureCookie(cookie.getSecure());  | 
 | 99 | +		}  | 
 | 100 | +		if (cookie.getMaxAge() != null) {  | 
 | 101 | +			cookieSerializer.setCookieMaxAge(cookie.getMaxAge());  | 
 | 102 | +		}  | 
 | 103 | +		return cookieSerializer;  | 
 | 104 | +	}  | 
 | 105 | + | 
68 | 106 | 	@Configuration  | 
69 | 107 | 	@ConditionalOnMissingBean(SessionRepository.class)  | 
70 | 108 | 	@Import({ SessionRepositoryImplementationValidator.class,  | 
 | 
0 commit comments