use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode 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);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project heron by twitter.
the class MarathonScheduler method getPorts.
protected ArrayNode getPorts(ObjectMapper mapper) {
ArrayNode ports = mapper.createArrayNode();
for (String portName : MarathonConstants.PORT_NAMES) {
ObjectNode port = mapper.createObjectNode();
port.put(MarathonConstants.PORT, 0);
port.put(MarathonConstants.PROTOCOL, MarathonConstants.TCP);
port.put(MarathonConstants.PORT_NAME, portName);
ports.add(port);
}
return ports;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project heron by twitter.
the class MarathonScheduler method getFetchList.
protected ArrayNode getFetchList(ObjectMapper mapper) {
String heronCoreURI = Context.corePackageUri(config);
String topologyURI = Runtime.topologyPackageUri(runtime).toString();
String[] uris = new String[] { heronCoreURI, topologyURI };
ArrayNode urisNode = mapper.createArrayNode();
for (String uri : uris) {
ObjectNode uriObject = mapper.createObjectNode();
uriObject.put(MarathonConstants.URI, uri);
uriObject.put(MarathonConstants.EXECUTABLE, false);
uriObject.put(MarathonConstants.EXTRACT, true);
uriObject.put(MarathonConstants.CACHE, false);
urisNode.add(uriObject);
}
return urisNode;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project asterixdb by apache.
the class ARecordType method toJSON.
@Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
type.put("type", ARecordType.class.getName());
type.put("name", typeName);
if (isOpen) {
type.put("open", true);
} else {
type.put("open", false);
}
ArrayNode fields = om.createArrayNode();
for (int i = 0; i < fieldNames.length; i++) {
ObjectNode field = om.createObjectNode();
field.set(fieldNames[i], fieldTypes[i].toJSON());
fields.add(field);
}
type.set("fields", fields);
return type;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project asterixdb by apache.
the class AUnionType method toJSON.
@Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
type.put("type", AUnionType.class.getName());
ArrayNode fields = om.createArrayNode();
Iterator<IAType> iter = unionList.iterator();
if (iter.hasNext()) {
IAType t0 = iter.next();
fields.add(t0.toJSON());
while (iter.hasNext()) {
fields.add(iter.next().toJSON());
}
}
type.set("fields", fields);
return type;
}
Aggregations