Skip to content

OAuth2AuthorizationServerJacksonModule should not override type validator configuration in SecurityJacksonModules #18102

@aspan

Description

@aspan

The OAuth2AuthorizationServerJacksonModule creates its own polymorphic type validator overriding the type validator created in SecurityJacksonModules.

Affects jackson3 support in 7.0.0-RC1

The following code should be removed from OAuth2AuthorizationServerJacksonModule.

		BasicPolymorphicTypeValidator.Builder builder = BasicPolymorphicTypeValidator.builder();
		this.configurePolymorphicTypeValidator(builder);
		((MapperBuilder<?, ?>) context.getOwner()).activateDefaultTyping(builder.build(), DefaultTyping.NON_FINAL,
				JsonTypeInfo.As.PROPERTY);

After removing the type validator I had to create the module and a type validator so the same type validator is used throughout the Jackson configuration.

    @Bean
    JsonMapperBuilderCustomizer jsonMapperBuilderCustomizer() {
        return new JsonMapperBuilderCustomizer() {
            @Override
            public void customize(@NonNull Builder jsonMapperBuilder) {
                BasicPolymorphicTypeValidator.Builder builder = BasicPolymorphicTypeValidator.builder();
                var oAuth2AuthorizationServerJacksonModule = new OAuth2AuthorizationServerJacksonModule();
                oAuth2AuthorizationServerJacksonModule.configurePolymorphicTypeValidator(builder);
                jsonMapperBuilder.addModules(SecurityJacksonModules.getModules(getClass().getClassLoader(), builder))
                                 .addModules(oAuth2AuthorizationServerJacksonModule);
            }
        };
    }

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions