Class AllowListDeserializingConverter

java.lang.Object
org.springframework.integration.support.converter.AllowListDeserializingConverter
All Implemented Interfaces:
Converter<byte[],Object>

public class AllowListDeserializingConverter extends Object implements Converter<byte[],Object>
A Converter that delegates to a Deserializer to convert data in a byte array to an object. By default, only the classes listed in DEFAULT_ALLOWED_PATTERNS (plus primitives, String and arrays of any of these) are deserialized. Use addAllowedPatterns(String...) to trust additional classes/packages, or setAllowedPatterns(String...) to replace the defaults. The "*" pattern allows all classes.

If a delegate deserializer is a DefaultDeserializer, only its ClassLoader is used for a ConfigurableObjectInputStream logic.

Since:
5.4
Author:
Gary Russell, Mark Fisher, Juergen Hoeller, Artem Bilan, Glenn Renfro
  • Field Details

    • DEFAULT_ALLOWED_PATTERNS

      public static final List<String> DEFAULT_ALLOWED_PATTERNS
      The classes allowed for deserialization by default.
      Since:
      7.2
  • Constructor Details

  • Method Details

    • setAllowedPatterns

      public void setAllowedPatterns(String... allowedPatterns)
      Set simple patterns for allowable packages/classes for deserialization. The patterns will be applied in order until a match is found. A class can be fully qualified, or a wildcard '*' is allowed at the beginning or end of the class name. Examples: com.example.*, *.MyClass. Replaces all the existing patterns, including the DEFAULT_ALLOWED_PATTERNS. Use addAllowedPatterns(String...) to keep the defaults.
      Parameters:
      allowedPatterns - the patterns; must not be empty.
    • addAllowedPatterns

      public void addAllowedPatterns(String... patterns)
      Add package/class patterns to the allowed list, in addition to the existing ones (by default the DEFAULT_ALLOWED_PATTERNS).
      Parameters:
      patterns - the patterns to add.
      See Also:
    • getAllowedPatterns

      public Set<String> getAllowedPatterns()
      Return the current allowed patterns.
      Returns:
      an unmodifiable view of the allowed patterns.
      Since:
      7.2
    • convert

      public Object convert(byte[] source)
      Specified by:
      convert in interface Converter<byte[],Object>
    • deserialize

      protected Object deserialize(ByteArrayInputStream inputStream) throws IOException
      Throws:
      IOException
    • checkAllowList

      protected void checkAllowList(Class<?> clazz)