How to use RequiresSecretFilter class of org.openqa.selenium.grid.security package

Best Selenium code snippet using org.openqa.selenium.grid.security.RequiresSecretFilter

Source:Node.java Github

copy

Full Screen

...21import org.openqa.selenium.grid.data.CreateSessionResponse;22import org.openqa.selenium.grid.data.NodeId;23import org.openqa.selenium.grid.data.NodeStatus;24import org.openqa.selenium.grid.data.Session;25import org.openqa.selenium.grid.security.RequiresSecretFilter;26import org.openqa.selenium.grid.security.Secret;27import org.openqa.selenium.internal.Require;28import org.openqa.selenium.io.TemporaryFilesystem;29import org.openqa.selenium.json.Json;30import org.openqa.selenium.remote.SessionId;31import org.openqa.selenium.remote.http.HttpRequest;32import org.openqa.selenium.remote.http.HttpResponse;33import org.openqa.selenium.remote.http.Routable;34import org.openqa.selenium.remote.http.Route;35import org.openqa.selenium.remote.tracing.SpanDecorator;36import org.openqa.selenium.remote.tracing.Tracer;37import org.openqa.selenium.status.HasReadyState;38import java.io.IOException;39import java.net.URI;40import java.util.Map;41import java.util.Optional;42import static org.openqa.selenium.remote.HttpSessionId.getSessionId;43import static org.openqa.selenium.remote.http.Contents.asJson;44import static org.openqa.selenium.remote.http.Route.combine;45import static org.openqa.selenium.remote.http.Route.delete;46import static org.openqa.selenium.remote.http.Route.get;47import static org.openqa.selenium.remote.http.Route.matching;48import static org.openqa.selenium.remote.http.Route.post;49/**50 * A place where individual webdriver sessions are running. Those sessions may be in-memory, or51 * only reachable via localhost and a network. Or they could be something else entirely.52 * <p>53 * This class responds to the following URLs:54 * <table summary="HTTP commands the Node understands">55 * <tr>56 * <th>Verb</th>57 * <th>URL Template</th>58 * <th>Meaning</th>59 * </tr>60 * <tr>61 * <td>POST</td>62 * <td>/se/grid/node/session</td>63 * <td>Attempts to start a new session for the given node. The posted data should be a64 * json-serialized {@link Capabilities} instance. Returns a serialized {@link Session}.65 * Subclasses of {@code Node} are expected to register the session with the66 * {@link org.openqa.selenium.grid.sessionmap.SessionMap}.</td>67 * </tr>68 * <tr>69 * <td>GET</td>70 * <td>/se/grid/node/session/{sessionId}</td>71 * <td>Finds the {@link Session} identified by {@code sessionId} and returns the JSON-serialized72 * form.</td>73 * </tr>74 * <tr>75 * <td>DELETE</td>76 * <td>/se/grid/node/session/{sessionId}</td>77 * <td>Stops the {@link Session} identified by {@code sessionId}. It is expected that this will78 * also cause the session to removed from the79 * {@link org.openqa.selenium.grid.sessionmap.SessionMap}.</td>80 * </tr>81 * <tr>82 * <td>GET</td>83 * <td>/se/grid/node/owner/{sessionId}</td>84 * <td>Allows the node to be queried about whether or not it owns the {@link Session} identified85 * by {@code sessionId}. This returns a boolean.</td>86 * </tr>87 * <tr>88 * <td>*</td>89 * <td>/session/{sessionId}/*</td>90 * <td>The request is forwarded to the {@link Session} identified by {@code sessionId}. When the91 * Quit command is called, the {@link Session} should remove itself from the92 * {@link org.openqa.selenium.grid.sessionmap.SessionMap}.</td>93 * </tr>94 * </table>95 */96public abstract class Node implements HasReadyState, Routable {97 protected final Tracer tracer;98 private final NodeId id;99 private final URI uri;100 private final Route routes;101 protected boolean draining;102 protected Node(Tracer tracer, NodeId id, URI uri, Secret registrationSecret) {103 this.tracer = Require.nonNull("Tracer", tracer);104 this.id = Require.nonNull("Node id", id);105 this.uri = Require.nonNull("URI", uri);106 Require.nonNull("Registration secret", registrationSecret);107 RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret);108 Json json = new Json();109 routes = combine(110 // "getSessionId" is aggressive about finding session ids, so this needs to be the last111 // route that is checked.112 matching(req -> getSessionId(req.getUri()).map(SessionId::new).map(this::isSessionOwner).orElse(false))113 .to(() -> new ForwardWebDriverCommand(this))114 .with(spanDecorator("node.forward_command")),115 post("/session/{sessionId}/file")116 .to(params -> new UploadFile(this, sessionIdFrom(params)))117 .with(spanDecorator("node.upload_file")),118 post("/session/{sessionId}/se/file")119 .to(params -> new UploadFile(this, sessionIdFrom(params)))120 .with(spanDecorator("node.upload_file")),121 get("/se/grid/node/owner/{sessionId}")...

Full Screen

Full Screen

Source:NewSessionQueuer.java Github

copy

Full Screen

...17package org.openqa.selenium.grid.sessionqueue;18import org.openqa.selenium.Capabilities;19import org.openqa.selenium.SessionNotCreatedException;20import org.openqa.selenium.grid.data.RequestId;21import org.openqa.selenium.grid.security.RequiresSecretFilter;22import org.openqa.selenium.grid.security.Secret;23import org.openqa.selenium.internal.Require;24import org.openqa.selenium.remote.NewSessionPayload;25import org.openqa.selenium.remote.http.HttpRequest;26import org.openqa.selenium.remote.http.HttpResponse;27import org.openqa.selenium.remote.http.Routable;28import org.openqa.selenium.remote.http.Route;29import org.openqa.selenium.remote.tracing.AttributeKey;30import org.openqa.selenium.remote.tracing.EventAttribute;31import org.openqa.selenium.remote.tracing.EventAttributeValue;32import org.openqa.selenium.remote.tracing.Span;33import org.openqa.selenium.remote.tracing.Tracer;34import org.openqa.selenium.status.HasReadyState;35import java.io.IOException;36import java.io.Reader;37import java.util.HashMap;38import java.util.Iterator;39import java.util.List;40import java.util.Map;41import java.util.Objects;42import java.util.Optional;43import java.util.UUID;44import static org.openqa.selenium.remote.http.Contents.reader;45import static org.openqa.selenium.remote.http.Route.combine;46import static org.openqa.selenium.remote.http.Route.delete;47import static org.openqa.selenium.remote.http.Route.get;48import static org.openqa.selenium.remote.http.Route.post;49import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;50public abstract class NewSessionQueuer implements HasReadyState, Routable {51 protected final Tracer tracer;52 private final Route routes;53 protected NewSessionQueuer(Tracer tracer, Secret registrationSecret) {54 this.tracer = Require.nonNull("Tracer", tracer);55 Require.nonNull("Registration secret", registrationSecret);56 RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret);57 routes = combine(58 post("/session")59 .to(() -> this::addToQueue),60 post("/se/grid/newsessionqueuer/session")61 .to(() -> new AddToSessionQueue(tracer, this)),62 post("/se/grid/newsessionqueuer/session/retry/{requestId}")63 .to(params -> new AddBackToSessionQueue(tracer, this, requestIdFrom(params)))64 .with(requiresSecret),65 get("/se/grid/newsessionqueuer/session/{requestId}")66 .to(params -> new RemoveFromSessionQueue(tracer, this, requestIdFrom(params)))67 .with(requiresSecret),68 get("/se/grid/newsessionqueuer/queue")69 .to(() -> new GetSessionQueue(tracer, this)),70 delete("/se/grid/newsessionqueuer/queue")...

Full Screen

Full Screen

Source:Distributor.java Github

copy

Full Screen

...21import org.openqa.selenium.grid.data.NodeId;22import org.openqa.selenium.grid.data.Session;23import org.openqa.selenium.grid.data.SessionRequest;24import org.openqa.selenium.grid.node.Node;25import org.openqa.selenium.grid.security.RequiresSecretFilter;26import org.openqa.selenium.grid.security.Secret;27import org.openqa.selenium.internal.Either;28import org.openqa.selenium.internal.Require;29import org.openqa.selenium.json.Json;30import org.openqa.selenium.remote.http.HttpClient;31import org.openqa.selenium.remote.http.HttpRequest;32import org.openqa.selenium.remote.http.HttpResponse;33import org.openqa.selenium.remote.http.Routable;34import org.openqa.selenium.remote.http.Route;35import org.openqa.selenium.remote.tracing.SpanDecorator;36import org.openqa.selenium.remote.tracing.Tracer;37import org.openqa.selenium.status.HasReadyState;38import java.io.UncheckedIOException;39import java.util.Map;40import java.util.UUID;41import java.util.function.Predicate;42import static org.openqa.selenium.remote.http.Route.delete;43import static org.openqa.selenium.remote.http.Route.get;44import static org.openqa.selenium.remote.http.Route.post;45/**46 * Responsible for being the central place where the {@link Node}s47 * on which {@link Session}s run48 * are determined.49 * <p>50 * This class responds to the following URLs:51 * <table summary="HTTP commands the Distributor understands">52 * <tr>53 * <th>Verb</th>54 * <th>URL Template</th>55 * <th>Meaning</th>56 * </tr>57 * <tr>58 * <td>POST</td>59 * <td>/session</td>60 * <td>This is exactly the same as the New Session command61 * from the WebDriver spec.</td>62 * </tr>63 * <tr>64 * <td>POST</td>65 * <td>/se/grid/distributor/node</td>66 * <td>Adds a new {@link Node} to this distributor.67 * Please read the javadocs for {@link Node} for68 * how the Node should be serialized.</td>69 * </tr>70 * <tr>71 * <td>DELETE</td>72 * <td>/se/grid/distributor/node/{nodeId}</td>73 * <td>Remove the {@link Node} identified by {@code nodeId}74 * from this distributor. It is expected75 * that any sessions running on the Node are allowed to complete:76 * this simply means that no new77 * sessions will be scheduled on this Node.</td>78 * </tr>79 * </table>80 */81public abstract class Distributor implements HasReadyState, Predicate<HttpRequest>, Routable {82 private final Route routes;83 protected final Tracer tracer;84 protected Distributor(85 Tracer tracer,86 HttpClient.Factory httpClientFactory,87 Secret registrationSecret) {88 this.tracer = Require.nonNull("Tracer", tracer);89 Require.nonNull("HTTP client factory", httpClientFactory);90 Require.nonNull("Registration secret", registrationSecret);91 RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret);92 Json json = new Json();93 routes = Route.combine(94 post("/se/grid/distributor/node")95 .to(() ->96 new AddNode(tracer, this, json, httpClientFactory, registrationSecret))97 .with(requiresSecret),98 post("/se/grid/distributor/node/{nodeId}/drain")99 .to((Map<String, String> params) ->100 new DrainNode(this, new NodeId(UUID.fromString(params.get("nodeId")))))101 .with(requiresSecret),102 delete("/se/grid/distributor/node/{nodeId}")103 .to(params ->104 new RemoveNode(this, new NodeId(UUID.fromString(params.get("nodeId")))))105 .with(requiresSecret),...

Full Screen

Full Screen

Source:NewSessionQueue.java Github

copy

Full Screen

...20import org.openqa.selenium.grid.data.CreateSessionResponse;21import org.openqa.selenium.grid.data.RequestId;22import org.openqa.selenium.grid.data.SessionRequest;23import org.openqa.selenium.grid.data.SessionRequestCapability;24import org.openqa.selenium.grid.security.RequiresSecretFilter;25import org.openqa.selenium.grid.security.Secret;26import org.openqa.selenium.internal.Either;27import org.openqa.selenium.internal.Require;28import org.openqa.selenium.remote.http.HttpRequest;29import org.openqa.selenium.remote.http.HttpResponse;30import org.openqa.selenium.remote.http.Routable;31import org.openqa.selenium.remote.http.Route;32import org.openqa.selenium.remote.tracing.Tracer;33import org.openqa.selenium.status.HasReadyState;34import java.time.Instant;35import java.util.List;36import java.util.Map;37import java.util.Optional;38import java.util.Set;39import java.util.UUID;40import static org.openqa.selenium.remote.http.Route.combine;41import static org.openqa.selenium.remote.http.Route.delete;42import static org.openqa.selenium.remote.http.Route.get;43import static org.openqa.selenium.remote.http.Route.post;44public abstract class NewSessionQueue implements HasReadyState, Routable {45 protected final Tracer tracer;46 private final Route routes;47 protected NewSessionQueue(Tracer tracer, Secret registrationSecret) {48 this.tracer = Require.nonNull("Tracer", tracer);49 Require.nonNull("Registration secret", registrationSecret);50 RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret);51 routes = combine(52 post("/session")53 .to(() -> req -> {54 SessionRequest sessionRequest = new SessionRequest(55 new RequestId(UUID.randomUUID()),56 req,57 Instant.now()58 );59 return addToQueue(sessionRequest);60 }),61 post("/se/grid/newsessionqueue/session")62 .to(() -> new AddToSessionQueue(tracer, this))63 .with(requiresSecret),64 post("/se/grid/newsessionqueue/session/{requestId}/retry")...

Full Screen

Full Screen

Source:RequiresSecretFilter.java Github

copy

Full Screen

...24import java.util.Objects;25import java.util.logging.Logger;26import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;27import static org.openqa.selenium.grid.security.AddSecretFilter.HEADER_NAME;28public class RequiresSecretFilter implements Filter {29 private static final Logger LOG = Logger.getLogger(RequiresSecretFilter.class.getName());30 private final Secret secret;31 public RequiresSecretFilter(Secret secret) {32 this.secret = secret;33 }34 @Override35 public HttpHandler apply(HttpHandler httpHandler) {36 Require.nonNull("HTTP handler", httpHandler);37 return req -> {38 if (!isSecretMatch(secret, req)) {39 return new HttpResponse()40 .setStatus(HTTP_UNAUTHORIZED)41 .addHeader("Content-Type", "text/plain; charset=UTF-8")42 .setContent(Contents.utf8String("Unauthorized access attempted to " + req.getUri()));43 }44 return httpHandler.execute(req);45 };...

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in RequiresSecretFilter

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful