Skip to content

Commit 111086d

Browse files
authored
[java] Schema HTTPS in Distributor, SessionQueue, SessionMap (#13413)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 10af32c commit 111086d

File tree

7 files changed

+19
-5
lines changed

7 files changed

+19
-5
lines changed

java/src/org/openqa/selenium/grid/distributor/config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ java_library(
1313
"//java/src/org/openqa/selenium/grid/data",
1414
"//java/src/org/openqa/selenium/grid/distributor",
1515
"//java/src/org/openqa/selenium/grid/distributor/selector",
16+
"//java/src/org/openqa/selenium/grid/server",
1617
artifact("com.beust:jcommander"),
1718
],
1819
)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
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

@@ -67,6 +68,8 @@ public URI getDistributorUri() {
6768
return host.get();
6869
}
6970

71+
BaseServerOptions serverOptions = new BaseServerOptions(config);
72+
String schema = (serverOptions.isSecure() || serverOptions.isSelfSigned()) ? "https" : "http";
7073
Optional<Integer> port = config.getInt(DISTRIBUTOR_SECTION, "port");
7174
Optional<String> hostname = config.get(DISTRIBUTOR_SECTION, "hostname");
7275

@@ -75,7 +78,7 @@ public URI getDistributorUri() {
7578
}
7679

7780
try {
78-
return new URI("http", null, hostname.get(), port.get(), null, null, null);
81+
return new URI(schema, null, hostname.get(), port.get(), null, null, null);
7982
} catch (URISyntaxException e) {
8083
throw new ConfigException(
8184
"Distributor uri configured through host (%s) and port (%d) is not a valid URI",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public SecretOptions(Config config) {
4141

4242
public Secret getRegistrationSecret() {
4343
String secret = "";
44-
if ((isSecure()) && !config.get(SERVER_SECTION, "registration-secret").isPresent()) {
44+
if ((isSecure() || isSelfSigned())
45+
&& !config.get(SERVER_SECTION, "registration-secret").isPresent()) {
4546
try {
4647
secret =
4748
getEncoder()

java/src/org/openqa/selenium/grid/sessionmap/config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ java_library(
1010
deps = [
1111
"//java:auto-service",
1212
"//java/src/org/openqa/selenium/grid/config",
13+
"//java/src/org/openqa/selenium/grid/server",
1314
"//java/src/org/openqa/selenium/grid/sessionmap",
1415
artifact("com.beust:jcommander"),
1516
],

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
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 {
@@ -30,7 +31,6 @@ public class SessionMapOptions {
3031

3132
private static final String DEFAULT_SESSION_MAP =
3233
"org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap";
33-
private static final String DEFAULT_SESSION_MAP_SCHEME = "http";
3434
private final Config config;
3535

3636
public SessionMapOptions(Config config) {
@@ -39,7 +39,11 @@ public SessionMapOptions(Config config) {
3939

4040
public URI getSessionMapUri() {
4141

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

4448
Optional<URI> host =
4549
config

java/src/org/openqa/selenium/grid/sessionqueue/config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ java_library(
1212
"//java:auto-service",
1313
"//java/src/org/openqa/selenium/grid/config",
1414
"//java/src/org/openqa/selenium/grid/jmx",
15+
"//java/src/org/openqa/selenium/grid/server",
1516
"//java/src/org/openqa/selenium/grid/sessionqueue",
1617
artifact("com.beust:jcommander"),
1718
],

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

Lines changed: 4 additions & 1 deletion
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(
@@ -70,6 +71,8 @@ public URI getSessionQueueUri() {
7071
return host.get();
7172
}
7273

74+
BaseServerOptions serverOptions = new BaseServerOptions(config);
75+
String schema = (serverOptions.isSecure() || serverOptions.isSelfSigned()) ? "https" : "http";
7376
Optional<Integer> port = config.getInt(SESSION_QUEUE_SECTION, "port");
7477
Optional<String> hostname = config.get(SESSION_QUEUE_SECTION, "hostname");
7578

@@ -78,7 +81,7 @@ public URI getSessionQueueUri() {
7881
}
7982

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

0 commit comments

Comments
 (0)