Class FileValidatorUtil

java.lang.Object
com.evolveum.midpoint.web.component.input.validator.FileValidatorUtil

public final class FileValidatorUtil extends Object
Contains utility methods for validating uploaded file content. Validation compares the content type detected from the file bytes with both the declared content type and the configured allowed MIME types.
Author:
matisovaa
  • Constructor Details

    • FileValidatorUtil

      public FileValidatorUtil()
  • Method Details

    • validateUploadContent

      public static void validateUploadContent(byte[] bytes, String declaredContentType, List<String> allowedContentTypes) throws FileUploadContentValidationException
      Validates uploaded file content against its declared content type and the configured allowed MIME types. The actual content type is detected from the file bytes. Configured allowed types support MIME wildcards, for example image/*.
      Parameters:
      bytes - uploaded file content
      declaredContentType - content type declared by the upload request; may be null or blank
      allowedContentTypes - MIME types allowed by the effective upload policy
      Throws:
      FileUploadContentValidationException - if the content type cannot be recognized, a MIME type is malformed, the detected type is not allowed, or the declared type does not match the detected type
    • detectContentType

      public static String detectContentType(byte[] bytes)
      Detects the MIME type of uploaded content from its bytes. The method uses Apache Tika detection without relying on a file name. Container detectors identify Office and OpenDocument formats precisely (e.g. docx, xlsx, doc, xls, odt, ods) in addition to magic-byte detection.
      Parameters:
      bytes - uploaded file content
      Returns:
      detected MIME type, or null if the content type is not recognized