Commit 22c22a1c authored by Brian Clozel's avatar Brian Clozel

Move server.session.* to server.servlet.session.*

Closes gh-11589
parent 199d2e30
...@@ -23,7 +23,7 @@ import java.util.Set; ...@@ -23,7 +23,7 @@ import java.util.Set;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties.Session; import org.springframework.boot.autoconfigure.web.ServerProperties.Servlet.Session;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.DispatcherType; import org.springframework.boot.web.servlet.DispatcherType;
import org.springframework.session.web.http.SessionRepositoryFilter; import org.springframework.session.web.http.SessionRepositoryFilter;
...@@ -53,7 +53,7 @@ public class SessionProperties { ...@@ -53,7 +53,7 @@ public class SessionProperties {
public SessionProperties(ObjectProvider<ServerProperties> serverProperties) { public SessionProperties(ObjectProvider<ServerProperties> serverProperties) {
ServerProperties properties = serverProperties.getIfUnique(); ServerProperties properties = serverProperties.getIfUnique();
Session session = (properties == null ? null : properties.getSession()); Session session = (properties == null ? null : properties.getServlet().getSession());
this.timeout = (session == null ? null : session.getTimeout()); this.timeout = (session == null ? null : session.getTimeout());
} }
...@@ -68,7 +68,7 @@ public class SessionProperties { ...@@ -68,7 +68,7 @@ public class SessionProperties {
/** /**
* Return the session timeout. * Return the session timeout.
* @return the session timeout * @return the session timeout
* @see ServerProperties#getSession() * @see ServerProperties.Servlet#getSession()
*/ */
public Duration getTimeout() { public Duration getTimeout() {
return this.timeout; return this.timeout;
......
...@@ -98,8 +98,6 @@ public class ServerProperties { ...@@ -98,8 +98,6 @@ public class ServerProperties {
*/ */
private Duration connectionTimeout; private Duration connectionTimeout;
private final Session session = new Session();
@NestedConfigurationProperty @NestedConfigurationProperty
private Ssl ssl; private Ssl ssl;
...@@ -177,10 +175,6 @@ public class ServerProperties { ...@@ -177,10 +175,6 @@ public class ServerProperties {
return this.error; return this.error;
} }
public Session getSession() {
return this.session;
}
public Ssl getSsl() { public Ssl getSsl() {
return this.ssl; return this.ssl;
} }
...@@ -236,6 +230,8 @@ public class ServerProperties { ...@@ -236,6 +230,8 @@ public class ServerProperties {
@NestedConfigurationProperty @NestedConfigurationProperty
private final Jsp jsp = new Jsp(); private final Jsp jsp = new Jsp();
private final Session session = new Session();
public String getContextPath() { public String getContextPath() {
return this.contextPath; return this.contextPath;
} }
...@@ -268,6 +264,10 @@ public class ServerProperties { ...@@ -268,6 +264,10 @@ public class ServerProperties {
return this.jsp; return this.jsp;
} }
public Session getSession() {
return this.session;
}
public String getServletMapping() { public String getServletMapping() {
if (this.path.equals("") || this.path.equals("/")) { if (this.path.equals("") || this.path.equals("/")) {
return "/"; return "/";
...@@ -319,196 +319,196 @@ public class ServerProperties { ...@@ -319,196 +319,196 @@ public class ServerProperties {
return result; return result;
} }
}
/**
* Session properties.
*/
public static class Session {
/** /**
* Session timeout. If a duration suffix is not specified, seconds will be used. * Session properties.
*/ */
@DefaultDurationUnit(ChronoUnit.SECONDS) public static class Session {
private Duration timeout;
/** /**
* Session tracking modes (one or more of the following: "cookie", "url", "ssl"). * Session timeout. If a duration suffix is not specified, seconds will be used.
*/ */
private Set<SessionTrackingMode> trackingModes; @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration timeout;
/** /**
* Whether to persist session data between restarts. * Session tracking modes (one or more of the following: "cookie", "url", "ssl").
*/ */
private boolean persistent; private Set<SessionTrackingMode> trackingModes;
/** /**
* Directory used to store session data. * Whether to persist session data between restarts.
*/ */
private File storeDir; private boolean persistent;
private final Cookie cookie = new Cookie(); /**
* Directory used to store session data.
*/
private File storeDir;
public Cookie getCookie() { private final Cookie cookie = new Cookie();
return this.cookie;
}
public Duration getTimeout() { public Cookie getCookie() {
return this.timeout; return this.cookie;
} }
public void setTimeout(Duration timeout) { public Duration getTimeout() {
this.timeout = timeout; return this.timeout;
} }
public Set<SessionTrackingMode> getTrackingModes() { public void setTimeout(Duration timeout) {
return this.trackingModes; this.timeout = timeout;
} }
public void setTrackingModes(Set<SessionTrackingMode> trackingModes) { public Set<SessionTrackingMode> getTrackingModes() {
this.trackingModes = trackingModes; return this.trackingModes;
} }
public boolean isPersistent() { public void setTrackingModes(Set<SessionTrackingMode> trackingModes) {
return this.persistent; this.trackingModes = trackingModes;
} }
public void setPersistent(boolean persistent) { public boolean isPersistent() {
this.persistent = persistent; return this.persistent;
} }
public File getStoreDir() { public void setPersistent(boolean persistent) {
return this.storeDir; this.persistent = persistent;
} }
public void setStoreDir(File storeDir) { public File getStoreDir() {
this.storeDir = storeDir; return this.storeDir;
} }
/** public void setStoreDir(File storeDir) {
* Cookie properties. this.storeDir = storeDir;
*/ }
public static class Cookie {
/** /**
* Session cookie name. * Cookie properties.
*/ */
private String name; public static class Cookie {
/** /**
* Domain for the session cookie. * Session cookie name.
*/ */
private String domain; private String name;
/** /**
* Path of the session cookie. * Domain for the session cookie.
*/ */
private String path; private String domain;
/** /**
* Comment for the session cookie. * Path of the session cookie.
*/ */
private String comment; private String path;
/** /**
* "HttpOnly" flag for the session cookie. * Comment for the session cookie.
*/ */
private Boolean httpOnly; private String comment;
/** /**
* "Secure" flag for the session cookie. * "HttpOnly" flag for the session cookie.
*/ */
private Boolean secure; private Boolean httpOnly;
/** /**
* Maximum age of the session cookie. * "Secure" flag for the session cookie.
*/ */
@DefaultDurationUnit(ChronoUnit.SECONDS) private Boolean secure;
private Duration maxAge;
public String getName() { /**
return this.name; * Maximum age of the session cookie.
} */
@DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration maxAge;
public void setName(String name) { public String getName() {
this.name = name; return this.name;
} }
public String getDomain() { public void setName(String name) {
return this.domain; this.name = name;
} }
public void setDomain(String domain) { public String getDomain() {
this.domain = domain; return this.domain;
} }
public String getPath() { public void setDomain(String domain) {
return this.path; this.domain = domain;
} }
public void setPath(String path) { public String getPath() {
this.path = path; return this.path;
} }
public String getComment() { public void setPath(String path) {
return this.comment; this.path = path;
} }
public void setComment(String comment) { public String getComment() {
this.comment = comment; return this.comment;
} }
public Boolean getHttpOnly() { public void setComment(String comment) {
return this.httpOnly; this.comment = comment;
} }
public void setHttpOnly(Boolean httpOnly) { public Boolean getHttpOnly() {
this.httpOnly = httpOnly; return this.httpOnly;
} }
public Boolean getSecure() { public void setHttpOnly(Boolean httpOnly) {
return this.secure; this.httpOnly = httpOnly;
} }
public void setSecure(Boolean secure) { public Boolean getSecure() {
this.secure = secure; return this.secure;
} }
public Duration getMaxAge() { public void setSecure(Boolean secure) {
return this.maxAge; this.secure = secure;
} }
public void setMaxAge(Duration maxAge) { public Duration getMaxAge() {
this.maxAge = maxAge; return this.maxAge;
} }
} public void setMaxAge(Duration maxAge) {
this.maxAge = maxAge;
}
/** }
* Available session tracking modes (mirrors
* {@link javax.servlet.SessionTrackingMode}.
*/
public enum SessionTrackingMode {
/** /**
* Send a cookie in response to the client's first request. * Available session tracking modes (mirrors
* {@link javax.servlet.SessionTrackingMode}.
*/ */
COOKIE, public enum SessionTrackingMode {
/** /**
* Rewrite the URL to append a session ID. * Send a cookie in response to the client's first request.
*/ */
URL, COOKIE,
/** /**
* Use SSL build-in mechanism to track the session. * Rewrite the URL to append a session ID.
*/ */
SSL URL,
} /**
* Use SSL build-in mechanism to track the session.
*/
SSL
}
}
} }
/** /**
* Tomcat properties. * Tomcat properties.
*/ */
......
...@@ -24,7 +24,7 @@ import javax.servlet.ServletException; ...@@ -24,7 +24,7 @@ import javax.servlet.ServletException;
import javax.servlet.SessionCookieConfig; import javax.servlet.SessionCookieConfig;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties.Session; import org.springframework.boot.autoconfigure.web.ServerProperties.Servlet.Session;
import org.springframework.boot.autoconfigure.web.embedded.jetty.JettyCustomizer; import org.springframework.boot.autoconfigure.web.embedded.jetty.JettyCustomizer;
import org.springframework.boot.autoconfigure.web.embedded.tomcat.TomcatCustomizer; import org.springframework.boot.autoconfigure.web.embedded.tomcat.TomcatCustomizer;
import org.springframework.boot.autoconfigure.web.embedded.undertow.UndertowCustomizer; import org.springframework.boot.autoconfigure.web.embedded.undertow.UndertowCustomizer;
...@@ -89,11 +89,11 @@ public class DefaultServletWebServerFactoryCustomizer ...@@ -89,11 +89,11 @@ public class DefaultServletWebServerFactoryCustomizer
if (this.serverProperties.getDisplayName() != null) { if (this.serverProperties.getDisplayName() != null) {
factory.setDisplayName(this.serverProperties.getDisplayName()); factory.setDisplayName(this.serverProperties.getDisplayName());
} }
if (this.serverProperties.getSession().getTimeout() != null) { if (this.serverProperties.getServlet().getSession().getTimeout() != null) {
factory.setSessionTimeout(this.serverProperties.getSession().getTimeout()); factory.setSessionTimeout(this.serverProperties.getServlet().getSession().getTimeout());
} }
factory.setPersistSession(this.serverProperties.getSession().isPersistent()); factory.setPersistSession(this.serverProperties.getServlet().getSession().isPersistent());
factory.setSessionStoreDir(this.serverProperties.getSession().getStoreDir()); factory.setSessionStoreDir(this.serverProperties.getServlet().getSession().getStoreDir());
if (this.serverProperties.getSsl() != null) { if (this.serverProperties.getSsl() != null) {
factory.setSsl(this.serverProperties.getSsl()); factory.setSsl(this.serverProperties.getSsl());
} }
...@@ -121,7 +121,7 @@ public class DefaultServletWebServerFactoryCustomizer ...@@ -121,7 +121,7 @@ public class DefaultServletWebServerFactoryCustomizer
(UndertowServletWebServerFactory) factory); (UndertowServletWebServerFactory) factory);
} }
factory.addInitializers( factory.addInitializers(
new SessionConfiguringInitializer(this.serverProperties.getSession())); new SessionConfiguringInitializer(this.serverProperties.getServlet().getSession()));
factory.addInitializers(new InitParameterConfiguringServletContextInitializer( factory.addInitializers(new InitParameterConfiguringServletContextInitializer(
this.serverProperties.getServlet().getContextParameters())); this.serverProperties.getServlet().getContextParameters()));
} }
......
...@@ -1020,6 +1020,96 @@ ...@@ -1020,6 +1020,96 @@
"level": "error" "level": "error"
} }
}, },
{
"name" : "server.session.cookie.comment",
"type" : "java.lang.String",
"description" : "Comment for the session cookie.",
"deprecation" : {
"replacement" : "server.servlet.session.cookie.comment",
"level" : "error"
}
}, {
"name" : "server.session.cookie.domain",
"type" : "java.lang.String",
"description" : "Domain for the session cookie.",
"deprecation" : {
"replacement" : "server.servlet.session.cookie.domain",
"level" : "error"
}
}, {
"name" : "server.session.cookie.http-only",
"type" : "java.lang.Boolean",
"description" : "\"HttpOnly\" flag for the session cookie.",
"deprecation" : {
"replacement" : "server.servlet.session.cookie.http-only",
"level" : "error"
}
}, {
"name" : "server.session.cookie.max-age",
"type" : "java.time.Duration",
"description" : "Maximum age of the session cookie.",
"deprecation" : {
"replacement" : "server.servlet.session.cookie.max-age",
"level" : "error"
}
}, {
"name" : "server.session.cookie.name",
"type" : "java.lang.String",
"description" : "Session cookie name.",
"deprecation" : {
"replacement" : "server.servlet.session.cookie.name",
"level" : "error"
}
}, {
"name" : "server.session.cookie.path",
"type" : "java.lang.String",
"description" : "Path of the session cookie.",
"deprecation" : {
"replacement" : "server.servlet.session.cookie.path",
"level" : "error"
}
}, {
"name" : "server.session.cookie.secure",
"type" : "java.lang.Boolean",
"description" : "\"Secure\" flag for the session cookie.",
"deprecation" : {
"replacement" : "server.servlet.session.cookie.secure",
"level" : "error"
}
}, {
"name" : "server.session.persistent",
"type" : "java.lang.Boolean",
"description" : "Whether to persist session data between restarts.",
"defaultValue" : false,
"deprecation" : {
"replacement" : "server.servlet.session.persistent",
"level" : "error"
}
}, {
"name" : "server.session.store-dir",
"type" : "java.io.File",
"description" : "Directory used to store session data.",
"deprecation" : {
"replacement" : "server.servlet.session.store-dir",
"level" : "error"
}
}, {
"name" : "server.session.timeout",
"type" : "java.time.Duration",
"description" : "Session timeout. If a duration suffix is not specified, seconds will be used.",
"deprecation" : {
"replacement" : "server.servlet.session.timeout",
"level" : "error"
}
}, {
"name" : "server.session.tracking-modes",
"type" : "java.util.Set<org.springframework.boot.autoconfigure.web.ServerProperties.Session.SessionTrackingMode>",
"description" : "Session tracking modes (one or more of the following: \"cookie\", \"url\", \"ssl\").",
"deprecation" : {
"replacement" : "server.servlet.session.tracking-modes",
"level" : "error"
}
},
{ {
"name": "server.undertow.buffers-per-region", "name": "server.undertow.buffers-per-region",
"type": "java.lang.Integer", "type": "java.lang.Integer",
......
...@@ -212,15 +212,15 @@ public class DefaultServletWebServerFactoryCustomizerTests { ...@@ -212,15 +212,15 @@ public class DefaultServletWebServerFactoryCustomizerTests {
@Test @Test
public void customizeSessionProperties() throws Exception { public void customizeSessionProperties() throws Exception {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("server.session.timeout", "123"); map.put("server.servlet.session.timeout", "123");
map.put("server.session.tracking-modes", "cookie,url"); map.put("server.servlet.session.tracking-modes", "cookie,url");
map.put("server.session.cookie.name", "testname"); map.put("server.servlet.session.cookie.name", "testname");
map.put("server.session.cookie.domain", "testdomain"); map.put("server.servlet.session.cookie.domain", "testdomain");
map.put("server.session.cookie.path", "/testpath"); map.put("server.servlet.session.cookie.path", "/testpath");
map.put("server.session.cookie.comment", "testcomment"); map.put("server.servlet.session.cookie.comment", "testcomment");
map.put("server.session.cookie.http-only", "true"); map.put("server.servlet.session.cookie.http-only", "true");
map.put("server.session.cookie.secure", "true"); map.put("server.servlet.session.cookie.secure", "true");
map.put("server.session.cookie.max-age", "60"); map.put("server.servlet.session.cookie.max-age", "60");
bindProperties(map); bindProperties(map);
ConfigurableServletWebServerFactory factory = mock( ConfigurableServletWebServerFactory factory = mock(
ConfigurableServletWebServerFactory.class); ConfigurableServletWebServerFactory.class);
...@@ -536,7 +536,7 @@ public class DefaultServletWebServerFactoryCustomizerTests { ...@@ -536,7 +536,7 @@ public class DefaultServletWebServerFactoryCustomizerTests {
@Test @Test
public void sessionStoreDir() { public void sessionStoreDir() {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("server.session.store-dir", "myfolder"); map.put("server.servlet.session.store-dir", "myfolder");
bindProperties(map); bindProperties(map);
JettyServletWebServerFactory factory = spy(new JettyServletWebServerFactory()); JettyServletWebServerFactory factory = spy(new JettyServletWebServerFactory());
this.customizer.customize(factory); this.customizer.customize(factory);
......
...@@ -50,7 +50,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro ...@@ -50,7 +50,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
devToolsProperties.put("spring.freemarker.cache", "false"); devToolsProperties.put("spring.freemarker.cache", "false");
devToolsProperties.put("spring.groovy.template.cache", "false"); devToolsProperties.put("spring.groovy.template.cache", "false");
devToolsProperties.put("spring.mustache.cache", "false"); devToolsProperties.put("spring.mustache.cache", "false");
devToolsProperties.put("server.session.persistent", "true"); devToolsProperties.put("server.servlet.session.persistent", "true");
devToolsProperties.put("spring.h2.console.enabled", "true"); devToolsProperties.put("spring.h2.console.enabled", "true");
devToolsProperties.put("spring.resources.cache.period", "0"); devToolsProperties.put("spring.resources.cache.period", "0");
devToolsProperties.put("spring.resources.chain.cache", "false"); devToolsProperties.put("spring.resources.chain.cache", "false");
......
...@@ -194,17 +194,17 @@ content into your application. Rather, pick only the properties that you need. ...@@ -194,17 +194,17 @@ content into your application. Rather, pick only the properties that you need.
server.servlet.jsp.init-parameters.*= # Init parameters used to configure the JSP servlet. server.servlet.jsp.init-parameters.*= # Init parameters used to configure the JSP servlet.
server.servlet.jsp.registered=true # Whether the JSP servlet is registered. server.servlet.jsp.registered=true # Whether the JSP servlet is registered.
server.servlet.path=/ # Path of the main dispatcher servlet. server.servlet.path=/ # Path of the main dispatcher servlet.
server.session.cookie.comment= # Comment for the session cookie. server.servlet.session.cookie.comment= # Comment for the session cookie.
server.session.cookie.domain= # Domain for the session cookie. server.servlet.session.cookie.domain= # Domain for the session cookie.
server.session.cookie.http-only= # "HttpOnly" flag for the session cookie. server.servlet.session.cookie.http-only= # "HttpOnly" flag for the session cookie.
server.session.cookie.max-age= # Maximum age of the session cookie. If a duration suffix is not specified, seconds will be used. server.servlet.session.cookie.max-age= # Maximum age of the session cookie. If a duration suffix is not specified, seconds will be used.
server.session.cookie.name= # Session cookie name. server.servlet.session.cookie.name= # Session cookie name.
server.session.cookie.path= # Path of the session cookie. server.servlet.session.cookie.path= # Path of the session cookie.
server.session.cookie.secure= # "Secure" flag for the session cookie. server.servlet.session.cookie.secure= # "Secure" flag for the session cookie.
server.session.persistent=false # Whether to persist session data between restarts. server.servlet.session.persistent=false # Whether to persist session data between restarts.
server.session.store-dir= # Directory used to store session data. server.servlet.session.store-dir= # Directory used to store session data.
server.session.timeout= # Session timeout. If a duration suffix is not specified, seconds will be used. server.servlet.session.timeout= # Session timeout. If a duration suffix is not specified, seconds will be used.
server.session.tracking-modes= # Session tracking modes (one or more of the following: "cookie", "url", "ssl"). server.servlet.session.tracking-modes= # Session tracking modes (one or more of the following: "cookie", "url", "ssl").
server.ssl.ciphers= # Supported SSL ciphers. server.ssl.ciphers= # Supported SSL ciphers.
server.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store. server.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store.
server.ssl.enabled= # Enable SSL support. server.ssl.enabled= # Enable SSL support.
......
...@@ -2809,10 +2809,10 @@ Common server settings include: ...@@ -2809,10 +2809,10 @@ Common server settings include:
* Network settings: Listen port for incoming HTTP requests (`server.port`), interface * Network settings: Listen port for incoming HTTP requests (`server.port`), interface
address to bind to `server.address`, and so on. address to bind to `server.address`, and so on.
* Session settings: Whether the session is persistent (`server.session.persistence`), * Session settings: Whether the session is persistent (`server.servlet.session.persistence`),
session timeout (`server.session.timeout`), location of session data session timeout (`server.servlet.session.timeout`), location of session data
(`server.session.store-dir`), and session-cookie configuration (`server.servlet.session.store-dir`), and session-cookie configuration
(`server.session.cookie.*`). (`server.servlet.session.cookie.*`).
* Error management: Location of the error page (`server.error.path`) and so on. * Error management: Location of the error page (`server.error.path`) and so on.
* <<howto.adoc#howto-configure-ssl,SSL>> * <<howto.adoc#howto-configure-ssl,SSL>>
* <<howto.adoc#how-to-enable-http-response-compression,HTTP compression>> * <<howto.adoc#how-to-enable-http-response-compression,HTTP compression>>
......
...@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Vedran Pavic * @author Vedran Pavic
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(properties = "server.session.timeout:2", webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(properties = "server.servlet.session.timeout:2", webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SampleSessionWebFluxApplicationTests { public class SampleSessionWebFluxApplicationTests {
@LocalServerPort @LocalServerPort
......
...@@ -59,7 +59,7 @@ public class SampleSessionApplicationTests { ...@@ -59,7 +59,7 @@ public class SampleSessionApplicationTests {
private ConfigurableApplicationContext createContext() { private ConfigurableApplicationContext createContext() {
ConfigurableApplicationContext context = new SpringApplicationBuilder() ConfigurableApplicationContext context = new SpringApplicationBuilder()
.sources(SampleSessionApplication.class) .sources(SampleSessionApplication.class)
.properties("server.port:0", "server.session.timeout:1") .properties("server.port:0", "server.servlet.session.timeout:1")
.initializers(new ServerPortInfoApplicationContextInitializer()).run(); .initializers(new ServerPortInfoApplicationContextInitializer()).run();
return context; return context;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment