From 881cd0befbdd8625000e549c0522866d96f6f9db Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Tue, 31 Oct 2017 09:57:45 -0500 Subject: [PATCH] Fix UsernamePasswordAuthenticationTokenMixin to handle null credentials/details Resolves #4698 --- ...sswordAuthenticationTokenDeserializer.java | 23 +++++++++++++++---- ...PasswordAuthenticationTokenMixinTests.java | 17 +++++++++++++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenDeserializer.java b/core/src/main/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenDeserializer.java index 1b6ef485ac..38016abc38 100644 --- a/core/src/main/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenDeserializer.java +++ b/core/src/main/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenDeserializer.java @@ -16,6 +16,9 @@ package org.springframework.security.jackson2; +import java.io.IOException; +import java.util.List; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -24,12 +27,10 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.MissingNode; + import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.GrantedAuthority; -import java.io.IOException; -import java.util.List; - /** * Custom deserializer for {@link UsernamePasswordAuthenticationToken}. At the time of deserialization * it will invoke suitable constructor depending on the value of authenticated property. @@ -39,6 +40,7 @@ import java.util.List; * you can also registered it with your own mixin class. * * @author Jitendra Singh + * @author Greg Turnquist * @see UsernamePasswordAuthenticationTokenMixin * @since 4.2 */ @@ -65,7 +67,13 @@ class UsernamePasswordAuthenticationTokenDeserializer extends JsonDeserializer authorities = mapper.readValue( readJsonNode(jsonNode, "authorities").traverse(mapper), new TypeReference>() { }); @@ -74,7 +82,12 @@ class UsernamePasswordAuthenticationTokenDeserializer extends JsonDeserializer