Search in sources :

Example 76 with ArrayNode

use of 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 77 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project fastjson by alibaba.

the class Bug_0_Test method f_jackson.

private void f_jackson() throws Exception {
    long startNano = System.nanoTime();
    for (int i = 0; i < COUNT; ++i) {
        ObjectMapper mapper = new ObjectMapper();
        ArrayNode node = (ArrayNode) mapper.readTree(text);
        JsonNode head = node.get(0);
        JsonNode body = node.get(1);
    }
    long nano = System.nanoTime() - startNano;
    System.out.println(NumberFormat.getInstance().format(nano));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 78 with ArrayNode

use of 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 79 with ArrayNode

use of 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 80 with ArrayNode

use of 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)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)277 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)167 JsonNode (com.fasterxml.jackson.databind.JsonNode)97 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)57 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)27 Test (org.junit.Test)25 Deployment (org.activiti.engine.test.Deployment)23 StringEntity (org.apache.http.entity.StringEntity)20 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)19 Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)18 IOException (java.io.IOException)16 Map (java.util.Map)16 HttpPost (org.apache.http.client.methods.HttpPost)16 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)14 Task (org.activiti.engine.task.Task)13 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)10 TextNode (com.fasterxml.jackson.databind.node.TextNode)8 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)7 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)7