Class BasicPolymorphicTypeValidator.Builder
- Enclosing class:
- BasicPolymorphicTypeValidator
BasicPolymorphicTypeValidator instances. Criteria for allowing
polymorphic subtypes is specified by adding rules in priority order, starting
with the rules to evaluate first: when a matching rule is found, its status
(PolymorphicTypeValidator.Validity.ALLOWED or PolymorphicTypeValidator.Validity.DENIED) is used and no further
rules are checked.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<BasicPolymorphicTypeValidator.TypeMatcher>Collected matchers for base types to allow.Optional set of base types (exact match) that are NOT accepted as base types for polymorphic properties.protected List<BasicPolymorphicTypeValidator.TypeMatcher>Collected Class-based matchers for sub types to allow.protected List<BasicPolymorphicTypeValidator.NameMatcher>Collected name-based matchers for sub types to allow. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected BasicPolymorphicTypeValidator.Builderprotected BasicPolymorphicTypeValidator.Builderprotected BasicPolymorphicTypeValidator.BuilderallowIfBaseType(Class<?> baseOfBase) Method for appending matcher that will allow all subtypes in cases where nominal base type is specified class, or one of its subtypes.allowIfBaseType(String prefixForBase) Method for appending matcher that will allow all subtypes in cases where nominal base type's class name starts with specific prefix.allowIfBaseType(Pattern patternForBase) Method for appending matcher that will allow all subtypes in cases where nominal base type's class name matches givenPatternFor example, call toMethod for appending custom matcher called with base type: if matcher returnstrue, all possible subtypes will be accepted; iffalse, other matchers are applied.allowIfSubType(Class<?> subTypeBase) Method for appending matcher that will allow specific subtype (regardless of declared base type) if it issubTypeBaseor its subtype.allowIfSubType(String prefixForSubType) Method for appending matcher that will allow specific subtype (regardless of declared base type) in cases where subclass name starts with specified prefix For example, call toallowIfSubType(Pattern patternForSubType) Method for appending matcher that will allow specific subtype (regardless of declared base type) in cases where subclass name matches givenPattern.Method for appending custom matcher called with resolved subtype: if matcher returnstrue, type will be accepted; iffalse, other matchers are applied.Method for appending matcher that will allow all subtypes that are Java arrays (regardless of element type).Method for appending matcher that will allow all subtypes for which aValueDeserializer) is explicitly provided by eitherjackson-databinditself or one of registeredJacksonModules.build()denyForExactBaseType(Class<?> baseTypeToDeny) Method for appending matcher that will mark any polymorphic properties with exact specific class to be invalid.
-
Field Details
-
_invalidBaseTypes
Optional set of base types (exact match) that are NOT accepted as base types for polymorphic properties. May be used to prevent "unsafe" base types likeObjectorSerializable. -
_baseTypeMatchers
Collected matchers for base types to allow. -
_subTypeNameMatchers
Collected name-based matchers for sub types to allow. -
_subTypeClassMatchers
Collected Class-based matchers for sub types to allow.
-
-
Constructor Details
-
Builder
protected Builder()
-
-
Method Details
-
allowIfBaseType
Method for appending matcher that will allow all subtypes in cases where nominal base type is specified class, or one of its subtypes. For example, call tobuilder.allowIfBaseType(MyBaseType.class)would indicate that any polymorphic properties where declared base type isMyBaseType(or subclass thereof) would allow all legal (assignment-compatible) subtypes. -
allowIfBaseType
Method for appending matcher that will allow all subtypes in cases where nominal base type's class name matches givenPatternFor example, call tobuilder.allowIfBaseType(Pattern.compile("com\\.mycompany\\..*")would indicate that any polymorphic properties where declared base type is in packagecom.mycompanywould allow all legal (assignment-compatible) subtypes.NOTE!
Patternmatch is applied usingif (patternForBase.matcher(typeId).matches()) { }that is, it must match the whole class name, not just part. -
allowIfBaseType
Method for appending matcher that will allow all subtypes in cases where nominal base type's class name starts with specific prefix. For example, call tobuilder.allowIfBaseType("com.mycompany.")would indicate that any polymorphic properties where declared base type is in packagecom.mycompanywould allow all legal (assignment-compatible) subtypes. -
allowIfBaseType
public BasicPolymorphicTypeValidator.Builder allowIfBaseType(BasicPolymorphicTypeValidator.TypeMatcher matcher) Method for appending custom matcher called with base type: if matcher returnstrue, all possible subtypes will be accepted; iffalse, other matchers are applied.- Parameters:
matcher- Custom matcher to apply to base type- Returns:
- This Builder to allow call chaining
-
denyForExactBaseType
Method for appending matcher that will mark any polymorphic properties with exact specific class to be invalid. For example, call tobuilder.denyforExactBaseType(Object.class)would indicate that any polymorphic properties where declared base type isjava.lang.Objectwould be deemed invalid, and attempt to deserialize values of such types should result in an exception. -
allowIfSubType
Method for appending matcher that will allow specific subtype (regardless of declared base type) if it issubTypeBaseor its subtype. For example, call tobuilder.allowIfSubType(MyImplType.class)would indicate that any polymorphic values with type of isMyImplType(or subclass thereof) would be allowed. -
allowIfSubType
Method for appending matcher that will allow specific subtype (regardless of declared base type) in cases where subclass name matches givenPattern. For example, call tobuilder.allowIfSubType(Pattern.compile("com\\.mycompany\\.")would indicate that any polymorphic values in packagecom.mycompanywould be allowed.NOTE!
Patternmatch is applied usingif (patternForSubType.matcher(typeId).matches()) { }that is, it must match the whole class name, not just part. -
allowIfSubType
Method for appending matcher that will allow specific subtype (regardless of declared base type) in cases where subclass name starts with specified prefix For example, call tobuilder.allowIfSubType("com.mycompany.")would indicate that any polymorphic values in packagecom.mycompanywould be allowed. -
allowIfSubType
public BasicPolymorphicTypeValidator.Builder allowIfSubType(BasicPolymorphicTypeValidator.TypeMatcher matcher) Method for appending custom matcher called with resolved subtype: if matcher returnstrue, type will be accepted; iffalse, other matchers are applied.- Parameters:
matcher- Custom matcher to apply to resolved subtype- Returns:
- This Builder to allow call chaining
-
allowIfSubTypeIsArray
Method for appending matcher that will allow all subtypes that are Java arrays (regardless of element type). Note that this does NOT validate element type itself as long as Polymorphic Type handling is enabled for element type: this is the case with all standard "Default Typing" inclusion criteria as well as for annotation (@JsonTypeInfo) use case (since annotation only applies to element types, not container).NOTE: not used with other Java collection types (
Lists,Collections), mostly since use of generic types as polymorphic values is not (well) supported. -
allowSubTypesWithExplicitDeserializer
Method for appending matcher that will allow all subtypes for which aValueDeserializer) is explicitly provided by eitherjackson-databinditself or one of registeredJacksonModules. Determination is implementation by callingDeserializerFactory.hasExplicitDeserializerFor(tools.jackson.databind.DatabindContext, java.lang.Class<?>).In practice this matcher should remove the need to register any standard Jackson-supported JDK types, as well as most if not all 3rd party types; leaving only POJOs and those 3rd party types that are not supported by relevant modules. In turn this should not open security holes to "gadget" types since insecure types should not be supported by datatype modules. For highest security cases (where input is untrusted) it is still preferable to add more specific allow-rules, if possible.
NOTE: Modules need to provide support for detection so if 3rd party types do not seem to be supported, Module in question may need to be updated to indicate existence of explicit deserializers.
-
build
-
_appendBaseMatcher
protected BasicPolymorphicTypeValidator.Builder _appendBaseMatcher(BasicPolymorphicTypeValidator.TypeMatcher matcher) -
_appendSubNameMatcher
protected BasicPolymorphicTypeValidator.Builder _appendSubNameMatcher(BasicPolymorphicTypeValidator.NameMatcher matcher) -
_appendSubClassMatcher
protected BasicPolymorphicTypeValidator.Builder _appendSubClassMatcher(BasicPolymorphicTypeValidator.TypeMatcher matcher)
-