-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add Jackson 3 support and deprecate Jackson 2 one #17832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Sébastien Deleuze <sdeleuze@users.noreply.github.com>
This commit adds support for Jackson 3 which has the following major differences with the Jackson 2 one: - jackson subpackage instead of jackson2 - Jackson type prefix instead of Jackson2 - JsonMapper instead of ObjectMapper - For configuration, JsonMapper.Builder instead of ObjectMapper since the latter is now immutable - AllowlistTypeResolverBuilder in new a public type in order to be used easily with the JsonMapper.Builder API Jackson 3 changes compared to Jackson 2 are documented on FasterXML/jackson-future-ideas#72. Signed-off-by: Sébastien Deleuze <sdeleuze@users.noreply.github.com>
Signed-off-by: Sébastien Deleuze <sdeleuze@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request. Generally, I think this is looking good. I've provided some feedback inline.
It also appears that there are still some classes that need migrated. Searching for jackson on main should give you a complete list of classes that are using jackson.
For example, webauthn has jackson support. I'm guessing this was missed because it is inconsistent with the rest of the jackson support in that it is in a jackson package rather than jackson2. It is also automatically registered because it does not use default types which would make it insecure.
There are also some tests that still use ObjectMapper
or deprecated Spring Framework Jackson 2 classes (e.g. JwtDecodersTests.java#L388). Unless the test is specifically for the Jackson 2 support, we should update these to use non-deprecated classes (e.g. JsonMapper
).
There are various Spring framework jackson based classes that have been deprecated that we should migrate away from. For example, MappingJackson2HttpMessageConverter
usage (e.g. WebAuthnAuthenticationFilter.converter) should be migrated to JacksonJsonHttpMessageConverter
if jackson 3 is on the classpath. Likely there could be a static factory method used that Spring Security uses to obtain the correct default json converter instance.
|
||
@Override | ||
public void setupModule(SetupContext context) { | ||
((MapperBuilder<?, ?>) context.getOwner()).setDefaultTyping(new AllowlistTypeResolverBuilder()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach appears to create a new instance of AllowlistTypeResolverBuilder
for every module. Is that necessary or do we only want a single instance?
* @author Hyunmin Choi | ||
* @since 7.0 | ||
*/ | ||
abstract class AbstractUnmodifiableCollectionDeserializer<T> extends ValueDeserializer<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is better built in support for unmodifiable collections now?
* @author Rob Winch | ||
* @since 7.0 | ||
*/ | ||
public class AllowlistTypeResolverBuilder extends DefaultTypeResolverBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that this is now public vs being encapsulated as it is for the Jackson 2 support?
* @author Rob Winch | ||
* @since 7.0 | ||
*/ | ||
public class AllowlistTypeResolverBuilder extends DefaultTypeResolverBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that now is a good time for Spring Security to stop using global default typing.
While the AllowlistTypeResolverBuilder
worked well as a security patch in the Jackson 2 support, I think that we should remove it for Jackson 3 support and better align with best practices with Jackson. Instead, I think that we should use https://github.com/FasterXML/jackson-docs/wiki/JacksonPolymorphicDeserialization#12-per-class-annotations This would mean that users would need to take the risk of enabling global default typing or opt into default typing per type.
I'd like to ensure that we have a test that verifies that a custom type does not just work after applying Spring Security's module. Another test would verify that users could add their own type. The docs would be updated to explain that global default typing is off, why it is off, and how they can add their own types.
|
||
@Override | ||
public void setupModule(SetupContext context) { | ||
// TODO Is it expected that default typing in not configured in the Jackson 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not expected, but please see my comment about no longer enabling global default typing.
@@ -50,6 +54,7 @@ public Saml2Jackson2Module() { | |||
|
|||
@Override | |||
public void setupModule(SetupContext context) { | |||
// TODO Is it expected that default typing in not configured here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not expected, but please see my comment about no longer enabling global default typing.
This PR adds support for Jackson 3 which has the following major differences with the Jackson 2 one:
jackson
subpackage instead ofjackson2
Jackson
type prefix instead ofJackson2
JsonMapper
instead ofObjectMapper
JsonMapper.Builder
instead ofObjectMapper
since the latter is now immutableAllowlistTypeResolverBuilder
in new a public type in order to be used easily with theJsonMapper.Builder
APIJackson 3 changes compared to Jackson 2 are documented on FasterXML/jackson-future-ideas#72.
It also deprecates Jackson 2 support for removal.
There are TODO comments in
SamlJacksonModule
andSaml2JacksonModule
to review.