|
31 | 31 | import org.openqa.selenium.grid.distributor.model.Host; |
32 | 32 | import org.openqa.selenium.grid.distributor.selector.SlotSelector; |
33 | 33 | import org.openqa.selenium.grid.node.Node; |
| 34 | +import org.openqa.selenium.grid.security.RequiresSecretFilter; |
34 | 35 | import org.openqa.selenium.grid.sessionmap.SessionMap; |
35 | 36 | import org.openqa.selenium.internal.Require; |
36 | 37 | import org.openqa.selenium.json.Json; |
@@ -129,26 +130,33 @@ protected Distributor( |
129 | 130 | Tracer tracer, |
130 | 131 | HttpClient.Factory httpClientFactory, |
131 | 132 | SlotSelector slotSelector, |
132 | | - SessionMap sessions) { |
| 133 | + SessionMap sessions, |
| 134 | + String registrationSecret) { |
133 | 135 | this.tracer = Require.nonNull("Tracer", tracer); |
134 | 136 | Require.nonNull("HTTP client factory", httpClientFactory); |
135 | 137 | this.slotSelector = Require.nonNull("Host selector", slotSelector); |
136 | 138 | this.sessions = Require.nonNull("Session map", sessions); |
137 | 139 |
|
| 140 | + RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret); |
| 141 | + |
138 | 142 | Json json = new Json(); |
139 | 143 | routes = Route.combine( |
140 | 144 | post("/session").to(() -> req -> { |
141 | 145 | CreateSessionResponse sessionResponse = newSession(req); |
142 | 146 | return new HttpResponse().setContent(bytes(sessionResponse.getDownstreamEncodedResponse())); |
143 | 147 | }), |
144 | 148 | post("/se/grid/distributor/session") |
145 | | - .to(() -> new CreateSession(this)), |
| 149 | + .to(() -> new CreateSession(this)) |
| 150 | + .with(requiresSecret), |
146 | 151 | post("/se/grid/distributor/node") |
147 | | - .to(() -> new AddNode(tracer, this, json, httpClientFactory)), |
| 152 | + .to(() -> new AddNode(tracer, this, json, httpClientFactory, registrationSecret)) |
| 153 | + .with(requiresSecret), |
148 | 154 | post("/se/grid/distributor/node/{nodeId}/drain") |
149 | | - .to((Map<String, String> params) -> new DrainNode(this, new NodeId(UUID.fromString(params.get("nodeId"))))), |
| 155 | + .to((Map<String, String> params) -> new DrainNode(this, new NodeId(UUID.fromString(params.get("nodeId"))))) |
| 156 | + .with(requiresSecret), |
150 | 157 | delete("/se/grid/distributor/node/{nodeId}") |
151 | | - .to(params -> new RemoveNode(this, new NodeId(UUID.fromString(params.get("nodeId"))))), |
| 158 | + .to(params -> new RemoveNode(this, new NodeId(UUID.fromString(params.get("nodeId"))))) |
| 159 | + .with(requiresSecret), |
152 | 160 | get("/se/grid/distributor/status") |
153 | 161 | .to(() -> new GetDistributorStatus(this)) |
154 | 162 | .with(new SpanDecorator(tracer, req -> "distributor.status"))); |
@@ -289,6 +297,4 @@ public boolean matches(HttpRequest req) { |
289 | 297 | public HttpResponse execute(HttpRequest req) throws UncheckedIOException { |
290 | 298 | return routes.execute(req); |
291 | 299 | } |
292 | | - |
293 | | - public abstract String getRegistrationSecret(); |
294 | 300 | } |
0 commit comments