Skip to content

Commit c9d4440

Browse files
committed
[java] Schema HTTPS in Distributor, SessionQueue, SessionMap
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent fffd05c commit c9d4440

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

java/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
import org.openqa.selenium.grid.data.SlotMatcher;
2727
import org.openqa.selenium.grid.distributor.Distributor;
2828
import org.openqa.selenium.grid.distributor.selector.SlotSelector;
29+
import org.openqa.selenium.grid.server.BaseServerOptions;
2930

3031
public class DistributorOptions {
3132

3233
public static final int DEFAULT_HEALTHCHECK_INTERVAL = 120;
3334
public static final String DISTRIBUTOR_SECTION = "distributor";
35+
private static final String SERVER_SECTION = "server";
3436
static final String DEFAULT_DISTRIBUTOR_IMPLEMENTATION =
3537
"org.openqa.selenium.grid.distributor.local.LocalDistributor";
3638
static final String DEFAULT_SLOT_MATCHER = "org.openqa.selenium.grid.data.DefaultSlotMatcher";
@@ -67,6 +69,8 @@ public URI getDistributorUri() {
6769
return host.get();
6870
}
6971

72+
BaseServerOptions serverOptions = new BaseServerOptions(config);
73+
String schema = (serverOptions.isSecure() || serverOptions.isSelfSigned()) ? "https" : "http";
7074
Optional<Integer> port = config.getInt(DISTRIBUTOR_SECTION, "port");
7175
Optional<String> hostname = config.get(DISTRIBUTOR_SECTION, "hostname");
7276

@@ -75,7 +79,7 @@ public URI getDistributorUri() {
7579
}
7680

7781
try {
78-
return new URI("http", null, hostname.get(), port.get(), null, null, null);
82+
return new URI(schema, null, hostname.get(), port.get(), null, null, null);
7983
} catch (URISyntaxException e) {
8084
throw new ConfigException(
8185
"Distributor uri configured through host (%s) and port (%d) is not a valid URI",

java/src/org/openqa/selenium/grid/security/SecretOptions.java

+4-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.openqa.selenium.UsernameAndPassword;
2828
import org.openqa.selenium.grid.config.Config;
2929
import org.openqa.selenium.grid.config.ConfigException;
30+
import org.openqa.selenium.grid.server.BaseServerOptions;
3031

3132
public class SecretOptions {
3233

@@ -41,7 +42,9 @@ public SecretOptions(Config config) {
4142

4243
public Secret getRegistrationSecret() {
4344
String secret = "";
44-
if ((isSecure()) && !config.get(SERVER_SECTION, "registration-secret").isPresent()) {
45+
BaseServerOptions serverOptions = new BaseServerOptions(config);
46+
if ((serverOptions.isSecure() || serverOptions.isSelfSigned())
47+
&& !config.get(SERVER_SECTION, "registration-secret").isPresent()) {
4548
try {
4649
secret =
4750
getEncoder()
@@ -69,15 +72,6 @@ public UsernameAndPassword getServerAuthentication() {
6972
return new UsernameAndPassword(username.get(), password.get());
7073
}
7174

72-
private boolean isSecure() {
73-
return config.get(SERVER_SECTION, "https-private-key").isPresent()
74-
&& config.get(SERVER_SECTION, "https-certificate").isPresent();
75-
}
76-
77-
private boolean isSelfSigned() {
78-
return config.getBool(SERVER_SECTION, "https-self-signed").orElse(false);
79-
}
80-
8175
private File getCertificate() {
8276
String certificatePath = config.get(SERVER_SECTION, "https-certificate").orElse(null);
8377
if (certificatePath != null) {

java/src/org/openqa/selenium/grid/sessionmap/config/SessionMapOptions.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222
import java.util.Optional;
2323
import org.openqa.selenium.grid.config.Config;
2424
import org.openqa.selenium.grid.config.ConfigException;
25+
import org.openqa.selenium.grid.server.BaseServerOptions;
2526
import org.openqa.selenium.grid.sessionmap.SessionMap;
2627

2728
public class SessionMapOptions {
2829

2930
private static final String SESSIONS_SECTION = "sessions";
31+
private static final String SERVER_SECTION = "server";
3032

3133
private static final String DEFAULT_SESSION_MAP =
3234
"org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap";
33-
private static final String DEFAULT_SESSION_MAP_SCHEME = "http";
3435
private final Config config;
3536

3637
public SessionMapOptions(Config config) {
@@ -39,7 +40,11 @@ public SessionMapOptions(Config config) {
3940

4041
public URI getSessionMapUri() {
4142

42-
String scheme = config.get(SESSIONS_SECTION, "scheme").orElse(DEFAULT_SESSION_MAP_SCHEME);
43+
BaseServerOptions serverOptions = new BaseServerOptions(config);
44+
String scheme =
45+
config
46+
.get(SESSIONS_SECTION, "scheme")
47+
.orElse((serverOptions.isSecure() || serverOptions.isSelfSigned()) ? "https" : "http");
4348

4449
Optional<URI> host =
4550
config

java/src/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueOptions.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.openqa.selenium.grid.jmx.JMXHelper;
2727
import org.openqa.selenium.grid.jmx.ManagedAttribute;
2828
import org.openqa.selenium.grid.jmx.ManagedService;
29+
import org.openqa.selenium.grid.server.BaseServerOptions;
2930
import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;
3031

3132
@ManagedService(
@@ -34,6 +35,7 @@
3435
public class NewSessionQueueOptions {
3536

3637
static final String SESSION_QUEUE_SECTION = "sessionqueue";
38+
private static final String SERVER_SECTION = "server";
3739
static final int DEFAULT_REQUEST_TIMEOUT = 300;
3840
static final int DEFAULT_REQUEST_TIMEOUT_PERIOD = 10;
3941
static final int DEFAULT_RETRY_INTERVAL = 15;
@@ -70,6 +72,8 @@ public URI getSessionQueueUri() {
7072
return host.get();
7173
}
7274

75+
BaseServerOptions serverOptions = new BaseServerOptions(config);
76+
String schema = (serverOptions.isSecure() || serverOptions.isSelfSigned()) ? "https" : "http";
7377
Optional<Integer> port = config.getInt(SESSION_QUEUE_SECTION, "port");
7478
Optional<String> hostname = config.get(SESSION_QUEUE_SECTION, "hostname");
7579

@@ -78,7 +82,7 @@ public URI getSessionQueueUri() {
7882
}
7983

8084
try {
81-
return new URI("http", null, hostname.get(), port.get(), "", null, null);
85+
return new URI(schema, null, hostname.get(), port.get(), "", null, null);
8286
} catch (URISyntaxException e) {
8387
throw new ConfigException(
8488
"Session queue server uri configured through host (%s) and port (%d) is not a valid URI",

0 commit comments

Comments
 (0)