Polish
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
||||
@@ -85,9 +85,7 @@ public abstract class ApplicationContextServerWebExchangeMatcher<C>
|
||||
@SuppressWarnings("unchecked")
|
||||
private C createContext(ServerWebExchange exchange) {
|
||||
ApplicationContext context = exchange.getApplicationContext();
|
||||
if (context == null) {
|
||||
throw new IllegalStateException("No WebApplicationContext found.");
|
||||
}
|
||||
Assert.state(context != null, "No WebApplicationContext found.");
|
||||
if (this.contextClass.isInstance(context)) {
|
||||
return (C) context;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.eclipse.jetty.server.Server;
|
||||
|
||||
/**
|
||||
* {@link JettyServerCustomizer} to add {@link ForwardedRequestCustomizer}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class ForwardHeadersCustomizer implements JettyServerCustomizer {
|
||||
|
||||
@@ -79,4 +79,5 @@ final class JettyHandlerWrappers {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -234,8 +234,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
|
||||
SessionHandler handler = context.getSessionHandler();
|
||||
Duration sessionTimeout = getSession().getTimeout();
|
||||
handler.setMaxInactiveInterval(
|
||||
(sessionTimeout == null || sessionTimeout.isNegative()) ? -1
|
||||
: (int) sessionTimeout.getSeconds());
|
||||
isNegative(sessionTimeout) ? -1 : (int) sessionTimeout.getSeconds());
|
||||
if (getSession().isPersistent()) {
|
||||
DefaultSessionCache cache = new DefaultSessionCache(handler);
|
||||
FileSessionDataStore store = new FileSessionDataStore();
|
||||
@@ -245,6 +244,10 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNegative(Duration sessionTimeout) {
|
||||
return sessionTimeout == null || sessionTimeout.isNegative();
|
||||
}
|
||||
|
||||
private void addLocaleMappings(WebAppContext context) {
|
||||
for (Map.Entry<Locale, Charset> entry : getLocaleCharsetMappings().entrySet()) {
|
||||
Locale locale = entry.getKey();
|
||||
|
||||
@@ -135,4 +135,5 @@ public class SslServerCustomizer implements NettyServerCustomizer {
|
||||
store.load(url.openStream(), password == null ? null : password.toCharArray());
|
||||
return store;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
||||
@@ -386,13 +386,17 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
|
||||
|
||||
private long getSessionTimeoutInMinutes() {
|
||||
Duration sessionTimeout = getSession().getTimeout();
|
||||
if (sessionTimeout == null || sessionTimeout.isNegative()
|
||||
|| sessionTimeout.isZero()) {
|
||||
if (isZeroOrLess(sessionTimeout)) {
|
||||
return 0;
|
||||
}
|
||||
return Math.max(sessionTimeout.toMinutes(), 1);
|
||||
}
|
||||
|
||||
private boolean isZeroOrLess(Duration sessionTimeout) {
|
||||
return sessionTimeout == null || sessionTimeout.isNegative()
|
||||
|| sessionTimeout.isZero();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process the Tomcat {@link Context} before it's used with the Tomcat Server.
|
||||
* Subclasses can override this method to apply additional processing to the
|
||||
|
||||
@@ -283,13 +283,17 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
|
||||
manager.deploy();
|
||||
SessionManager sessionManager = manager.getDeployment().getSessionManager();
|
||||
Duration timeoutDuration = getSession().getTimeout();
|
||||
int sessionTimeout = (timeoutDuration == null || timeoutDuration.isZero()
|
||||
|| timeoutDuration.isNegative() ? -1
|
||||
: (int) timeoutDuration.getSeconds());
|
||||
int sessionTimeout = (isZeroOrLess(timeoutDuration) ? -1
|
||||
: (int) timeoutDuration.getSeconds());
|
||||
sessionManager.setDefaultSessionTimeout(sessionTimeout);
|
||||
return manager;
|
||||
}
|
||||
|
||||
private boolean isZeroOrLess(Duration timeoutDuration) {
|
||||
return timeoutDuration == null || timeoutDuration.isZero()
|
||||
|| timeoutDuration.isNegative();
|
||||
}
|
||||
|
||||
private void configureAccessLog(DeploymentInfo deploymentInfo) {
|
||||
deploymentInfo.addInitialHandlerChainWrapper(this::createAccessLogHandler);
|
||||
}
|
||||
|
||||
@@ -62,31 +62,10 @@ public interface ConfigurableServletWebServerFactory
|
||||
/**
|
||||
* Sets the configuration that will be applied to the container's HTTP session
|
||||
* support.
|
||||
*
|
||||
* @param session the session configuration
|
||||
*/
|
||||
void setSession(Session session);
|
||||
|
||||
// /**
|
||||
// * The session timeout in seconds (default 30 minutes). If {@code null} then
|
||||
// sessions
|
||||
// * never expire.
|
||||
// * @param sessionTimeout the session timeout
|
||||
// */
|
||||
// void setSessionTimeout(Duration sessionTimeout);
|
||||
//
|
||||
// /**
|
||||
// * Sets if session data should be persisted between restarts.
|
||||
// * @param persistSession {@code true} if session data should be persisted
|
||||
// */
|
||||
// void setPersistSession(boolean persistSession);
|
||||
//
|
||||
// /**
|
||||
// * Set the directory used to store serialized session data.
|
||||
// * @param sessionStoreDir the directory or {@code null} to use a default location.
|
||||
// */
|
||||
// void setSessionStoreDir(File sessionStoreDir);
|
||||
|
||||
/**
|
||||
* Set if the DefaultServlet should be registered. Defaults to {@code true} so that
|
||||
* files from the {@link #setDocumentRoot(File) document root} will be served.
|
||||
@@ -141,7 +120,6 @@ public interface ConfigurableServletWebServerFactory
|
||||
/**
|
||||
* Sets the init parameters that are applied to the container's
|
||||
* {@link ServletContext}.
|
||||
*
|
||||
* @param initParameters the init parameters
|
||||
*/
|
||||
void setInitParameters(Map<String, String> initParameters);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
||||
@@ -156,7 +156,6 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
ssl.setKeyStore("classpath:test.jks");
|
||||
ssl.setKeyPassword("password");
|
||||
ssl.setTrustStore("classpath:test.jks");
|
||||
|
||||
testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector());
|
||||
}
|
||||
|
||||
@@ -168,7 +167,6 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
ssl.setKeyStore("classpath:test.jks");
|
||||
ssl.setKeyPassword("password");
|
||||
ssl.setTrustStore("classpath:test.jks");
|
||||
|
||||
testClientAuthSuccess(ssl, buildTrustAllSslConnector());
|
||||
}
|
||||
|
||||
@@ -192,10 +190,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
ReactorClientHttpConnector clientConnector) {
|
||||
AbstractReactiveWebServerFactory factory = getFactory();
|
||||
factory.setSsl(sslConfiguration);
|
||||
|
||||
this.webServer = factory.getWebServer(new EchoHandler());
|
||||
this.webServer.start();
|
||||
|
||||
WebClient client = WebClient.builder()
|
||||
.baseUrl("https://localhost:" + this.webServer.getPort())
|
||||
.clientConnector(clientConnector).build();
|
||||
@@ -213,7 +209,6 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
ssl.setKeyStore("classpath:test.jks");
|
||||
ssl.setKeyPassword("password");
|
||||
ssl.setTrustStore("classpath:test.jks");
|
||||
|
||||
testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector());
|
||||
}
|
||||
|
||||
@@ -228,7 +223,6 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
ssl.setKeyStore("classpath:test.jks");
|
||||
ssl.setKeyPassword("password");
|
||||
ssl.setTrustStore("classpath:test.jks");
|
||||
|
||||
testClientAuthFailure(ssl, buildTrustAllSslConnector());
|
||||
}
|
||||
|
||||
@@ -236,17 +230,14 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
ReactorClientHttpConnector clientConnector) {
|
||||
AbstractReactiveWebServerFactory factory = getFactory();
|
||||
factory.setSsl(sslConfiguration);
|
||||
|
||||
this.webServer = factory.getWebServer(new EchoHandler());
|
||||
this.webServer.start();
|
||||
|
||||
WebClient client = WebClient.builder()
|
||||
.baseUrl("https://localhost:" + this.webServer.getPort())
|
||||
.clientConnector(clientConnector).build();
|
||||
Mono<String> result = client.post().uri("/test").contentType(MediaType.TEXT_PLAIN)
|
||||
.body(BodyInserters.fromObject("Hello World")).exchange()
|
||||
.flatMap((response) -> response.bodyToMono(String.class));
|
||||
|
||||
StepVerifier.create(result).expectError(SSLException.class)
|
||||
.verify(Duration.ofSeconds(10));
|
||||
}
|
||||
@@ -372,6 +363,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
}
|
||||
ctx.fireChannelRead(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class CharsHandler implements HttpHandler {
|
||||
@@ -395,6 +387,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
response.getHeaders().setContentType(this.mediaType);
|
||||
return response.writeWith(Mono.just(this.bytes));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -999,15 +999,6 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
@Test
|
||||
public void sessionConfiguration() {
|
||||
AbstractServletWebServerFactory factory = getFactory();
|
||||
// map.put("server.servlet.session.timeout", "123");
|
||||
// map.put("server.servlet.session.tracking-modes", "cookie,url");
|
||||
// map.put("server.servlet.session.cookie.name", "testname");
|
||||
// map.put("server.servlet.session.cookie.domain", "testdomain");
|
||||
// map.put("server.servlet.session.cookie.path", "/testpath");
|
||||
// map.put("server.servlet.session.cookie.comment", "testcomment");
|
||||
// map.put("server.servlet.session.cookie.http-only", "true");
|
||||
// map.put("server.servlet.session.cookie.secure", "true");
|
||||
// map.put("server.servlet.session.cookie.max-age", "60");
|
||||
factory.getSession().setTimeout(Duration.ofSeconds(123));
|
||||
factory.getSession().setTrackingModes(
|
||||
EnumSet.of(SessionTrackingMode.COOKIE, SessionTrackingMode.URL));
|
||||
@@ -1035,7 +1026,6 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
assertThat(servletContext.getSessionCookieConfig().isHttpOnly()).isTrue();
|
||||
assertThat(servletContext.getSessionCookieConfig().isSecure()).isTrue();
|
||||
assertThat(servletContext.getSessionCookieConfig().getMaxAge()).isEqualTo(60);
|
||||
|
||||
}
|
||||
|
||||
protected abstract void addConnector(int port,
|
||||
|
||||
Reference in New Issue
Block a user