Class ImageSanitizationUtil

java.lang.Object
com.evolveum.midpoint.web.component.input.ImageSanitizationUtil

public final class ImageSanitizationUtil extends Object
Handle sanitization if images. Sanitization is configurable by input ImageUploadProcessingType configuration. Possible sanitization options are e.g. remove EXIF data or convert to fixed format.
Author:
matisovaa
  • Constructor Details

    • ImageSanitizationUtil

      public ImageSanitizationUtil()
  • Method Details

    • getFileExtensionFromFileMagicNumber

      public static String getFileExtensionFromFileMagicNumber(byte[] fileBytes)
      Determines file extension by comparing first bytes of file byte array with known magic numbers.
      Parameters:
      fileBytes - file byte array to determine file extension
      Returns:
      file extension or null if file extension was not possible to determine
    • sanitizeImage

      public static byte[] sanitizeImage(byte[] originalBytes, ImageUploadProcessingType config) throws ImageSanitizationException
      Sanitize image based on ImageUploadProcessingType configuration.
      Parameters:
      originalBytes - image to sanitize
      config - configuration what conversion is needed with input image e.g. remove EXIF data or convert to fixed format
      Returns:
      image updated based on given configuration
      Throws:
      ImageSanitizationException - if there was error during sanitization process