Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2222

Spring Session Redis failing to serialize OAuth2AccessToken

$
0
0

I'm trying to setup Spring session with Redis and I want data to be serialized to JSON.

This is my SessionConfig:

@Configurationpublic class SessionConfig implements BeanClassLoaderAware {    @Value("${server.session.cookie.secure}")    private Boolean useSecureCookie;    private ClassLoader loader;    @Bean    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {        return new GenericJackson2JsonRedisSerializer(objectMapper());    }    private ObjectMapper objectMapper() {        ObjectMapper mapper = new ObjectMapper();        mapper.registerModules(SecurityJackson2Modules.getModules(this.loader));        return mapper;    }    @Override    public void setBeanClassLoader(ClassLoader classLoader) {        this.loader = classLoader;    }    @Bean    public DefaultCookieSerializer cookieSerializer() {        DefaultCookieSerializer serializer = new DefaultCookieSerializer();        serializer.setCookieName("SESSION");        serializer.setCookiePath("/");        serializer.setUseSecureCookie(Optional.ofNullable(useSecureCookie).orElse(false));        return serializer;    }}

I'm getting this exception when logging in:

org.springframework.data.redis.serializer.SerializationException: Could not write JSON: Type id handling not implemented for type org.springframework.security.oauth2.common.OAuth2AccessToken (by serializer of type org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer) (through reference chain: org.springframework.security.core.context.SecurityContextImpl["authentication"]->org.springframework.security.oauth2.provider.OAuth2Authentication["userAuthentication"]->org.springframework.security.authentication.UsernamePasswordAuthenticationToken["principal"]->my.package.app.security.OAuth2Employee["accessToken"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Type id handling not implemented for type org.springframework.security.oauth2.common.OAuth2AccessToken (by serializer of type org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer) (through reference chain: org.springframework.security.core.context.SecurityContextImpl["authentication"]->org.springframework.security.oauth2.provider.OAuth2Authentication["userAuthentication"]->org.springframework.security.authentication.UsernamePasswordAuthenticationToken["principal"]->my.package.app.security.OAuth2Employee["accessToken"])

Java version 8Spring boot version is 1.5.12.RELEASESpring Session and Spring Session Data Redis versions are both 1.3.5.RELEASE

Am I missing something in configuration?


Viewing all articles
Browse latest Browse all 2222


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>