From 935199b6ba1dd0ca071d978ed299846511dd15be Mon Sep 17 00:00:00 2001 From: weixsun Date: Sun, 16 May 2021 20:15:07 +0800 Subject: [PATCH 1/2] Polish AbstractServletWebServerFactory See gh-26478 --- .../AbstractServletWebServerFactory.java | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java index e4b485105c..e00e9bd297 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java @@ -19,6 +19,7 @@ package org.springframework.boot.web.servlet.server; import java.io.File; import java.net.URL; import java.nio.charset.Charset; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -37,6 +38,7 @@ import javax.servlet.SessionCookieConfig; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; import org.springframework.boot.web.server.MimeMappings; import org.springframework.boot.web.servlet.ServletContextInitializer; @@ -317,27 +319,14 @@ public abstract class AbstractServletWebServerFactory extends AbstractConfigurab private void configureSessionCookie(SessionCookieConfig config) { Session.Cookie cookie = this.session.getCookie(); - if (cookie.getName() != null) { - config.setName(cookie.getName()); - } - if (cookie.getDomain() != null) { - config.setDomain(cookie.getDomain()); - } - if (cookie.getPath() != null) { - config.setPath(cookie.getPath()); - } - if (cookie.getComment() != null) { - config.setComment(cookie.getComment()); - } - if (cookie.getHttpOnly() != null) { - config.setHttpOnly(cookie.getHttpOnly()); - } - if (cookie.getSecure() != null) { - config.setSecure(cookie.getSecure()); - } - if (cookie.getMaxAge() != null) { - config.setMaxAge((int) cookie.getMaxAge().getSeconds()); - } + PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); + map.from(cookie::getName).to(config::setName); + map.from(cookie::getDomain).to(config::setDomain); + map.from(cookie::getPath).to(config::setPath); + map.from(cookie::getComment).to(config::setComment); + map.from(cookie::getHttpOnly).to(config::setHttpOnly); + map.from(cookie::getSecure).to(config::setSecure); + map.from(cookie::getMaxAge).asInt(Duration::getSeconds).to(config::setMaxAge); } private Set unwrap(Set modes) { From e9174c1e3d96de85d866d2126475c9b051586b14 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sun, 16 May 2021 15:31:48 +0200 Subject: [PATCH 2/2] Update copyright year of changed files See gh-26478 --- .../web/servlet/server/AbstractServletWebServerFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java index e00e9bd297..fc4a0aa3d2 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.