1
0
mirror of synced 2026-08-03 00:37:03 +00:00

JSON UserDetails deserializes null

JSON UserDetails null use to be treated as "".

This changes null to be treated as a null

Issue gh-3736
This commit is contained in:
Rob Winch
2016-09-01 15:01:13 -05:00
parent 3fb77f3b59
commit df613ed4cc
3 changed files with 23 additions and 9 deletions
@@ -58,12 +58,18 @@ class UserDeserializer extends JsonDeserializer<User> {
JsonNode jsonNode = mapper.readTree(jp);
Set<GrantedAuthority> authorities = mapper.convertValue(jsonNode.get("authorities"), new TypeReference<Set<SimpleGrantedAuthority>>() {
});
return new User(
readJsonNode(jsonNode, "username").asText(), readJsonNode(jsonNode, "password").asText(""),
JsonNode password = readJsonNode(jsonNode, "password");
User result = new User(
readJsonNode(jsonNode, "username").asText(), password.asText(""),
readJsonNode(jsonNode, "enabled").asBoolean(), readJsonNode(jsonNode, "accountNonExpired").asBoolean(),
readJsonNode(jsonNode, "credentialsNonExpired").asBoolean(),
readJsonNode(jsonNode, "accountNonLocked").asBoolean(), authorities
);
if(password.asText(null) == null) {
result.eraseCredentials();
}
return result;
}
private JsonNode readJsonNode(JsonNode jsonNode, String field) {
@@ -80,8 +80,8 @@ public class UserDeserializerTests extends AbstractMixinTests {
User user = mapper.readValue(userJsonWithoutPasswordString, User.class);
assertThat(user).isNotNull();
assertThat(user.getUsername()).isEqualTo("admin");
assertThat(user.getPassword()).isEqualTo("");
assertThat(user.getAuthorities()).hasSize(0);
assertThat(user.getPassword()).isNull();
assertThat(user.getAuthorities()).isEmpty();
assertThat(user.isEnabled()).isEqualTo(true);
}