mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-27 05:52:37 +02:00
Fix webserver 'proxy'-mode with Jetty
This commit is contained in:
parent
7a69c895ee
commit
58cd2d6a8f
@ -107,4 +107,8 @@ public class WebserverConfiguration {
|
|||||||
public String getAlias() {
|
public String getAlias() {
|
||||||
return config.get(WebserverSettings.CERTIFICATE_ALIAS);
|
return config.get(WebserverSettings.CERTIFICATE_ALIAS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProxyModeHttps() {
|
||||||
|
return "proxy".equals(config.get(WebserverSettings.CERTIFICATE_PATH));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,11 @@ public class JettyWebserver implements WebServer {
|
|||||||
return new ServerConnector(webserver, sslContextFactory, alpn, httpConnector, http2Connector, http2CConnector);
|
return new ServerConnector(webserver, sslContextFactory, alpn, httpConnector, http2Connector, http2CConnector);
|
||||||
})
|
})
|
||||||
.orElseGet(() -> {
|
.orElseGet(() -> {
|
||||||
webserverLogMessages.authenticationNotPossible();
|
if (webserverConfiguration.isProxyModeHttps()) {
|
||||||
|
webserverLogMessages.authenticationUsingProxy();
|
||||||
|
} else {
|
||||||
|
webserverLogMessages.authenticationNotPossible();
|
||||||
|
}
|
||||||
return new ServerConnector(webserver, httpConnector, http2CConnector);
|
return new ServerConnector(webserver, httpConnector, http2CConnector);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -146,12 +150,11 @@ public class JettyWebserver implements WebServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Optional<SslContextFactory.Server> getSslContextFactory() {
|
private Optional<SslContextFactory.Server> getSslContextFactory() {
|
||||||
String keyStorePath = webserverConfiguration.getKeyStorePath();
|
if (webserverConfiguration.isProxyModeHttps()) {
|
||||||
if ("proxy".equals(keyStorePath)) {
|
|
||||||
webserverLogMessages.authenticationUsingProxy();
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String keyStorePath = webserverConfiguration.getKeyStorePath();
|
||||||
if (!new File(keyStorePath).exists()) {
|
if (!new File(keyStorePath).exists()) {
|
||||||
webserverLogMessages.keystoreFileNotFound();
|
webserverLogMessages.keystoreFileNotFound();
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@ -207,7 +210,7 @@ public class JettyWebserver implements WebServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUsingHTTPS() {
|
public boolean isUsingHTTPS() {
|
||||||
return usingHttps;
|
return usingHttps || webserverConfiguration.isProxyModeHttps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.delivery.webserver;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanSystem;
|
||||||
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
|
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import utilities.RandomData;
|
||||||
|
import utilities.mocks.PluginMockComponent;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class ProxyModeHttpsTest {
|
||||||
|
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||||
|
|
||||||
|
private static PlanSystem system;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void setUpClass(@TempDir Path tempDir) throws Exception {
|
||||||
|
PluginMockComponent component = new PluginMockComponent(tempDir);
|
||||||
|
system = component.getPlanSystem();
|
||||||
|
|
||||||
|
PlanConfig config = system.getConfigSystem().getConfig();
|
||||||
|
|
||||||
|
config.set(WebserverSettings.CERTIFICATE_PATH, "proxy");
|
||||||
|
|
||||||
|
config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
|
||||||
|
|
||||||
|
system.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void tearDownClass() {
|
||||||
|
if (system != null) {
|
||||||
|
system.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Webserver with 'proxy' keystore path assumes proxy server is handling https")
|
||||||
|
void proxyModeAddressIsHttps() {
|
||||||
|
assertEquals("https", system.getWebServerSystem().getWebServer().getProtocol());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user