Class ComponentValueProvider

java.lang.Object
com.authlete.hms.ComponentValueProvider
All Implemented Interfaces:
SignatureContext

public class ComponentValueProvider extends Object implements SignatureContext
A utility to provide component values.
Since:
1.1
See Also:
  • Constructor Details

    • ComponentValueProvider

      public ComponentValueProvider()
      The default constructor.
  • Method Details

    • getComponentValue

      public String getComponentValue(SignatureMetadata metadata, ComponentIdentifier identifier) throws SignatureException
      Description copied from interface: SignatureContext
      Get the component value.
      Specified by:
      getComponentValue in interface SignatureContext
      Parameters:
      metadata - The signature metadata where the component identifier is included.
      identifier - The component identifier.
      Returns:
      The value of the component identified by the component identifier. null if the component value is not available.
      Throws:
      SignatureException - Something wrong happened.
    • getHeaders

      public Map<String,List<String>> getHeaders()
      Get the pool of the HTTP header fields.
      Returns:
      The pool of the HTTP header fields.
    • setHeaders

      public ComponentValueProvider setHeaders(Map<String,List<String>> headers)
      Set the pool of the HTTP header fields.
      Parameters:
      headers - The pool of the HTTP header fields.
      Returns:
      this object.
    • getTrailers

      public Map<String,List<String>> getTrailers()
      Get the pool of the HTTP trailer fields.
      Returns:
      The pool of the HTTP trailer fields.
    • setTrailers

      public ComponentValueProvider setTrailers(Map<String,List<String>> trailers)
      Set the pool of the HTTP trailer fields.
      Parameters:
      trailers - The pool of the HTTP trailer fields.
      Returns:
      this object.
    • getHeadersInRequest

      public Map<String,List<String>> getHeadersInRequest()
      Get the pool of the HTTP header fields in the request.
      Returns:
      The pool of the HTTP header fields in the request.
    • setHeadersInRequest

      public ComponentValueProvider setHeadersInRequest(Map<String,List<String>> headersInRequest)
      Set the pool of the HTTP header fields in the request.
      Parameters:
      headersInRequest - The pool of the HTTP header fields in the request.
      Returns:
      this object.
    • getTrailersInRequest

      public Map<String,List<String>> getTrailersInRequest()
      Get the pool of the HTTP trailer fields in the request.
      Returns:
      The pool of the HTTP trailer fields in the request.
    • setTrailersInRequest

      public ComponentValueProvider setTrailersInRequest(Map<String,List<String>> trailersInRequest)
      Set the pool of the HTTP trailer fields in the request.
      Parameters:
      trailersInRequest - The pool of the HTTP trailer fields in the request.
      Returns:
      this object.
    • getDataTypeMappings

      public Map<String,StructuredDataType> getDataTypeMappings()
      Get the Map instance that manages additional mappings between field names and their structured data types. The mappings managed by the instance are referenced when processing the sf flag (RFC 9421, Section 2.1.1. Strict Serialization of HTTP Structured Fields).

      This class implementation refers to the default mappings maintained within the StructuredDataType class when the mapping for a field name, specified as a component name with the sf flag, is not found in the additional mappings.

      Returns:
      The Map instance that manages additional mappings.
    • addDataTypeMapping

      public ComponentValueProvider addDataTypeMapping(String fieldName, StructuredDataType dataType)
      Add an additional mapping between a field name and its structured data type. This mapping is referenced when processing the sf flag (RFC 9421, Section 2.1.1. Strict Serialization of HTTP Structured Fields).

      This class implementation refers to the default mappings maintained within the StructuredDataType class when the mapping for a field name, specified as a component name with the sf flag, is not found in the additional mappings.

      Parameters:
      fieldName - A field name. The given value is converted to lowercase before being added.
      dataType - A data type.
      Returns:
      this object.
    • getMethod

      public String getMethod()
      Get the HTTP method of a request message. This is used as the value of the "@method" derived component.
      Returns:
      The HTTP method of a request message.
      See Also:
    • setMethod

      public ComponentValueProvider setMethod(String method)
      Set the HTTP method of a request message. This is used as the value of the "@method" derived component.
      Parameters:
      method - The HTTP method of a request message.
      Returns:
      this object.
      See Also:
    • getTargetUri

      public String getTargetUri()
      Get the target URI of a request message. This is used as the value of the "@target-uri" derived component.
      Returns:
      The target URI of a request message.
      See Also:
    • setTargetUri

      public ComponentValueProvider setTargetUri(String uri)
      Set the target URI of a request message. This is used as the value of the "@target-uri" derived component.
      Parameters:
      uri - The target URI of a request message.
      Returns:
      this object.
      Throws:
      IllegalArgumentException - The given string violates RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax.
      See Also:
    • setTargetUri

      public ComponentValueProvider setTargetUri(URI uri)
      Set the target URI of a request message. This is used as the value of the "@target-uri" derived component.
      Parameters:
      uri - The target URI of a request message.
      Returns:
      this object.
      See Also:
    • getAuthority

      public String getAuthority()
      Get the authority component of the target URI of the HTTP request message. This is used as the value of the "@authority" derived component.

      The value of this derived component is computed based on the target URI set by the setTargetUri method.

      Returns:
      The authority component of the target URI of the HTTP request message.
      See Also:
    • getScheme

      public String getScheme()
      Get the scheme of the target URL of the HTTP request message. This is used as the value of the "@scheme" derived component.

      The value of this derived component is computed based on the target URI set by the setTargetUri method.

      Returns:
      The scheme of the target URL of the HTTP request message.
      See Also:
    • getRequestTarget

      public String getRequestTarget()
      Get the full request target of the HTTP request message. This is used as the value of the "@request-target" derived component.
      Returns:
      The full request target of the HTTP request message.
      See Also:
    • setRequestTarget

      public ComponentValueProvider setRequestTarget(String requestTarget)
      Set the full request target of the HTTP request message. This is used as the value of the "@request-target" derived component.
      Parameters:
      requestTarget - The full request target of the HTTP request message.
      Returns:
      this object.
      See Also:
    • getPath

      public String getPath()
      Get the target path of the HTTP request message. This is used as the value of the "@path" derived component.

      The value of this derived component is computed based on the target URI set by the setTargetUri method.

      Returns:
      The target path of the HTTP request message.
      See Also:
    • getQuery

      public String getQuery()
      Get the query component of the HTTP request message. This is used as the value of the "@query" derived component.

      The value of this derived component is computed based on the target URI set by the setTargetUri method.

      Returns:
      The query component of the HTTP request message.
      See Also:
    • getQueryParam

      public String getQueryParam(String name)
      Get the value of a query parameter in the HTTP request message. This is used as the value of the "@query-param";name="name" derived component.

      The value of this derived component is computed based on the target URI set by the setTargetUri method.

      Parameters:
      name - The name of a query parameter.
      Returns:
      The value of a query parameter in the HTTP request message.
      See Also:
    • getStatus

      public String getStatus()
      Get the three-digit numeric HTTP status code of a response message. This is used as the "@status" derived component.
      Returns:
      The three-digit numeric HTTP status code of a response message.
      See Also:
    • setStatus

      public ComponentValueProvider setStatus(String status)
      Set the three-digit numeric HTTP status code of a response message. This is used as the "@status" derived component.
      Parameters:
      status - The three-digit numeric HTTP status code of a response message.
      Returns:
      this object.
      Throws:
      IllegalArgumentException - The value of status does not represent a three-digit positive integer.
      See Also:
    • setStatus

      public ComponentValueProvider setStatus(int status)
      Set the three-digit numeric HTTP status code of a response message. This is used as the "@status" derived component.
      Parameters:
      status - The three-digit numeric HTTP status code of a response message.
      Returns:
      this object.
      Throws:
      IllegalArgumentException - The value of status is not a three-digit positive integer.
      See Also:
    • getComponentValue

      public String getComponentValue(ComponentIdentifier identifier) throws SignatureException
      Get the value of the component specified by the component identifier.
      Parameters:
      identifier - A component identifier.
      Returns:
      The value of the specified component. If the value is unavailable, null is returned.
      Throws:
      SignatureException - (1) The component identifier includes the key parameter, but the HTTP field value is either missing, cannot be parsed as a dictionary, or contains no entry with the specified key. (2) The component identifier includes the sf parameter, but the data type of the HTTP field is either unknown or its value cannot be parsed as the expected data type.
    • getComponentValue

      public String getComponentValue(String componentName) throws SignatureException
      Get the value of the component specified by the component name.
      Parameters:
      componentName - A component name.
      Returns:
      The value of the specified component. If the value is unavailable, null is returned.
      Throws:
      SignatureException - If the value of the specified component is unavailable, even when the component name represents a derived component.