use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project jackson-core by FasterXML.
the class TestParserOverrides method testCurrentName.
public void testCurrentName() throws Exception {
JsonFactory jf = new JsonFactory();
_testCurrentName(jf, false);
_testCurrentName(jf, true);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project jackson-core by FasterXML.
the class TestJDKSerializability method testParseException.
public void testParseException() throws Exception {
JsonFactory jf = new JsonFactory();
JsonParser p = jf.createParser(" { garbage! }");
JsonParseException exc = null;
try {
p.nextToken();
p.nextToken();
fail("Should not get here");
} catch (JsonParseException e) {
exc = e;
}
p.close();
byte[] stuff = jdkSerialize(exc);
JsonParseException result = jdkDeserialize(stuff);
assertNotNull(result);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project jackson-databind by FasterXML.
the class TestGeneratorUsingMapper method testPojoWriting.
/*
/**********************************************************
/* Tests for data binding integration
/**********************************************************
*/
public void testPojoWriting() throws IOException {
JsonFactory jf = new MappingJsonFactory();
StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(sw);
gen.writeObject(new Pojo());
gen.close();
// trimming needed if main-level object has leading space
String act = sw.toString().trim();
assertEquals("{\"x\":4}", act);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project jackson-databind by FasterXML.
the class SerConfigTest method testGeneratorFeatures.
public void testGeneratorFeatures() throws Exception {
SerializationConfig config = MAPPER.getSerializationConfig();
JsonFactory f = MAPPER.getFactory();
assertFalse(config.isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII, f));
assertNotSame(config, config.with(JsonGenerator.Feature.ESCAPE_NON_ASCII));
SerializationConfig newConfig = config.withFeatures(JsonGenerator.Feature.ESCAPE_NON_ASCII, JsonGenerator.Feature.IGNORE_UNKNOWN);
assertNotSame(config, newConfig);
assertTrue(newConfig.isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII, f));
assertNotSame(config, config.without(JsonGenerator.Feature.ESCAPE_NON_ASCII));
assertNotSame(config, config.withoutFeatures(JsonGenerator.Feature.ESCAPE_NON_ASCII, JsonGenerator.Feature.IGNORE_UNKNOWN));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project midpoint by Evolveum.
the class MidpointRestSecurityQuestionsAuthenticator method createAuthenticationContext.
@Override
protected SecurityQuestionsAuthenticationContext createAuthenticationContext(AuthorizationPolicy policy, ContainerRequestContext requestCtx) {
JsonFactory f = new JsonFactory();
ObjectMapper mapper = new ObjectMapper(f);
JsonNode node = null;
try {
node = mapper.readTree(policy.getAuthorization());
} catch (IOException e) {
RestServiceUtil.createSecurityQuestionAbortMessage(requestCtx, "{" + USER_CHALLENGE + "}");
return null;
}
JsonNode userNameNode = node.findPath("user");
if (userNameNode instanceof MissingNode) {
RestServiceUtil.createSecurityQuestionAbortMessage(requestCtx, "{" + USER_CHALLENGE + "}");
return null;
}
String userName = userNameNode.asText();
policy.setUserName(userName);
JsonNode answerNode = node.findPath("answer");
if (answerNode instanceof MissingNode) {
SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("restapi", "REST", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS")));
SearchResultList<PrismObject<UserType>> users = null;
try {
users = searchUser(userName);
} finally {
SecurityContextHolder.getContext().setAuthentication(null);
}
if (users.size() != 1) {
requestCtx.abortWith(Response.status(Status.UNAUTHORIZED).header("WWW-Authenticate", "Security question authentication failed. Incorrect username and/or password").build());
return null;
}
PrismObject<UserType> user = users.get(0);
PrismContainer<SecurityQuestionAnswerType> questionAnswerContainer = user.findContainer(SchemaConstants.PATH_SECURITY_QUESTIONS_QUESTION_ANSWER);
if (questionAnswerContainer == null || questionAnswerContainer.isEmpty()) {
requestCtx.abortWith(Response.status(Status.UNAUTHORIZED).header("WWW-Authenticate", "Security question authentication failed. Incorrect username and/or password").build());
return null;
}
String questionChallenge = "";
List<SecurityQuestionDefinitionType> questions = null;
try {
SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("restapi", "REST", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS")));
questions = getQuestions(user);
} finally {
SecurityContextHolder.getContext().setAuthentication(null);
}
Collection<SecurityQuestionAnswerType> questionAnswers = questionAnswerContainer.getRealValues();
Iterator<SecurityQuestionAnswerType> questionAnswerIterator = questionAnswers.iterator();
while (questionAnswerIterator.hasNext()) {
SecurityQuestionAnswerType questionAnswer = questionAnswerIterator.next();
SecurityQuestionDefinitionType question = questions.stream().filter(q -> q.getIdentifier().equals(questionAnswer.getQuestionIdentifier())).findFirst().get();
String challenge = QUESTION.replace(Q_ID, question.getIdentifier());
questionChallenge += challenge.replace(Q_TXT, question.getQuestionText());
if (questionAnswerIterator.hasNext()) {
questionChallenge += ",";
}
}
String userChallenge = USER_CHALLENGE.replace("username", userName);
String challenge = "{" + userChallenge + ", \"answer\" : [" + questionChallenge + "]}";
RestServiceUtil.createSecurityQuestionAbortMessage(requestCtx, challenge);
return null;
}
ArrayNode answers = (ArrayNode) answerNode;
Iterator<JsonNode> answersList = answers.elements();
Map<String, String> questionAnswers = new HashMap<>();
while (answersList.hasNext()) {
JsonNode answer = answersList.next();
String questionId = answer.findPath("qid").asText();
String questionAnswer = answer.findPath("qans").asText();
questionAnswers.put(questionId, questionAnswer);
}
return new SecurityQuestionsAuthenticationContext(userName, questionAnswers);
}
Aggregations