# WebDriverRequestParameters.java

    /*
     ** Module   : WebDriverRequestParameters.java
     ** Abstract : Container for parameters needed for spawning a new web client. These are fetched from the
     **            HTTP request.
     **
     ** Copyright (c) 2023-2024, Golden Code Development Corporation.
     **
     ** -#- -I- --Date-- ---------------------------------Description---------------------------------
     ** 001 GBB 20230817 Created initial version
     ** 002 GBB 20231113 Cleanup for web:referrer:url.
     ** 003 GBB 20240214 Adding serverName & serverPort. Adding convenience method getParameter(String).
     ** 004 GBB 20240515 Adding queryString.
     */
    /*
    ** This program is free software: you can redistribute it and/or modify
    ** it under the terms of the GNU Affero General Public License as
    ** published by the Free Software Foundation, either version 3 of the
    ** License, or (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ** GNU Affero General Public License for more details.
    **
    ** You may find a copy of the GNU Affero GPL version 3 at the following
    ** location: https://www.gnu.org/licenses/agpl-3.0.en.html
    **
    ** Additional terms under GNU Affero GPL version 3 section 7:
    **
    **   Under Section 7 of the GNU Affero GPL version 3, the following additional
    **   terms apply to the works covered under the License.  These additional terms
    **   are non-permissive additional terms allowed under Section 7 of the GNU
    **   Affero GPL version 3 and may not be removed by you.
    **
    **   0. Attribution Requirement.
    **
    **     You must preserve all legal notices or author attributions in the covered
    **     work or Appropriate Legal Notices displayed by works containing the covered
    **     work.  You may not remove from the covered work any author or developer
    **     credit already included within the covered work.
    **
    **   1. No License To Use Trademarks.
    **
    **     This license does not grant any license or rights to use the trademarks
    **     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
    **     of Golden Code Development Corporation. You are not authorized to use the
    **     name Golden Code, FWD, or the names of any author or contributor, for
    **     publicity purposes without written authorization.
    **
    **   2. No Misrepresentation of Affiliation.
    **
    **     You may not represent yourself as Golden Code Development Corporation or FWD.
    **
    **     You may not represent yourself for publicity purposes as associated with
    **     Golden Code Development Corporation, FWD, or any author or contributor to
    **     the covered work, without written authorization.
    **
    **   3. No Misrepresentation of Source or Origin.
    **
    **     You may not represent the covered work as solely your work.  All modified
    **     versions of the covered work must be marked in a reasonable way to make it
    **     clear that the modified work is not originating from Golden Code Development
    **     Corporation or FWD.  All modified versions must contain the notices of
    **     attribution required in this license.
    */
    package com.goldencode.p2j.main;

    import org.eclipse.jetty.http.*;
    import org.eclipse.jetty.util.*;

    import javax.servlet.http.*;
    import java.util.*;

    /** The container for the web request details fetched from the servlet request. */
    public class WebDriverRequestParameters
    {
       /**
        * If SSO is disabled or SSO auto-login has completed, it's the operating system userid.
        * If the SSO login attempt hasn't been processed, it's the app user.
        */
       private String user;

       /**
        * If SSO is disabled or SSO auto-login has completed, it's the operating system user password.
        * If the SSO login attempt hasn't been processed, it's the app password.
        */
       private String password;

       /** The selected UI theme. */
       private String theme;

       /** A map of all query / form params. */
       private Map<String, String[]> paramMap;

       /** The login url query parameters as map. */
       private MultiMap<String> queryParams;

       /** X-Forwarded-Host HTTP header, i.e. www.example.com:port. Available with proxy forwarding. */
       private String forwardedHost;

       /** X-Forwarded-Proto HTTP header, i.e. https. Available with proxy forwarding. */
       private String forwardedProto;

       /** The external user IP. */
       private String externalUserIp;

       /** The internal user IP. */
       private String internalUserIp;

       /** The server name. */
       private String serverName;

       /** The server port. */
       private int serverPort;

       /** Cookies attached to the request. */
       private Cookie[] cookies;

       /** Package-private constructor. */
       WebDriverRequestParameters()
       {
       }

       /**
        * Getter for {@link #user}.
        *
        * @return   See above.
        */
       public String getUser()
       {
          return user;
       }

       /**
        * Setter for {@link #user}.
        *
        * @param    user
        *           The user name
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setUser(String user)
       {
          this.user = user;
          return this;
       }

       /**
        * Getter for {@link #password}.
        *
        * @return   See above.
        */
       public String getPassword()
       {
          return password;
       }

       /**
        * Setter for {@link #password}.
        *
        * @param    password
        *           The user's password
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setPassword(String password)
       {
          this.password = password;
          return this;
       }

       /**
        * Getter for {@link #paramMap}.
        *
        * @return   See above.
        */
       public Map<String, String[]> getParamMap()
       {
          return paramMap;
       }

       /**
        * Setter for {@link #paramMap}.
        *
        * @param    paramMap
        *           The map of all query / form params.
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setParamMap(Map<String, String[]> paramMap)
       {
          this.paramMap = paramMap;
          return this;
       }

       /**
        * Getter for {@link #queryParams}.
        *
        * @return   See above.
        */
       public MultiMap<String> getQueryParams()
       {
          return queryParams;
       }

       /**
        * Setter for {@link #queryParams}.
        *
        * @param    queryParams
        *           The query parameters.
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setQueryParams(MultiMap<String> queryParams)
       {
          this.queryParams = queryParams;
          return this;
       }

       /**
        * Returns the first value of for the param name or <code>null</code> if not found.
        *
        * @return   See above.
        */
       public String getParameter(String paramNameToken)
       {
          if (!paramMap.containsKey(paramNameToken))
          {
             return null;
          }
          String[] values = paramMap.get(paramNameToken);
          return values != null && values.length > 0 ? values[0] : null;
       }

       /**
        * Getter for {@link #theme}.
        *
        * @return   See above.
        */
       public String getTheme()
       {
          return theme;
       }

       /**
        * Setter for {@link #theme}.
        *
        * @param    theme
        *           The selected theme
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setTheme(String theme)
       {
          this.theme = theme;
          return this;
       }

       /**
        * Getter for {@link #forwardedHost}.
        *
        * @return   See above.
        */
       public String getForwardedHost()
       {
          return forwardedHost;
       }

       /**
        * Setter for {@link #forwardedHost}.
        *
        * @param    forwardedHost
        *           The X-Forwarded-Host header
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setForwardedHost(String forwardedHost)
       {
          this.forwardedHost = forwardedHost;
          return this;
       }

       /**
        * Getter for {@link #forwardedProto}.
        *
        * @return   See above.
        */
       public String getForwardedProto()
       {
          return forwardedProto;
       }

       /**
        * Setter for {@link #forwardedProto}.
        *
        * @param    forwardedProto
        *           The X-Forwarded-Proto header
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setForwardedProto(String forwardedProto)
       {
          this.forwardedProto = forwardedProto != null ? forwardedProto : HttpScheme.HTTPS.asString();
          return this;
       }

       /**
        * Getter for {@link #externalUserIp}.
        *
        * @return   See above.
        */
       public String getExternalUserIp()
       {
          return externalUserIp;
       }

       /**
        * Setter for {@link #externalUserIp}.
        *
        * @param    clientIp
        *           The external client address
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setExternalUserIp(String clientIp)
       {
          this.externalUserIp = clientIp;
          return this;
       }

       /**
        * Getter for {@link #internalUserIp}.
        *
        * @return   See above.
        */
       public String getInternalUserIp()
       {
          return internalUserIp;
       }

       /**
        * Setter for {@link #internalUserIp}.
        *
        * @param    internalUserIp
        *           The internal client address
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setInternalUserIp(String internalUserIp)
       {
          this.internalUserIp = internalUserIp;
          return this;
       }

       /**
        * Getter for {@link #serverName}.
        *
        * @return   See above.
        */
       public String getServerName()
       {
          return serverName;
       }

       /**
        * Setter for {@link #serverName}.
        *
        * @param    serverName
        *           The server name.
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setServerName(String serverName)
       {
          this.serverName = serverName;
          return this;
       }

       /**
        * Getter for {@link #serverPort}.
        *
        * @return   See above.
        */
       public int getServerPort()
       {
          return serverPort;
       }

       /**
        * Setter for {@link #serverPort}.
        *
        * @param    serverPort
        *           The server port.
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setServerPort(int serverPort)
       {
          this.serverPort = serverPort;
          return this;
       }

       /**
        * Getter for {@link #cookies}.
        *
        * @return   See above.
        */
       public Cookie[] getCookies()
       {
          return cookies;
       }

       /**
        * Setter for {@link #cookies}.
        *
        * @param    cookies
        *           The cookies
        *
        * @return   The current object.
        */
       public WebDriverRequestParameters setCookies(Cookie[] cookies)
       {
          this.cookies = cookies;
          return this;
       }
    }