Class FileValidatorUtil

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

public final class FileValidatorUtil extends Object
Contains methods for file validation. E.g. compares file contentType with list of allowed ones or checks if given file starts with magic number of expected contentType.
Author:
matisovaa
  • Constructor Details

    • FileValidatorUtil

      public FileValidatorUtil()
  • Method Details

    • getMimeTypes

      public static List<jakarta.activation.MimeType> getMimeTypes(List<String> stringMimeTypes)
      Converts list of String mime type names (e.g. "image/jpeg") to list of MimeType objects.
      Parameters:
      stringMimeTypes - list of String mime type names (e.g. "image/jpeg")
      Returns:
      list of MimeType objects creates from input list of String mime type names (e.g. "image/jpeg")
    • isValidContentType

      public static boolean isValidContentType(String contentType, List<jakarta.activation.MimeType> allowedTypes) throws jakarta.activation.MimeTypeParseException
      Validates if given content type name is in the list of allowed MimeTypes.
      Parameters:
      contentType - to check if it is allowed
      allowedTypes - the list of allowed MimeTypes
      Returns:
      true if given contentType is in the list of allowed MimeTypes, false otherwise
      Throws:
      jakarta.activation.MimeTypeParseException - if it is not possible to convert given contentType to MimeType
    • isValidMagicNumber

      public static boolean isValidMagicNumber(String contentType, InputStream inputStream) throws IOException
      Validates if given inputStream begins with magic number of given contentType.
      Parameters:
      contentType - expected contentType of data in given inputStream
      inputStream - stream of data to check contentType based on its magic number
      Returns:
      true if given inputStream begins with magic number of given contentType, false otherwise
      Throws:
      IOException - if there is problem to read bytes from given inputStream