All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openqa.selenium.devtools.v90.fetch.model.AuthChallengeResponse Maven / Gradle / Ivy

Go to download

Selenium automates browsers. That's it! What you do with that power is entirely up to you.

There is a newer version: 4.0.0-beta-4
Show newest version
package org.openqa.selenium.devtools.v90.fetch.model;

import org.openqa.selenium.Beta;
import org.openqa.selenium.json.JsonInput;

/**
 * Response to an AuthChallenge.
 */
public class AuthChallengeResponse {

    public enum Response {

        DEFAULT("Default"), CANCELAUTH("CancelAuth"), PROVIDECREDENTIALS("ProvideCredentials");

        private String value;

        Response(String value) {
            this.value = value;
        }

        public static Response fromString(String s) {
            return java.util.Arrays.stream(Response.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within Response "));
        }

        public String toString() {
            return value;
        }

        public String toJson() {
            return value;
        }

        private static Response fromJson(JsonInput input) {
            return fromString(input.nextString());
        }
    }

    private final Response response;

    private final java.util.Optional username;

    private final java.util.Optional password;

    public AuthChallengeResponse(Response response, java.util.Optional username, java.util.Optional password) {
        this.response = java.util.Objects.requireNonNull(response, "response is required");
        this.username = username;
        this.password = password;
    }

    /**
     * The decision on what to do in response to the authorization challenge.  Default means
     * deferring to the default behavior of the net stack, which will likely either the Cancel
     * authentication or display a popup dialog box.
     */
    public Response getResponse() {
        return response;
    }

    /**
     * The username to provide, possibly empty. Should only be set if response is
     * ProvideCredentials.
     */
    public java.util.Optional getUsername() {
        return username;
    }

    /**
     * The password to provide, possibly empty. Should only be set if response is
     * ProvideCredentials.
     */
    public java.util.Optional getPassword() {
        return password;
    }

    private static AuthChallengeResponse fromJson(JsonInput input) {
        Response response = null;
        java.util.Optional username = java.util.Optional.empty();
        java.util.Optional password = java.util.Optional.empty();
        input.beginObject();
        while (input.hasNext()) {
            switch(input.nextName()) {
                case "response":
                    response = Response.fromString(input.nextString());
                    break;
                case "username":
                    username = java.util.Optional.ofNullable(input.nextString());
                    break;
                case "password":
                    password = java.util.Optional.ofNullable(input.nextString());
                    break;
                default:
                    input.skipValue();
                    break;
            }
        }
        input.endObject();
        return new AuthChallengeResponse(response, username, password);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy