AVRO-4189: [java] Simplify the setting of the serializable classes#3525
AVRO-4189: [java] Simplify the setting of the serializable classes#3525RyanSkraba merged 4 commits intoapache:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the class security validation mechanism in Apache Avro by introducing a new ClassSecurityValidator utility that centralizes and simplifies how trusted classes and packages are configured. The change allows using package-level whitelisting instead of requiring explicit enumeration of every class, reducing configuration verbosity.
Key Changes:
- Introduced
ClassSecurityValidatorclass with a builder pattern and predicate-based validation - Added support for
org.apache.avro.SERIALIZABLE_PACKAGESsystem property to whitelist entire packages - Migrated validation logic from
SpecificDatumReaderto the centralizedClassSecurityValidator
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lang/java/avro/src/main/java/org/apache/avro/util/ClassSecurityValidator.java | New utility class implementing the centralized class security validation with builder pattern and system property support |
| lang/java/avro/src/main/java/org/apache/avro/util/ClassUtils.java | Updated to use the new ClassSecurityValidator and load classes without initialization for security validation |
| lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java | Refactored to delegate security validation to ClassSecurityValidator and deprecated old validation methods |
| lang/java/avro/src/test/java/org/apache/avro/util/TestClassSecurityValidator.java | New test class covering various validation scenarios including builder, predicates, and composite validators |
| lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificRecordWithUnion.java | Added test to verify SecurityException is thrown for untrusted classes |
| lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectDatumReader.java | Added test to verify SecurityException is thrown for untrusted classes during reflection |
| lang/java/avro/pom.xml | Updated system properties to use package whitelisting instead of individual class enumeration |
| lang/java/avro/src/it/pom.xml | Updated system properties to use package whitelisting instead of individual class enumeration |
| lang/java/ipc/pom.xml | Updated system properties to use package whitelisting instead of individual class enumeration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
Outdated
Show resolved
Hide resolved
lang/java/avro/src/main/java/org/apache/avro/util/ClassUtils.java
Outdated
Show resolved
Hide resolved
lang/java/avro/src/main/java/org/apache/avro/util/ClassSecurityValidator.java
Outdated
Show resolved
Hide resolved
RyanSkraba
left a comment
There was a problem hiding this comment.
This LGTM -- I'm pretty confident in this implementation (and it has improved readability in what it's doing). We should definitely cherry-pick this to 1.11.x as well.
| } | ||
| if (c == null) { | ||
| throw new ClassNotFoundException("Failed to load class" + className); | ||
| throw new ClassNotFoundException("Failed to load class " + className); |
|
Cherry-picked to branch-1.12. |
|
Cherry-picked to branch-1.11 |
|
@martin-g, thanks for pushing/cherry-picking my change. I've cherry-picked to 1.11 as well. Then, I've realized, there is a branch called Also, may we have new releases with this change from 1.11 and 1.12? |
|
Credits go to @RyanSkraba ! @opwvhk Which branch should be used for 1.11.x ? |
|
I don't know about the |
What is the purpose of the change
(For example: This pull request improves file read performance by buffering data, fixing AVRO-XXXX.)
Verifying this change
(Please pick one of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Documentation