Allow overriding the default validators added to attributes

Closes #27148

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
Pedro Igor 2024-02-19 18:41:31 -03:00
parent df281df669
commit 52fe8b0feb

View file

@ -167,7 +167,7 @@ public class DefaultAttributes extends HashMap<String, List<String>> implements
.map(Collections::singletonList).orElse(emptyList())); .map(Collections::singletonList).orElse(emptyList()));
metadatas.addAll(Optional.ofNullable(this.metadataByAttribute.get(READ_ONLY_ATTRIBUTE_KEY)) metadatas.addAll(Optional.ofNullable(this.metadataByAttribute.get(READ_ONLY_ATTRIBUTE_KEY))
.map(Collections::singletonList).orElse(emptyList())); .map(Collections::singletonList).orElse(emptyList()));
limitLengthOnAttributesWithNoLengthRestriction(name, metadatas); addDefaultValidators(name, metadatas);
Boolean result = null; Boolean result = null;
@ -209,11 +209,15 @@ public class DefaultAttributes extends HashMap<String, List<String>> implements
return result == null; return result == null;
} }
protected void addDefaultValidators(String name, List<AttributeMetadata> metadatas) {
addLengthValidatorIfNotSet(name, metadatas);
}
/** /**
* In case there are unmanaged attributes or attributes that don't have a length restrictions, * In case there are unmanaged attributes or attributes that don't have a length restrictions,
* add a default length restriction to avoid a denial of service by a caller. * add a default length restriction to avoid a denial of service by a caller.
*/ */
private static void limitLengthOnAttributesWithNoLengthRestriction(String name, List<AttributeMetadata> metadatas) { private void addLengthValidatorIfNotSet(String name, List<AttributeMetadata> metadatas) {
for (AttributeMetadata metadata : metadatas) { for (AttributeMetadata metadata : metadatas) {
for (AttributeValidatorMetadata validator : metadata.getValidators()) { for (AttributeValidatorMetadata validator : metadata.getValidators()) {
if (validator.getValidatorId().equals(LengthValidator.ID)) { if (validator.getValidatorId().equals(LengthValidator.ID)) {