|
19 | 19 | import java.io.File; |
20 | 20 | import java.net.URL; |
21 | 21 | import java.nio.charset.Charset; |
| 22 | +import java.time.Duration; |
22 | 23 | import java.util.ArrayList; |
23 | 24 | import java.util.Arrays; |
24 | 25 | import java.util.Collections; |
|
37 | 38 | import org.apache.commons.logging.Log; |
38 | 39 | import org.apache.commons.logging.LogFactory; |
39 | 40 |
|
| 41 | +import org.springframework.boot.context.properties.PropertyMapper; |
40 | 42 | import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; |
41 | 43 | import org.springframework.boot.web.server.MimeMappings; |
42 | 44 | import org.springframework.boot.web.servlet.ServletContextInitializer; |
@@ -317,27 +319,14 @@ public void onStartup(ServletContext servletContext) throws ServletException { |
317 | 319 |
|
318 | 320 | private void configureSessionCookie(SessionCookieConfig config) { |
319 | 321 | Session.Cookie cookie = this.session.getCookie(); |
320 | | - if (cookie.getName() != null) { |
321 | | - config.setName(cookie.getName()); |
322 | | - } |
323 | | - if (cookie.getDomain() != null) { |
324 | | - config.setDomain(cookie.getDomain()); |
325 | | - } |
326 | | - if (cookie.getPath() != null) { |
327 | | - config.setPath(cookie.getPath()); |
328 | | - } |
329 | | - if (cookie.getComment() != null) { |
330 | | - config.setComment(cookie.getComment()); |
331 | | - } |
332 | | - if (cookie.getHttpOnly() != null) { |
333 | | - config.setHttpOnly(cookie.getHttpOnly()); |
334 | | - } |
335 | | - if (cookie.getSecure() != null) { |
336 | | - config.setSecure(cookie.getSecure()); |
337 | | - } |
338 | | - if (cookie.getMaxAge() != null) { |
339 | | - config.setMaxAge((int) cookie.getMaxAge().getSeconds()); |
340 | | - } |
| 322 | + PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); |
| 323 | + map.from(cookie::getName).to(config::setName); |
| 324 | + map.from(cookie::getDomain).to(config::setDomain); |
| 325 | + map.from(cookie::getPath).to(config::setPath); |
| 326 | + map.from(cookie::getComment).to(config::setComment); |
| 327 | + map.from(cookie::getHttpOnly).to(config::setHttpOnly); |
| 328 | + map.from(cookie::getSecure).to(config::setSecure); |
| 329 | + map.from(cookie::getMaxAge).asInt(Duration::getSeconds).to(config::setMaxAge); |
341 | 330 | } |
342 | 331 |
|
343 | 332 | private Set<javax.servlet.SessionTrackingMode> unwrap(Set<Session.SessionTrackingMode> modes) { |
|
0 commit comments