use of com.fasterxml.jackson.databind.ObjectMapper in project spring-security by spring-projects.
the class UnmodifiableSetDeserializer method deserialize.
@Override
public Set deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = mapper.readTree(jp);
Set<Object> resultSet = new HashSet<Object>();
if (node != null) {
if (node instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) node;
Iterator<JsonNode> nodeIterator = arrayNode.iterator();
while (nodeIterator.hasNext()) {
JsonNode elementNode = nodeIterator.next();
resultSet.add(mapper.readValue(elementNode.toString(), Object.class));
}
} else {
resultSet.add(mapper.readValue(node.toString(), Object.class));
}
}
return Collections.unmodifiableSet(resultSet);
}
use of com.fasterxml.jackson.databind.ObjectMapper in project spring-security by spring-projects.
the class UsernamePasswordAuthenticationTokenDeserializer method deserialize.
/**
* This method construct {@link UsernamePasswordAuthenticationToken} object from serialized json.
* @param jp the JsonParser
* @param ctxt the DeserializationContext
* @return the user
* @throws IOException if a exception during IO occurs
* @throws JsonProcessingException if an error during JSON processing occurs
*/
@Override
public UsernamePasswordAuthenticationToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
UsernamePasswordAuthenticationToken token = null;
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode jsonNode = mapper.readTree(jp);
Boolean authenticated = readJsonNode(jsonNode, "authenticated").asBoolean();
JsonNode principalNode = readJsonNode(jsonNode, "principal");
Object principal = null;
if (principalNode.isObject()) {
principal = mapper.readValue(principalNode.toString(), new TypeReference<User>() {
});
} else {
principal = principalNode.asText();
}
Object credentials = readJsonNode(jsonNode, "credentials").asText();
List<GrantedAuthority> authorities = mapper.readValue(readJsonNode(jsonNode, "authorities").toString(), new TypeReference<List<GrantedAuthority>>() {
});
if (authenticated) {
token = new UsernamePasswordAuthenticationToken(principal, credentials, authorities);
} else {
token = new UsernamePasswordAuthenticationToken(principal, credentials);
}
token.setDetails(readJsonNode(jsonNode, "details"));
return token;
}
use of com.fasterxml.jackson.databind.ObjectMapper in project spring-security by spring-projects.
the class AbstractMixinTests method setup.
@Before
public void setup() {
mapper = new ObjectMapper();
ClassLoader loader = getClass().getClassLoader();
mapper.registerModules(SecurityJackson2Modules.getModules(loader));
}
use of com.fasterxml.jackson.databind.ObjectMapper in project keywhiz by square.
the class Printing method printSanitizedSecretWithDetails.
public void printSanitizedSecretWithDetails(SanitizedSecret secret) {
System.out.println(SanitizedSecret.displayName(secret));
SecretDetailResponse secretDetails;
try {
secretDetails = keywhizClient.secretDetailsForId(secret.id());
} catch (IOException e) {
throw Throwables.propagate(e);
}
System.out.println("\tGroups:");
secretDetails.groups.stream().sorted(Comparator.comparing(Group::getName)).forEach(g -> System.out.println(INDENT + g.getName()));
System.out.println("\tClients:");
secretDetails.clients.stream().sorted(Comparator.comparing(Client::getName)).forEach(c -> System.out.println(INDENT + c.getName()));
System.out.println("\tMetadata:");
if (!secret.metadata().isEmpty()) {
String metadata;
try {
metadata = new ObjectMapper().writeValueAsString(secret.metadata());
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
System.out.println(INDENT + metadata);
}
if (secret.expiry() > 0) {
System.out.println("\tExpiry:");
Date d = new Date(secret.expiry() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
}
if (!secret.description().isEmpty()) {
System.out.println("\tDescription:");
System.out.println(INDENT + secret.description());
}
if (!secret.createdBy().isEmpty()) {
System.out.println("\tCreated by:");
System.out.println(INDENT + secret.createdBy());
}
System.out.println("\tCreated at:");
Date d = new Date(secret.createdAt().toEpochSecond() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
if (!secret.updatedBy().isEmpty()) {
System.out.println("\tUpdated by:");
System.out.println(INDENT + secret.updatedBy());
}
System.out.println("\tUpdated at:");
d = new Date(secret.updatedAt().toEpochSecond() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
}
use of com.fasterxml.jackson.databind.ObjectMapper in project keywhiz by square.
the class Printing method printGroupWithDetails.
public void printGroupWithDetails(Group group) {
System.out.println(group.getName());
GroupDetailResponse groupDetails;
try {
groupDetails = keywhizClient.groupDetailsForId(group.getId());
} catch (IOException e) {
throw Throwables.propagate(e);
}
System.out.println("\tClients:");
groupDetails.getClients().stream().sorted(Comparator.comparing(Client::getName)).forEach(c -> System.out.println(INDENT + c.getName()));
System.out.println("\tSecrets:");
groupDetails.getSecrets().stream().sorted(Comparator.comparing(SanitizedSecret::name)).forEach(s -> System.out.println(INDENT + SanitizedSecret.displayName(s)));
System.out.println("\tMetadata:");
if (!groupDetails.getMetadata().isEmpty()) {
String metadata;
try {
metadata = new ObjectMapper().writeValueAsString(groupDetails.getMetadata());
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
System.out.println(INDENT + metadata);
}
if (!groupDetails.getDescription().isEmpty()) {
System.out.println("\tDescription:");
System.out.println(INDENT + groupDetails.getDescription());
}
if (!groupDetails.getCreatedBy().isEmpty()) {
System.out.println("\tCreated by:");
System.out.println(INDENT + groupDetails.getCreatedBy());
}
System.out.println("\tCreated at:");
Date d = new Date(groupDetails.getCreationDate().toEpochSecond() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
if (!groupDetails.getUpdatedBy().isEmpty()) {
System.out.println("\tUpdated by:");
System.out.println(INDENT + groupDetails.getUpdatedBy());
}
System.out.println("\tUpdated at:");
d = new Date(groupDetails.getUpdateDate().toEpochSecond() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
}
Aggregations