mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Add sessionTimeout to embedded servlet containers
* ConfigurableEmbeddedServletContainerFactory now has a sessionTimeout property * The ServerProperties in Actuator supports it [Fixes #53667353] [bs-243] Support setSessionTimeout
This commit is contained in:
parent
1b780beddd
commit
ea3d2e74dd
@ -55,6 +55,7 @@ public class EndpointWebMvcChildContextConfiguration implements
|
|||||||
factory.setPort(this.managementServerProperties.getPort());
|
factory.setPort(this.managementServerProperties.getPort());
|
||||||
factory.setAddress(this.managementServerProperties.getAddress());
|
factory.setAddress(this.managementServerProperties.getAddress());
|
||||||
factory.setContextPath(this.managementServerProperties.getContextPath());
|
factory.setContextPath(this.managementServerProperties.getContextPath());
|
||||||
|
// TODO: Disable sessions
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for the
|
* {@link EnableAutoConfiguration Auto-configuration} for the
|
||||||
* {@link ManagementServerPropertiesAutoConfiguration} bean.
|
* {@link ManagementServerProperties} bean.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
|
@ -67,6 +67,8 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
|
|
||||||
private InetAddress address;
|
private InetAddress address;
|
||||||
|
|
||||||
|
private int sessionTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link AbstractEmbeddedServletContainerFactory} instance.
|
* Create a new {@link AbstractEmbeddedServletContainerFactory} instance.
|
||||||
*/
|
*/
|
||||||
@ -155,6 +157,30 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
|||||||
return this.address;
|
return this.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The session timeout in minutes.
|
||||||
|
*
|
||||||
|
* @param sessionTimeout the session timeout to set (default 30)
|
||||||
|
*/
|
||||||
|
public void setSessionTimeout(int sessionTimeout) {
|
||||||
|
this.sessionTimeout = sessionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the session timeout in minutes
|
||||||
|
*/
|
||||||
|
public int getSessionTimeout() {
|
||||||
|
return this.sessionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets {@link ServletContextInitializer} that should be applied in addition to
|
||||||
|
* {@link #getEmbeddedServletContainer(ServletContextInitializer...)} parameters. This
|
||||||
|
* method will replace any previously set or added initializers.
|
||||||
|
* @param initializers the initializers to set
|
||||||
|
* @see #addInitializers
|
||||||
|
* @see #getInitializers
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setInitializers(List<? extends ServletContextInitializer> initializers) {
|
public void setInitializers(List<? extends ServletContextInitializer> initializers) {
|
||||||
Assert.notNull(initializers, "Initializers must not be null");
|
Assert.notNull(initializers, "Initializers must not be null");
|
||||||
|
@ -46,6 +46,25 @@ public interface ConfigurableEmbeddedServletContainerFactory extends
|
|||||||
*/
|
*/
|
||||||
void setPort(int port);
|
void setPort(int port);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The port that the embedded server listens on.
|
||||||
|
* @return the port
|
||||||
|
*/
|
||||||
|
int getPort();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The session timeout in seconds (default 30). If 0 or negative then sessions never
|
||||||
|
* expire.
|
||||||
|
*
|
||||||
|
* @param sessionTimeout the session timeout
|
||||||
|
*/
|
||||||
|
void setSessionTimeout(int sessionTimeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the session timeout value
|
||||||
|
*/
|
||||||
|
int getSessionTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the specific network address that the server should bind to.
|
* Sets the specific network address that the server should bind to.
|
||||||
* @param address the address to set (defaults to {@code null})
|
* @param address the address to set (defaults to {@code null})
|
||||||
|
@ -121,6 +121,8 @@ public class JettyEmbeddedServletContainerFactory extends
|
|||||||
Configuration[] configurations = getWebAppContextConfigurations(context,
|
Configuration[] configurations = getWebAppContextConfigurations(context,
|
||||||
initializersToUse);
|
initializersToUse);
|
||||||
context.setConfigurations(configurations);
|
context.setConfigurations(configurations);
|
||||||
|
context.getSessionHandler().getSessionManager()
|
||||||
|
.setMaxInactiveInterval(getSessionTimeout());
|
||||||
postProcessWebAppContext(context);
|
postProcessWebAppContext(context);
|
||||||
|
|
||||||
server.setHandler(context);
|
server.setHandler(context);
|
||||||
|
@ -45,6 +45,8 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
|
|||||||
|
|
||||||
private InetAddress address;
|
private InetAddress address;
|
||||||
|
|
||||||
|
private int sessionTimeout = 30;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String contextPath = "";
|
private String contextPath = "";
|
||||||
|
|
||||||
@ -78,11 +80,20 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
|
|||||||
this.address = address;
|
this.address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSessionTimeout() {
|
||||||
|
return this.sessionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionTimeout(int sessionTimeout) {
|
||||||
|
this.sessionTimeout = sessionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void customize(ConfigurableEmbeddedServletContainerFactory factory) {
|
public void customize(ConfigurableEmbeddedServletContainerFactory factory) {
|
||||||
factory.setPort(getPort());
|
factory.setPort(getPort());
|
||||||
factory.setAddress(getAddress());
|
factory.setAddress(getAddress());
|
||||||
factory.setContextPath(getContextPath());
|
factory.setContextPath(getContextPath());
|
||||||
|
factory.setSessionTimeout(getSessionTimeout());
|
||||||
if (factory instanceof TomcatEmbeddedServletContainerFactory) {
|
if (factory instanceof TomcatEmbeddedServletContainerFactory) {
|
||||||
getTomcat().customizeTomcat((TomcatEmbeddedServletContainerFactory) factory);
|
getTomcat().customizeTomcat((TomcatEmbeddedServletContainerFactory) factory);
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,7 @@ public class TomcatEmbeddedServletContainerFactory extends
|
|||||||
for (MimeMappings.Mapping mapping : getMimeMappings()) {
|
for (MimeMappings.Mapping mapping : getMimeMappings()) {
|
||||||
context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
|
context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
|
||||||
}
|
}
|
||||||
|
context.setSessionTimeout(getSessionTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user