Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support both HTTPS and HTTP concurrently, respect session timeout #697

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions server/configs/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ server.port=@@serverPort@@
#server.ssl.key-alias=my_selfsigned
#server.ssl.key-store=/path/to/key-store-file
#server.ssl.key-store-password=pwd
#server.ssl.key-store-type=key-store-type
# Typically either PKCS12 or JKS
#server.ssl.key-store-type=PKCS12
#server.ssl.ciphers=ciphers

# HTTP-only port for servers that need to handle both HTTPS (configure via server.port and server.ssl above) and HTTP
#context.httpPort=8080

context.dataSourceName[0]=jdbc/labkeyDataSource
context.driverClassName[0]=@@jdbcDriverClassName@@
context.url[0]=@@jdbcURL@@
Expand Down Expand Up @@ -84,9 +88,12 @@ mail.smtpUser=@@smtpUser@@

#useLocalBuild#spring.devtools.restart.additional-paths=@@pathToServer@@/build/deploy/modules,@@pathToServer@@/build/deploy/embedded/config

# Make management endpoints accessible with LabKey at ROOT context path
server.servlet.context-path=/actuator
management.endpoints.web.base-path=/
# HTTP session timeout for users - defaults to 30 minutes
#server.servlet.session.timeout=30m

## Make management endpoints accessible with LabKey at ROOT context path
#server.servlet.context-path=/actuator
#management.endpoints.web.base-path=/
#Enable shutdown endpoint
management.endpoint.shutdown.enabled=true
# turn off other endpoints
Expand Down
33 changes: 32 additions & 1 deletion server/embedded/src/org/labkey/embedded/LabKeyServer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.labkey.embedded;

import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.startup.Tomcat;
Expand All @@ -17,6 +18,7 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -111,7 +113,7 @@ public JsonAccessLog jsonAccessLog()
@Bean
public TomcatServletWebServerFactory servletContainerFactory()
{
return new TomcatServletWebServerFactory()
var result = new TomcatServletWebServerFactory()
{
@Override
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat)
Expand Down Expand Up @@ -145,9 +147,15 @@ protected TomcatWebServer getTomcatWebServer(Tomcat tomcat)
webAppLocation = contextProperties.getWebAppLocation();
}

tomcat.setAddDefaultWebXmlToWebapp(false);

// tomcat requires a unique context path other than root here
// can not set context path as "" because em tomcat complains "Child name [] is not unique"
StandardContext context = (StandardContext) tomcat.addWebapp("/labkey", webAppLocation);

// Propagate standard Spring Boot properties such as the session timeout
configureContext(context, new ServletContextInitializer[0]);

CSPFilterProperties cspFilterProperties = cspSource();

if (cspFilterProperties.getEnforce() != null)
Expand Down Expand Up @@ -443,6 +451,18 @@ private ContextResource getMailResource()
return mailResource;
}
};

var contextProperties = contextSource();

if (contextProperties.getHttpPort() != null)
{
Connector httpConnector = new Connector();
httpConnector.setScheme("http");
httpConnector.setPort(contextProperties.getHttpPort());
result.addAdditionalTomcatConnectors(httpConnector);
}

return result;
}

private static void extractExecutableJar(String destDirectory, String jarFilePath)
Expand Down Expand Up @@ -668,6 +688,7 @@ public static class ContextProperties
private String requiredModules;
private boolean bypass2FA = false;
private String serverGUID;
private Integer httpRedirectorPort;
private Map<Integer, String> maxTotal;
private Map<Integer, String> maxIdle;
private Map<Integer, String> maxWaitMillis;
Expand Down Expand Up @@ -816,6 +837,16 @@ public void setBypass2FA(boolean bypass2FA)
this.bypass2FA = bypass2FA;
}

public Integer getHttpPort()
{
return httpRedirectorPort;
}

public void setHttpRedirectorPort(Integer httpRedirectorPort)
{
this.httpRedirectorPort = httpRedirectorPort;
}

public String getServerGUID()
{
return serverGUID;
Expand Down