Class SchemaValidator


  • public class SchemaValidator
    extends Object
    author Pascal Knueppel
    created at: 06.10.2019 - 00:18

    This class will validate documents against their meta-schemata. Normally the validation should be done with the help of ResourceType-definitions that define a resource endpoint with the setup of their resources. Meaning that a ResourceType knows the meta-schemata of a resource and its extensions which is why the ResourceType is the base of validating a resource-document
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  SchemaValidator.DirectionType
      the direction type is used for validation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static com.fasterxml.jackson.databind.JsonNode validateDocumentForRequest​(Schema metaSchema, com.fasterxml.jackson.databind.JsonNode document, HttpMethod httpMethod)
      will validate an incoming document against its main schema and all its extensions.
      static com.fasterxml.jackson.databind.JsonNode validateDocumentForRequest​(ResourceType resourceType, com.fasterxml.jackson.databind.JsonNode document, HttpMethod httpMethod)
      will validate an incoming document against its main schema and all its extensions.
      protected static com.fasterxml.jackson.databind.JsonNode validateDocumentForResponse​(Schema metaSchema, com.fasterxml.jackson.databind.JsonNode document)
      will validate an outgoing document against its main schema and all its extensions.
      protected static com.fasterxml.jackson.databind.JsonNode validateDocumentForResponse​(Schema metaSchema, com.fasterxml.jackson.databind.JsonNode document, com.fasterxml.jackson.databind.JsonNode validatedRequest, String attributes, String excludedAttributes)
      will validate an outgoing document against its main schema and all its extensions.
      static com.fasterxml.jackson.databind.JsonNode validateDocumentForResponse​(ResourceTypeFactory resourceTypeFactory, ResourceType resourceType, com.fasterxml.jackson.databind.JsonNode document, com.fasterxml.jackson.databind.JsonNode validatedRequest, String attributes, String excludedAttributes)
      will validate an outgoing document against its main schema and all its extensions.
      protected static com.fasterxml.jackson.databind.JsonNode validateExtensionForRequest​(Schema metaSchema, com.fasterxml.jackson.databind.JsonNode document, HttpMethod httpMethod)
      This method is explicitly for extension validation.
      static com.fasterxml.jackson.databind.JsonNode validateSchemaDocument​(Schema metaSchema, com.fasterxml.jackson.databind.JsonNode schemaDocument)
      this method will validate a new schema declaration against a meta schema.
      static com.fasterxml.jackson.databind.JsonNode validateSchemaDocumentForRequest​(Schema metaSchema, com.fasterxml.jackson.databind.JsonNode schemaDocument)
      this method will validate a new schema declaration against a meta schema.
    • Method Detail

      • validateSchemaDocument

        public static com.fasterxml.jackson.databind.JsonNode validateSchemaDocument​(Schema metaSchema,
                                                                                     com.fasterxml.jackson.databind.JsonNode schemaDocument)
        this method will validate a new schema declaration against a meta schema. In other validations it might happen that specific attributes will be removed from the document because they do not belong into a request or a response. This method will ignore the direction-validation and keeps these attributes
        Parameters:
        metaSchema - the meta schema that is used to validate the new schema
        schemaDocument - the new schema document that should be validated
        Returns:
        the validated schema definition
      • validateSchemaDocumentForRequest

        public static com.fasterxml.jackson.databind.JsonNode validateSchemaDocumentForRequest​(Schema metaSchema,
                                                                                               com.fasterxml.jackson.databind.JsonNode schemaDocument)
        this method will validate a new schema declaration against a meta schema. In other validations it might happen that specific attributes will be removed from the document because they do not belong into a request or a response. This method will ignore the direction-validation and keeps these attributes
        Parameters:
        metaSchema - the meta schema that is used to validate the new schema
        schemaDocument - the new schema document that should be validated
        Returns:
        the validated schema definition
      • validateDocumentForResponse

        public static com.fasterxml.jackson.databind.JsonNode validateDocumentForResponse​(ResourceTypeFactory resourceTypeFactory,
                                                                                          ResourceType resourceType,
                                                                                          com.fasterxml.jackson.databind.JsonNode document,
                                                                                          com.fasterxml.jackson.databind.JsonNode validatedRequest,
                                                                                          String attributes,
                                                                                          String excludedAttributes)
                                                                                   throws DocumentValidationException
        will validate an outgoing document against its main schema and all its extensions. Attributes that are unknown to the given schema or are meaningless or forbidden in responses due to their mutability or returned value will be removed from the validated document.
        attributes that will be removed in the response validation are thos that are having a mutability of Mutability.WRITE_ONLY or a returned value of Returned.NEVER. This will prevent the server from accidentally returning passwords or equally sensitive information
        Parameters:
        resourceType - the resource type definition of the incoming document
        document - the document that should be validated
        validatedRequest - this parameter is used for attributes that have a returned value of Returned.REQUEST. Those attributes should only be returned if the attribute was modified on a POST, PUT or PATCH request or in a query request only if the attribute is present within the attributes parameter. So the validated request tells us if the client tried to write to the attribute and if this is the case the attribute should be returned
        attributes - When specified, the default list of attributes SHALL be overridden, and each resource returned MUST contain the minimum set of resource attributes and any attributes or sub-attributes explicitly requested by the "attributes" parameter. The query parameter attributes value is a comma-separated list of resource attribute names in standard attribute notation (Section 3.10) form (e.g., userName, name, emails).
        excludedAttributes - When specified, each resource returned MUST contain the minimum set of resource attributes. Additionally, the default set of attributes minus those attributes listed in "excludedAttributes" is returned. The query parameter attributes value is a comma-separated list of resource attribute names in standard attribute notation (Section 3.10) form (e.g., userName, name, emails).
        Returns:
        the validated document that consists of ScimNodes
        Throws:
        DocumentValidationException - if the schema validation failed
      • validateDocumentForResponse

        protected static com.fasterxml.jackson.databind.JsonNode validateDocumentForResponse​(Schema metaSchema,
                                                                                             com.fasterxml.jackson.databind.JsonNode document)
        will validate an outgoing document against its main schema and all its extensions. Attributes that are unknown to the given schema or are meaningless or forbidden in responses due to their mutability or returned value will be removed from the validated document.
        attributes that will be removed in the response validation are thos that are having a mutability of Mutability.WRITE_ONLY or a returned value of Returned.NEVER. This will prevent the server from accidentally returning passwords or equally sensitive information
        Parameters:
        metaSchema - the json meta schema definition of the document
        document - the document to validate
        Returns:
        the validated document that consists of ScimNodes
      • validateDocumentForResponse

        protected static com.fasterxml.jackson.databind.JsonNode validateDocumentForResponse​(Schema metaSchema,
                                                                                             com.fasterxml.jackson.databind.JsonNode document,
                                                                                             com.fasterxml.jackson.databind.JsonNode validatedRequest,
                                                                                             String attributes,
                                                                                             String excludedAttributes)
        will validate an outgoing document against its main schema and all its extensions. Attributes that are unknown to the given schema or are meaningless or forbidden in responses due to their mutability or returned value will be removed from the validated document.
        attributes that will be removed in the response validation are thos that are having a mutability of Mutability.WRITE_ONLY or a returned value of Returned.NEVER. This will prevent the server from accidentally returning passwords or equally sensitive information
        Parameters:
        metaSchema - the json meta schema definition of the document
        document - the document to validate
        validatedRequest - this parameter is used for attributes that have a returned value of Returned.REQUEST. Those attributes should only be returned if the attribute was modified on a POST, PUT or PATCH request or in a query request only if the attribute is present within the attributes parameter. So the validated request tells us if the client tried to write to the attribute and if this is the case the attribute should be returned write to the attribute and if this is the case the attribute should be returned
        attributes - When specified, the default list of attributes SHALL be overridden, and each resource returned MUST contain the minimum set of resource attributes and any attributes or sub-attributes explicitly requested by the "attributes" parameter. The query parameter attributes value is a comma-separated list of resource attribute names in standard attribute notation (Section 3.10) form (e.g., userName, name, emails).
        excludedAttributes - When specified, each resource returned MUST contain the minimum set of resource attributes. Additionally, the default set of attributes minus those attributes listed in "excludedAttributes" is returned. The query parameter attributes value is a comma-separated list of resource attribute names in standard attribute notation (Section 3.10) form (e.g., userName, name, emails).
        Returns:
        the validated document that consists of ScimNodes
      • validateDocumentForRequest

        public static com.fasterxml.jackson.databind.JsonNode validateDocumentForRequest​(ResourceType resourceType,
                                                                                         com.fasterxml.jackson.databind.JsonNode document,
                                                                                         HttpMethod httpMethod)
                                                                                  throws DocumentValidationException
        will validate an incoming document against its main schema and all its extensions. Attributes that are unknown to the given schema or are meaningless in requests due to their mutability value will be removed from the validated document.
        attributes that will be removed in the request validation are those that are have a mutability of Mutability.READ_ONLY. The client is not able to write these attributes and therefore the server does not need to process them.
        Parameters:
        resourceType - the resource type definition of the incoming document
        document - the document that should be validated
        httpMethod - the request http method that is used to validate the request-document
        Returns:
        the validated document that consists of ScimNodes
        Throws:
        DocumentValidationException - if the schema validation failed
      • validateDocumentForRequest

        protected static com.fasterxml.jackson.databind.JsonNode validateDocumentForRequest​(Schema metaSchema,
                                                                                            com.fasterxml.jackson.databind.JsonNode document,
                                                                                            HttpMethod httpMethod)
        will validate an incoming document against its main schema and all its extensions. Attributes that are unknown to the given schema or are meaningless in requests due to their mutability value will be removed from the validated document.
        attributes that will be removed in the request validation are those that are have a mutability of Mutability.READ_ONLY. The client is not able to write these attributes and therefore the server does not need to process them.
        Parameters:
        metaSchema - the json meta schema definition of the document
        document - the document to validate
        httpMethod - tells us which request type the client has used. This is e.g. necessary for immutable types that are valid on POST requests but invalid on PUT requests
        Returns:
        the validated document that consists of ScimNodes
      • validateExtensionForRequest

        protected static com.fasterxml.jackson.databind.JsonNode validateExtensionForRequest​(Schema metaSchema,
                                                                                             com.fasterxml.jackson.databind.JsonNode document,
                                                                                             HttpMethod httpMethod)
        This method is explicitly for extension validation. Extensions within its main documents should not have "schemas"-attribute itself since the relation of the schema-uri can be found in the "schemas"-attribute of the main-document. So this method will trigger the schema validation but will ignore the validation of the "schemas"-attrbiute
        Parameters:
        metaSchema - the json meta schema definition of the document
        document - the extension to validate
        httpMethod - tells us which request type the client has used. This is e.g. necessary for immutable types that are valid on POST requests but invalid on PUT requests
        Returns:
        the validated document that consists of ScimNodes