Skip to content

Logging in via oauth2 using redis session throws jackson error #3510

Open

Description

@msosa

Describe the bug
When I attempt to login via oauth 2 using redis sessions I get this jackson error

org.springframework.data.redis.serializer.SerializationException: Could not read JSON:Could not resolve type id 'java.net.URL' as a subtype of `java.lang.Object`: Configured `PolymorphicTypeValidator` (of type `tools.jackson.databind.jsontype.BasicPolymorphicTypeValidator`) denied resolution
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); byte offset: #1988] (through reference chain: org.springframework.security.core.context.SecurityContextImpl["authentication"]->org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken["principal"]->org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser["authorities"]->java.util.HashSet[0]->org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority["idToken"]->org.springframework.security.oauth2.core.oidc.OidcIdToken["claims"]->java.util.LinkedHashMap["iss"])

the error location of the json in redis appears to be here

          "iss": [
            "java.net.URL",
            "https://accounts.google.com"
          ],

I am using the documentation code for 4.0.1-SNAPSHOT

Sample

Here is a link to the sample. To set it up add your oauth2 details to application.yml, start up spring boot and attempt to login

Activity

  1. bilak commented on Mar 3, 2026

    @bilak

    I'm facing the same issue currently. Were you able to fix/workaround it?

    I have config like this:

    @Configuration
    @EnableRedisIndexedWebSession
    public class RedisSessionConfig implements BeanClassLoaderAware {
    
        private ClassLoader loader;
    
        @Bean
        RedisSerializer<Object> springSessionDefaultRedisSerializer() {
            return new GenericJacksonJsonRedisSerializer(objectMapper());
        }
    
        private ObjectMapper objectMapper() {
            return JsonMapper.builder()
                .addModules(SecurityJacksonModules.getModules(this.loader))
                .build();
        }
    
        @Override
        public void setBeanClassLoader(final ClassLoader classLoader) {
            this.loader = classLoader;
        }
    
        @Bean
        ConfigureReactiveRedisAction configureRedisAction(final Environment environment) {
            if (environment.matchesProfiles("dragonfly")) {
                return new DragonflyConfigureNotifyKeyspaceEventsAction();
            } else {
                return new ConfigureNotifyKeyspaceEventsReactiveAction();
            }
        }
    
    }
  2. bilak commented on Mar 3, 2026

    @bilak

    Hmm and quickly found a solution adding BasicPolymorphicTypeValidator

    private ObjectMapper objectMapper() {
            final BasicPolymorphicTypeValidator.Builder typeValidatorBuilder =
                BasicPolymorphicTypeValidator.builder()
                    .allowIfSubType(Object.class);
            
            return JsonMapper.builder()
                .addModules(SecurityJacksonModules.getModules(this.loader, typeValidatorBuilder))
                .build();
        }
  3. czp3009 commented on Apr 8, 2026

    @czp3009

    I've encountered the same problem, it seems that the URL type was omitted after Spring Session was migrated to Jackson 3.

    The URL was present in the AllowlistTypeIdResolver of Jackson 2 in older versions, but was lost during the migration to Jackson 3.

    The URL type is used in the iss field of the OIDC token, so it's currently broken.

    A more precise and secure method for adding URL types:

    BasicPolymorphicTypeValidator.Builder ptvBuilder = BasicPolymorphicTypeValidator.builder()
                    .allowIfSubType(URL.class);
  4. ievgen-kapinos commented on Apr 11, 2026

    @ievgen-kapinos

    @bilak Thank you man 🙏

  5. msosa commented on Apr 15, 2026

    @msosa
    Author

    I created a new bug in spring security which is where I now think this bug belongs. If their team confirms I will close this one in favor of the new one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions