Skip to content

Commit

Permalink
added https support
Browse files Browse the repository at this point in the history
  • Loading branch information
asishupadhyay committed Feb 3, 2025
1 parent 36b3dd2 commit 8eb2fca
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@
public class HttpConfig implements Serializable {

private boolean enabled = ServerConfigOptions.ENABLE_HTTP.defaultValue();

private int port = ServerConfigOptions.PORT.defaultValue();

private String contextPath = ServerConfigOptions.CONTEXT_PATH.defaultValue();

private boolean enableDynamicPort = ServerConfigOptions.ENABLE_DYNAMIC_PORT.defaultValue();

private int portRange = ServerConfigOptions.PORT_RANGE.defaultValue();

// HTTPS configuration
private int httpsPort = ServerConfigOptions.HTTPS_PORT.defaultValue();
private boolean enableHttps = ServerConfigOptions.ENABLE_HTTPS.defaultValue();

private String keystore = ServerConfigOptions.KEYSTORE.defaultValue();
private String keystorePassword = ServerConfigOptions.KEYSTORE_PASSWORD.defaultValue();
private String keyPassword = ServerConfigOptions.KEY_PASSWORD.defaultValue();
private String truststore = ServerConfigOptions.TRUSTSTORE.defaultValue();
private String truststorePassword = ServerConfigOptions.TRUSTSTORE_PASSWORD.defaultValue();
private boolean requireClientAuth = ServerConfigOptions.REQUIRE_CLIENT_AUTH.defaultValue();

public void setPort(int port) {
checkPositive(port, ServerConfigOptions.HTTP + " must be > 0");
this.port = port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,62 @@ public class ServerConfigOptions {
.defaultValue(new HttpConfig())
.withDescription("The http configuration.");

// New HTTPS configurations
public static final Option<Integer> HTTPS_PORT =
Options.key("https-port")
.intType()
.defaultValue(8443)
.withDescription("The port used for HTTPS communication.");

public static final Option<Boolean> ENABLE_HTTPS =
Options.key("enable-https")
.booleanType()
.defaultValue(false)
.withDescription("Whether to enable HTTPS.");

public static final Option<String> KEYSTORE =
Options.key("keystore")
.stringType()
.defaultValue("")
.withDescription("The file path of the keystore for HTTPS.");

public static final Option<String> KEYSTORE_PASSWORD =
Options.key("keystore-password")
.stringType()
.defaultValue("")
.withDescription("The password for the keystore.");

public static final Option<String> KEY_PASSWORD =
Options.key("key-password")
.stringType()
.defaultValue("")
.withDescription("The password for the key in the keystore.");

public static final Option<Boolean> REQUIRE_CLIENT_AUTH =
Options.key("require-client-auth")
.booleanType()
.defaultValue(false)
.withDescription(
"Whether to require client authentication for HTTPS connections.");

public static final Option<String> KEY_MANAGER_PASSWORD =
Options.key("key-manager-password")
.stringType()
.defaultValue("")
.withDescription("The password for the key manager.");

public static final Option<String> TRUSTSTORE =
Options.key("truststore")
.stringType()
.defaultValue("")
.withDescription("The file path of the truststore for HTTPS.");

public static final Option<String> TRUSTSTORE_PASSWORD =
Options.key("truststore-password")
.stringType()
.defaultValue("")
.withDescription("The password for the truststore.");

public static final String EVENT_REPORT_HTTP = "event-report-http";
public static final String EVENT_REPORT_HTTP_URL = "url";
public static final String EVENT_REPORT_HTTP_HEADERS = "headers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
package org.apache.seatunnel.engine.server;

import org.apache.seatunnel.shade.org.eclipse.jetty.server.Server;
import org.apache.seatunnel.shade.org.eclipse.jetty.server.ServerConnector;
import org.apache.seatunnel.shade.org.eclipse.jetty.servlet.DefaultServlet;
import org.apache.seatunnel.shade.org.eclipse.jetty.servlet.FilterHolder;
import org.apache.seatunnel.shade.org.eclipse.jetty.servlet.ServletContextHandler;
import org.apache.seatunnel.shade.org.eclipse.jetty.servlet.ServletHolder;
import org.apache.seatunnel.shade.org.eclipse.jetty.util.ssl.SslContextFactory;

import org.apache.seatunnel.engine.common.config.SeaTunnelConfig;
import org.apache.seatunnel.engine.server.rest.filter.ExceptionHandlingFilter;
Expand Down Expand Up @@ -50,6 +52,7 @@
import javax.servlet.DispatcherType;
import javax.servlet.MultipartConfigElement;

import java.io.File;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.ServerSocket;
Expand Down Expand Up @@ -88,18 +91,58 @@ public class JettyService {
public JettyService(NodeEngineImpl nodeEngine, SeaTunnelConfig seaTunnelConfig) {
this.nodeEngine = nodeEngine;
this.seaTunnelConfig = seaTunnelConfig;

// Determine if HTTPS is enabled based on your new YAML properties.
boolean enableHttps = seaTunnelConfig.getEngineConfig().getHttpConfig().isEnableHttps();
int port = seaTunnelConfig.getEngineConfig().getHttpConfig().getPort();
if (seaTunnelConfig.getEngineConfig().getHttpConfig().isEnableDynamicPort()) {
port =
chooseAppropriatePort(
port, seaTunnelConfig.getEngineConfig().getHttpConfig().getPortRange());
}
log.info("SeaTunnel REST service will start on port {}", port);
log.info("SeaTunnel REST service will start on HTTP port {}", port);
this.server = new Server(port);

// Add HTTPS connector if enabled.
if (enableHttps) {
// Use the new property names from your YAML.
String keystore = seaTunnelConfig.getEngineConfig().getHttpConfig().getKeystore();
String keystorePassword =
seaTunnelConfig.getEngineConfig().getHttpConfig().getKeystorePassword();
String keyPassword = seaTunnelConfig.getEngineConfig().getHttpConfig().getKeyPassword();
String truststore = seaTunnelConfig.getEngineConfig().getHttpConfig().getTruststore();
String truststorePassword =
seaTunnelConfig.getEngineConfig().getHttpConfig().getTruststorePassword();

File keystoreFile = new File(keystore);
if (keystoreFile.exists() && keystoreFile.isFile()) {
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
sslContextFactory.setKeyStorePath(keystore);
sslContextFactory.setKeyStorePassword(keystorePassword);
sslContextFactory.setKeyManagerPassword(keyPassword);

// Optionally enable two-way SSL if truststore values are provided.
if (truststore != null
&& !truststore.isEmpty()
&& truststorePassword != null
&& !truststorePassword.isEmpty()) {
sslContextFactory.setNeedClientAuth(true);
sslContextFactory.setTrustStorePath(truststore);
sslContextFactory.setTrustStorePassword(truststorePassword);
}

int httpsPort = seaTunnelConfig.getEngineConfig().getHttpConfig().getHttpsPort();
ServerConnector httpsConnector = new ServerConnector(server, sslContextFactory);
httpsConnector.setPort(httpsPort);
server.addConnector(httpsConnector);
log.info("HTTPS enabled on port {}", httpsPort);
} else {
log.warn("Keystore file not found at '{}'. HTTPS will not be enabled.", keystore);
}
}
}

public void createJettyServer() {

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath(seaTunnelConfig.getEngineConfig().getHttpConfig().getContextPath());

Expand Down

0 comments on commit 8eb2fca

Please sign in to comment.