Class Credentials

java.lang.Object
org.apache.guacamole.net.auth.Credentials
All Implemented Interfaces:
Serializable

public class Credentials extends Object implements Serializable
Simple arbitrary set of credentials, including a username/password pair and a copy of the details of the HTTP request received for authentication.

This class is used along with AuthenticationProvider to provide arbitrary HTTP-based authentication for Guacamole.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Credentials(String username, String password, javax.servlet.http.HttpServletRequest request)
    Creates a new Credentials object with the given username, password, and HTTP request.
    Credentials(String username, String password, RequestDetails requestDetails)
    Creates a new Credentials object with the given username, password, and general HTTP request details.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the HTTP header having the given name from the original details of the HTTP request that is related to these credentials.
    Returns the value of the HTTP parameter having the given name from the original details of the HTTP request that is related to these credentials.
    Returns the password associated with this set of credentials.
    Returns the address of the client end of the connection which provided these credentials, if known.
    Returns the hostname of the client end of the connection which provided these credentials, if known.
    javax.servlet.http.HttpServletRequest
    Deprecated.
    It is not reliable to reference an HttpServletRequest outside the scope of the specific request that created it.
    Returns the details of the HTTP request related to these Credentials.
    javax.servlet.http.HttpSession
    Returns the HttpSession associated with this set of credentials.
    Returns the username associated with this set of credentials.
    boolean
    Returns whether this Credentials object does not contain any specific authentication parameters, including HTTP parameters and the HTTP header used for the authentication token.
    void
    setPassword(String password)
    Sets the password associated with this set of credentials.
    void
    setRemoteAddress(String remoteAddress)
    Deprecated.
    Since 1.6.0, the address that may be associated with a Credentials object is tied to the RequestDetails.
    void
    setRemoteHostname(String remoteHostname)
    Deprecated.
    Since 1.6.0, the hostname that may be associated with a Credentials object is tied to the RequestDetails.
    void
    setRequest(javax.servlet.http.HttpServletRequest request)
    Deprecated.
    It is not reliable to reference an HttpServletRequest outside the scope of the specific request that created it.
    void
    Replaces the current HTTP request details of these Credentials with the given details.
    void
    setSession(javax.servlet.http.HttpSession session)
    Deprecated.
    Since 1.6.0, the HttpSession that may be associated with a Credentials object is tied to the RequestDetails.
    void
    setUsername(String username)
    Sets the username associated with this set of credentials.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Credentials

      public Credentials(String username, String password, javax.servlet.http.HttpServletRequest request)
      Creates a new Credentials object with the given username, password, and HTTP request. The details of the request are copied for later reference and can be retrieved with getRequestDetails().
      Parameters:
      username - The username that was provided for authentication.
      password - The password that was provided for authentication.
      request - The HTTP request associated with the authentication request.
    • Credentials

      public Credentials(String username, String password, RequestDetails requestDetails)
      Creates a new Credentials object with the given username, password, and general HTTP request details.
      Parameters:
      username - The username that was provided for authentication.
      password - The password that was provided for authentication.
      requestDetails - The details of the HTTP request associated with the authentication request.
  • Method Details

    • getPassword

      public String getPassword()
      Returns the password associated with this set of credentials.
      Returns:
      The password associated with this username/password pair, or null if no password has been set.
    • setPassword

      public void setPassword(String password)
      Sets the password associated with this set of credentials.
      Parameters:
      password - The password to associate with this username/password pair.
    • getUsername

      public String getUsername()
      Returns the username associated with this set of credentials.
      Returns:
      The username associated with this username/password pair, or null if no username has been set.
    • setUsername

      public void setUsername(String username)
      Sets the username associated with this set of credentials.
      Parameters:
      username - The username to associate with this username/password pair.
    • getRequest

      @Deprecated public javax.servlet.http.HttpServletRequest getRequest()
      Deprecated.
      It is not reliable to reference an HttpServletRequest outside the scope of the specific request that created it. Use getRequestDetails() instead.
      Returns the HttpServletRequest associated with this set of credentials.
      Returns:
      The HttpServletRequest associated with this set of credentials, or null if no such request exists.
    • setRequest

      @Deprecated public void setRequest(javax.servlet.http.HttpServletRequest request)
      Deprecated.
      It is not reliable to reference an HttpServletRequest outside the scope of the specific request that created it. Use setRequestDetails(org.apache.guacamole.net.RequestDetails) instead.
      Sets the HttpServletRequest associated with this set of credentials.
      Parameters:
      request - The HttpServletRequest to associated with this set of credentials.
    • getRequestDetails

      public RequestDetails getRequestDetails()
      Returns the details of the HTTP request related to these Credentials.
      Returns:
      The details of the HTTP request related to these Credentials.
    • setRequestDetails

      public void setRequestDetails(RequestDetails requestDetails)
      Replaces the current HTTP request details of these Credentials with the given details.
      Parameters:
      requestDetails - The details of the HTTP request that should replace the established details within these Credentials.
    • getSession

      public javax.servlet.http.HttpSession getSession()
      Returns the HttpSession associated with this set of credentials.

      This is a convenience function that is equivalent to invoking RequestDetails.getSession() on the RequestDetails returned by getRequestDetails().

      NOTE: Guacamole itself does not use the HttpSession. The extension subsystem does not provide access to the session object used by Guacamole, which is considered internal. Access to an HttpSession is only of use if you have another application in place that does use HttpSession and needs to be considered.

      Returns:
      The HttpSession associated with this set of credentials, or null if there is no HttpSession.
    • setSession

      @Deprecated public void setSession(javax.servlet.http.HttpSession session)
      Deprecated.
      Since 1.6.0, the HttpSession that may be associated with a Credentials object is tied to the RequestDetails. If the HttpSession is part of a Credentials and truly needs to be replaced by another HttpSession, use setRequestDetails(org.apache.guacamole.net.RequestDetails) to override the underlying RequestDetails instead.
      Sets the HttpSession associated with this set of credentials.
      Parameters:
      session - The HttpSession to associated with this set of credentials.
    • getHeader

      public String getHeader(String name)
      Returns the value of the HTTP header having the given name from the original details of the HTTP request that is related to these credentials. Header names are case-insensitive. If no such header was present, null is returned. If the header had multiple values, the first value is returned.

      For access to all values of a header, as well as other details of the request, see getRequestDetails(). This is a convenience function that is equivalent to invoking RequestDetails.getHeader(java.lang.String).

      Parameters:
      name - The name of the header to retrieve. This name is case-insensitive.
      Returns:
      The first value of the HTTP header with the given name, or null if there is no such header.
    • getParameter

      public String getParameter(String name)
      Returns the value of the HTTP parameter having the given name from the original details of the HTTP request that is related to these credentials. Parameter names are case-sensitive. If no such parameter was present, null is returned. If the parameter had multiple values, the first value is returned.

      For access to all values of a parameter, as well as other details of the request, see getRequestDetails(). This is a convenience function that is equivalent to invoking RequestDetails.getParameter(java.lang.String).

      Parameters:
      name - The name of the parameter to retrieve. This name is case-sensitive.
      Returns:
      The first value of the HTTP parameter with the given name, or null if there is no such parameter.
    • getRemoteAddress

      public String getRemoteAddress()
      Returns the address of the client end of the connection which provided these credentials, if known.

      This is a convenience function that is equivalent to invoking RequestDetails.getRemoteAddress() on the RequestDetails returned by getRequestDetails().

      Returns:
      The address of the client end of the connection which provided these credentials, or null if the address is not known.
    • setRemoteAddress

      @Deprecated public void setRemoteAddress(String remoteAddress)
      Deprecated.
      Since 1.6.0, the address that may be associated with a Credentials object is tied to the RequestDetails. If the address truly needs to be replaced, use setRequestDetails(org.apache.guacamole.net.RequestDetails) to override the underlying RequestDetails instead.
      Sets the address of the client end of the connection which provided these credentials.
      Parameters:
      remoteAddress - The address of the client end of the connection which provided these credentials, or null if the address is not known.
    • getRemoteHostname

      public String getRemoteHostname()
      Returns the hostname of the client end of the connection which provided these credentials, if known. If the hostname of the client cannot be determined, but the address is known, the address may be returned instead.

      This is a convenience function that is equivalent to invoking RequestDetails.getRemoteHostname() on the RequestDetails returned by getRequestDetails().

      Returns:
      The hostname or address of the client end of the connection which provided these credentials, or null if the hostname is not known.
    • setRemoteHostname

      @Deprecated public void setRemoteHostname(String remoteHostname)
      Deprecated.
      Since 1.6.0, the hostname that may be associated with a Credentials object is tied to the RequestDetails. If the hostname truly needs to be replaced, use setRequestDetails(org.apache.guacamole.net.RequestDetails) to override the underlying RequestDetails instead.
      Sets the hostname of the client end of the connection which provided these credentials, if known. If the hostname of the client cannot be determined, but the address is known, the address may be specified instead.
      Parameters:
      remoteHostname - The hostname or address of the client end of the connection which provided these credentials, or null if the hostname is not known.
    • isEmpty

      public boolean isEmpty()
      Returns whether this Credentials object does not contain any specific authentication parameters, including HTTP parameters and the HTTP header used for the authentication token. An authentication request that contains no parameters whatsoever will tend to be the first, anonymous, credential-less authentication attempt that results in the initial login screen rendering.
      Returns:
      true if this Credentials object contains no authentication parameters whatsoever, false otherwise.