27
27
import org .openqa .selenium .grid .config .Config ;
28
28
import org .openqa .selenium .grid .data .RequestId ;
29
29
import org .openqa .selenium .grid .log .LoggingOptions ;
30
+ import org .openqa .selenium .grid .security .AddSecretFilter ;
31
+ import org .openqa .selenium .grid .security .Secret ;
32
+ import org .openqa .selenium .grid .security .SecretOptions ;
30
33
import org .openqa .selenium .grid .server .NetworkOptions ;
31
34
import org .openqa .selenium .grid .sessionqueue .NewSessionQueuer ;
32
35
import org .openqa .selenium .grid .sessionqueue .config .NewSessionQueuerOptions ;
33
36
import org .openqa .selenium .grid .web .Values ;
34
37
import org .openqa .selenium .internal .Require ;
38
+ import org .openqa .selenium .remote .http .Filter ;
35
39
import org .openqa .selenium .remote .http .HttpClient ;
36
40
import org .openqa .selenium .remote .http .HttpRequest ;
37
41
import org .openqa .selenium .remote .http .HttpResponse ;
@@ -50,19 +54,29 @@ public class RemoteNewSessionQueuer extends NewSessionQueuer {
50
54
private final HttpClient client ;
51
55
private static final String timestampHeader = SESSIONREQUEST_TIMESTAMP_HEADER ;
52
56
private static final String reqIdHeader = SESSIONREQUEST_ID_HEADER ;
57
+ private final Filter addSecret ;
53
58
54
- public RemoteNewSessionQueuer (Tracer tracer , HttpClient client ) {
55
- super (tracer );
59
+ public RemoteNewSessionQueuer (Tracer tracer , HttpClient client , Secret registrationSecret ) {
60
+ super (tracer , registrationSecret );
56
61
this .client = Require .nonNull ("HTTP client" , client );
62
+
63
+ Require .nonNull ("Registration secret" , registrationSecret );
64
+ this .addSecret = new AddSecretFilter (registrationSecret );
57
65
}
58
66
59
67
public static NewSessionQueuer create (Config config ) {
60
68
Tracer tracer = new LoggingOptions (config ).getTracer ();
61
69
URI uri = new NewSessionQueuerOptions (config ).getSessionQueuerUri ();
62
70
HttpClient .Factory clientFactory = new NetworkOptions (config ).getHttpClientFactory (tracer );
63
71
72
+ SecretOptions secretOptions = new SecretOptions (config );
73
+ Secret registrationSecret = secretOptions .getRegistrationSecret ();
74
+
64
75
try {
65
- return new RemoteNewSessionQueuer (tracer , clientFactory .createClient (uri .toURL ()));
76
+ return new RemoteNewSessionQueuer (
77
+ tracer ,
78
+ clientFactory .createClient (uri .toURL ()),
79
+ registrationSecret );
66
80
} catch (MalformedURLException e ) {
67
81
throw new UncheckedIOException (e );
68
82
}
@@ -84,7 +98,7 @@ public boolean retryAddToQueue(HttpRequest request, RequestId reqId) {
84
98
upstream .setContent (request .getContent ());
85
99
upstream .setHeader (timestampHeader , request .getHeader (timestampHeader ));
86
100
upstream .setHeader (reqIdHeader , reqId .toString ());
87
- HttpResponse response = client .execute (upstream );
101
+ HttpResponse response = client .with ( addSecret ). execute (upstream );
88
102
return Values .get (response , Boolean .class );
89
103
}
90
104
@@ -93,7 +107,7 @@ public Optional<HttpRequest> remove(RequestId reqId) {
93
107
HttpRequest upstream =
94
108
new HttpRequest (GET , "/se/grid/newsessionqueuer/session/" + reqId .toString ());
95
109
HttpTracing .inject (tracer , tracer .getCurrentContext (), upstream );
96
- HttpResponse response = client .execute (upstream );
110
+ HttpResponse response = client .with ( addSecret ). execute (upstream );
97
111
98
112
if (response .getStatus ()==HTTP_OK ) {
99
113
HttpRequest httpRequest = new HttpRequest (POST , "/session" );
@@ -110,7 +124,7 @@ public Optional<HttpRequest> remove(RequestId reqId) {
110
124
public int clearQueue () {
111
125
HttpRequest upstream = new HttpRequest (DELETE , "/se/grid/newsessionqueuer/queue" );
112
126
HttpTracing .inject (tracer , tracer .getCurrentContext (), upstream );
113
- HttpResponse response = client .execute (upstream );
127
+ HttpResponse response = client .with ( addSecret ). execute (upstream );
114
128
115
129
return Values .get (response , Integer .class );
116
130
}
0 commit comments