1
0
mirror of synced 2026-08-04 09:17:02 +00:00

Deserialize the principal in a neutral way

When the principal of the Authentication is an object, it is not necessarily
an User: it could be another implementation of UserDetails, or even a
completely unrelated type. Since the type of the object is serialized as a
property and used by the deserialization anyway, there's no point in
enforcing a stricter type.
This commit is contained in:
Frank Pavageau
2017-03-17 16:58:04 +01:00
committed by Rob Winch
parent 6fd9ff254b
commit 35706ad60a
3 changed files with 50 additions and 4 deletions
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.List;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import com.fasterxml.jackson.core.JsonParser;
@@ -63,7 +62,7 @@ class PreAuthenticatedAuthenticationTokenDeserializer extends JsonDeserializer<P
JsonNode principalNode = readJsonNode(jsonNode, "principal");
Object principal = null;
if(principalNode.isObject()) {
principal = mapper.readValue(principalNode.traverse(mapper), new TypeReference<User>() {});
principal = mapper.readValue(principalNode.traverse(mapper), Object.class);
} else {
principal = principalNode.asText();
}