Search in sources :

Example 31 with ArrayNode

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);
}
Also used : SecurityQuestionDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionDefinitionType) HashMap(java.util.HashMap) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) IOException(java.io.IOException) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) PrismObject(com.evolveum.midpoint.prism.PrismObject) SecurityQuestionsAuthenticationContext(com.evolveum.midpoint.model.api.context.SecurityQuestionsAuthenticationContext) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SecurityQuestionAnswerType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 32 with ArrayNode

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 33 with ArrayNode

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 34 with ArrayNode

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 35 with ArrayNode

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)979 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)542 JsonNode (com.fasterxml.jackson.databind.JsonNode)402 Test (org.junit.Test)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)125 ArrayList (java.util.ArrayList)110 IOException (java.io.IOException)93 Map (java.util.Map)74 HashMap (java.util.HashMap)68 List (java.util.List)50 TextNode (com.fasterxml.jackson.databind.node.TextNode)38 Test (org.testng.annotations.Test)35 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)30 HashSet (java.util.HashSet)30 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)25 Deployment (org.activiti.engine.test.Deployment)23 File (java.io.File)22 InputStream (java.io.InputStream)20 Iterator (java.util.Iterator)20 StringEntity (org.apache.http.entity.StringEntity)20