Class RequestUtils

java.lang.Object
de.captaingoldfish.scim.sdk.server.utils.RequestUtils

public final class RequestUtils extends Object
author Pascal Knueppel
created at: 12.10.2019 - 20:08

this class will add some helper methods that can be used to validate or modify request based attributes based on the SCIM specification RFC7643 and RFC7644
  • Method Details

    • getAttributes

      public static List<String> getAttributes(String attributes)
      this method will parse either the attributes parameter or the excludedAttributes parameter into a list. The expected form of the attributes list is: form (e.g., userName, name, emails)
      Parameters:
      attributes - the comma separated string of scim attribute names
      Returns:
      the list of attributes
    • getAttributes

      public static List<SchemaAttribute> getAttributes(ResourceType resourceType, String attributes)
      this method will parse either the attributes parameter or the excludedAttributes parameter into a list of SchemaAttributes. The expected form of the attributes list is: form (e.g., userName, name, emails)
      Parameters:
      attributes - the comma separated string of scim attribute names
      Returns:
      the list of attributes
    • validateAttributesAndExcludedAttributes

      public static void validateAttributesAndExcludedAttributes(String attributes, String excludedAttributes)
      From RFC7644 chapter 3.9:
           Clients MAY request a partial resource representation on any
           operation that returns a resource within the response by specifying
           either of the mutually exclusive URL query parameters "attributes" or
           "excludedAttributes"
       
      so only one these parameters are allowed to be specified in a request
      Parameters:
      attributes - the required attributes that should be present in the response
      excludedAttributes - the attributes that should not be returned in the response
    • parseFilter

      public static FilterNode parseFilter(ResourceType resourceType, String filter)
      parses the filter of a list request
      Parameters:
      resourceType - the resource type that describes the endpoint on which the filter is used so that the filter expression can be correctly resolved
      filter - the filter expression that must apply to the given resource type
      Returns:
      The parsed filter expression as resolvable tree structure that might be used to resolve them to jpa predicates for example
    • parsePatchPath

      public static AttributePathRoot parsePatchPath(ResourceType resourceType, String path)
      parses a value path context for patch path expressions
      Parameters:
      resourceType - the resource type that describes the endpoint on which the path expression is used
      path - the path expression that must apply to the given resource type
      Returns:
      The parsed path expression as resolvable tree structure to find matching attributes within a single resource
    • parseStartIndex

      public static Optional<Long> parseStartIndex(String startIndexQueryParameter)
      tries to parse the incoming startIndex value as long number
      Parameters:
      countQueryParameter - the query parameter that should be a number
      Returns:
      the parsed startIndex value or an empty if the parameter is missing
    • parseCount

      public static Optional<Integer> parseCount(String countQueryParameter)
      tries to parse the incoming count value as integer number
      Parameters:
      countQueryParameter - the query parameter that should be a number
      Returns:
      the parsed count value or an empty if the parameter is missing
    • getEffectiveStartIndex

      public static long getEffectiveStartIndex(Long startIndex)
      The 1-based index of the first query result. A value less than 1 SHALL be interpreted as 1.
      Parameters:
      startIndex - the index to start with to list the resources
      Returns:
      number "1" or greater
    • getEffectiveCount

      public static int getEffectiveCount(ServiceProvider serviceProvider, Integer count)
      Will get the effective count value as described in RFC7644:

      Non-negative integer. Specifies the desired maximum number of query results per page, e.g., 10. A negative value SHALL be interpreted as "0". A value of "0" indicates that no resource results are to be returned except for "totalResults".
      DEFAULT: None
      When specified, the service provider MUST NOT return more results than specified, although it MAY return fewer results. If unspecified, the maximum number of results is set by the service provider.
    • getSchemaAttributeByAttributeName

      public static SchemaAttribute getSchemaAttributeByAttributeName(ResourceType resourceType, String attributeName)
      gets the SchemaAttribute from the given ResourceType
      Parameters:
      resourceType - the resource type from which the attribute definition should be extracted
      attributeName - this instance holds the attribute name to extract the SchemaAttribute from the ResourceType
      Returns:
      the found SchemaAttribute definition
      Throws:
      BadRequestException - if no SchemaAttribute was found for the given name attribute
    • getSchemaAttributeForFilter

      public static SchemaAttribute getSchemaAttributeForFilter(ResourceType resourceType, FilterAttributeName attributeName)
      gets the SchemaAttribute from the given ResourceType
      Parameters:
      resourceType - the resource type from which the attribute definition should be extracted
      attributeName - this instance holds the attribute name to extract the SchemaAttribute from the ResourceType
      Returns:
      the found SchemaAttribute definition
      Throws:
      InvalidFilterException - if no SchemaAttribute was found for the given name attribute
    • getQueryParameters

      public static Map<String,String> getQueryParameters(String query)
      gets the query parameter from the given URL
      Parameters:
      query - the query string
      Returns:
      the query parameters as a map
    • getEffectiveFailOnErrors

      public static int getEffectiveFailOnErrors(BulkRequest bulkRequest)
      will check the failOnErrors attribute in a bulk request and return a sanitized value.

      RFC7644 chapter 3.7.3 defines the minimum value of failOnErrors as 1
         The "failOnErrors" attribute is set to '1', indicating that the
         service provider will stop processing and return results after one
         error
       
      Parameters:
      bulkRequest - the bulk request
      Returns:
      a failOnErrors value that has been validated and sanitized