spring-projects / spring-projects/spring-security

The class with java.sql.Timestamp is not whitelisted.

Open
#6,601 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Summary

Hi. In my project i use spring session with redis to store our session and share it. due to reasons we decided to use json serialization instead of jdk serialization. here is configuration for this based on spring session sample app.

@Configuration
public class SessionConfig implements BeanClassLoaderAware {

	private ClassLoader loader;

	@Bean
	public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
		return new GenericJackson2JsonRedisSerializer(objectMapper());
	}

	/**
	 * Customized {@link ObjectMapper} to add mix-in for class that doesn't have default
	 * constructors
	 *
	 * @return the {@link ObjectMapper} to use
	 */
	private ObjectMapper objectMapper() {
		ObjectMapper mapper = new ObjectMapper();
                SecurityJackson2Modules.enableDefaultTyping(mapper);
		mapper.registerModules(SecurityJackson2Modules.getModules(this.loader));
		return mapper;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang
	 * .ClassLoader)
	 */
	@Override
	public void setBeanClassLoader(ClassLoader classLoader) {
		this.loader = classLoader;
	}
}

But i get following error.

com.fasterxml.jackson.databind.JsonMappingException: The class with java.sql.Timestamp and name of java.sql.Timestamp is not whitelisted. If you believe this class is safe to deserialize, please provide an explicit mapping using Jackson annotations or by providing a Mixin. If the serialization is only done by a trusted source, you can also enable default typing. See https://github.com/spring-projects/spring-security/issues/4370 for details (through reference chain: org.springframework.security.core.context.SecurityContextImpl["authentication"]->org.baharan.framework.model.security.User["lastVisitDate"])

The thing is that lastVisitDate field type is Date. its not Timestamp. i appreciate it if you help me in this. thanks in advance.

Version

Spring Boot 2.1.1.RELEASE

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the SessionConfig objectMapper setup, focusing on SecurityJackson2Modules and the springSessionDefaultRedisSerializer path. Trace how User.lastVisitDate is serialized and why its runtime type is reported as java.sql.Timestamp; done means the Date/Timestamp whitelist behavior and a suitable resolution are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis, spring
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.