Search in sources :

Example 1 with MissingNode

use of com.fasterxml.jackson.databind.node.MissingNode in project azure-sdk-for-java by Azure.

the class LinuxDiskVolumeEncryptionMonitorImpl method osDiskStatus.

@Override
public EncryptionStatus osDiskStatus() {
    if (!hasEncryptionExtension()) {
        return EncryptionStatus.NOT_ENCRYPTED;
    }
    final JsonNode subStatusNode = instanceViewFirstSubStatus();
    if (subStatusNode == null) {
        return EncryptionStatus.UNKNOWN;
    }
    JsonNode diskNode = subStatusNode.path("os");
    if (diskNode instanceof MissingNode) {
        return EncryptionStatus.UNKNOWN;
    }
    return EncryptionStatus.fromString(diskNode.asText());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode)

Example 2 with MissingNode

use of com.fasterxml.jackson.databind.node.MissingNode 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 3 with MissingNode

use of com.fasterxml.jackson.databind.node.MissingNode in project XRTB by benmfaul.

the class BidRequest method getNativeAdAssetIndex.

/**
 * Returns the asset id in the bid request of the requested index
 *
 * @param type String. The type of asset
 * @param subtype String. sub type of the asset
 * @param value int. The integer representation of the entity.
 * @return int. Returns the index in the asset object. If not found, returns
 *         -1
 */
public int getNativeAdAssetIndex(String type, String subtype, int value) {
    JsonNode nat = rootNode.path("imp");
    if (nat == null || nat.isArray() == false)
        return -1;
    ArrayNode array = (ArrayNode) nat;
    JsonNode node = array.get(0).path("native").path("assets");
    ArrayNode nodes = (ArrayNode) node;
    for (int i = 0; i < nodes.size(); i++) {
        JsonNode asset = nodes.get(i);
        JsonNode n = asset.path(type);
        JsonNode id = asset.path("id");
        if (n instanceof MissingNode == false) {
            if (subtype != null) {
                n = n.path(subtype);
                if (n != null) {
                    if (n.intValue() == value)
                        return id.intValue();
                }
            } else {
                return id.intValue();
            }
        }
    }
    return -1;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 4 with MissingNode

use of com.fasterxml.jackson.databind.node.MissingNode in project XRTB by benmfaul.

the class BidRequest method setup.

/**
 * Sets up the database of values of the JSON, from the mapped keys in the
 * campaigns. THis traverses the JSON once, and stores the required values
 * needed by campaigns once.
 *
 * @throws Exception
 *             on JSON processing errors.
 */
protected void setup() throws Exception {
    id = rootNode.path("id").textValue();
    if (id == null) {
        throw new Exception("Required field 'id' is missing or wrong type");
    }
    IntNode in = null;
    Object test = null;
    // a fast way to keep up
    StringBuilder item = new StringBuilder("id");
    // Im looking for
    try {
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            List list = mapp.get(key);
            if (list.size() != 0)
                compileList(key, list);
        }
        // ////////////////////////////////////////////////////////////////////
        if ((test = getNode("site.id")) != null)
            siteId = ((TextNode) test).textValue();
        else {
            test = getNode("app.id");
            if (test != null) {
                siteId = ((TextNode) test).textValue();
            }
        }
        if ((test = getNode("site.domain")) != null)
            siteDomain = ((TextNode) test).textValue();
        else {
            test = getNode("app.domain");
            if (test != null) {
                siteDomain = ((TextNode) test).textValue();
            }
        }
        // ///////////////
        if (siteDomain != null && blackList != null) {
            if (blackList.contains(siteDomain)) {
                blackListed = true;
                return;
            }
        }
        if ((test = getNode("site.name")) != null)
            siteName = ((TextNode) test).textValue();
        else {
            test = getNode("app.name");
            if (test != null) {
                siteName = ((TextNode) test).textValue();
            }
        }
        // //////////////// Fill in pageurl info ////////////////
        if ((test = getNode("site.content.url")) != null) {
            pageurl = ((TextNode) test).textValue();
        } else if ((test = getNode("site.page")) != null) {
            pageurl = ((TextNode) test).textValue();
        } else {
            test = getNode("app.content.url");
            if (test != null) {
                pageurl = ((TextNode) test).textValue();
            }
        }
        if ((test = database.get("device.geo.lat")) != null && test instanceof MissingNode == false) {
            try {
                lat = getDoubleFrom(test);
                test = database.get("device.geo.lon");
                if (test != null)
                    lon = getDoubleFrom(test);
            } catch (Exception error) {
            }
        }
        // ////////////////////////////////////////////////////////////////
        // 
        // Handle the impressions
        // 
        ArrayNode imps = (ArrayNode) rootNode.get("imp");
        impressions = new ArrayList();
        for (int i = 0; i < imps.size(); i++) {
            JsonNode obj = imps.get(i);
            Impression imp = new Impression(rootNode, obj);
            impressions.add(imp);
        }
        handleRtb4FreeExtensions();
    } catch (Exception error) {
        // This is an error in the protocol
        error.printStackTrace();
        if (Configuration.isInitialized() == false)
            return;
        // error.printStackTrace();
        // String str = rootNode.toString();
        // System.out.println(str);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        error.printStackTrace(pw);
        String str = sw.toString();
        String[] lines = str.split("\n");
        StringBuilder sb = new StringBuilder();
        sb.append("Abmormal processing of bid ");
        sb.append(id);
        sb.append(", ");
        if (lines.length > 0)
            sb.append(lines[0]);
        if (lines.length > 1)
            sb.append(lines[1]);
        logger.debug("BidRequest:setup():error: {}", sb.toString());
    }
}
Also used : ArrayList(java.util.ArrayList) TextNode(com.fasterxml.jackson.databind.node.TextNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntNode(com.fasterxml.jackson.databind.node.IntNode) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PrintWriter(java.io.PrintWriter)

Example 5 with MissingNode

use of com.fasterxml.jackson.databind.node.MissingNode in project XRTB by benmfaul.

the class Impression method doVideo.

/**
 * Handle the video impression.
 */
void doVideo() {
    JsonNode test;
    JsonNode rvideo = rnode.get("video");
    test = rvideo.get("w");
    if (test != null) {
        w = test.intValue();
        test = rvideo.get("h");
        if (test != null)
            h = test.intValue();
    }
    video = new Video();
    test = rvideo.get("linearity");
    if (test != null && !(test instanceof MissingNode)) {
        video.linearity = test.intValue();
    }
    test = rvideo.get("minduration");
    if (test != null && !(test instanceof MissingNode)) {
        video.minduration = test.intValue();
    }
    test = rvideo.get("maxduration");
    if (test != null && !(test instanceof MissingNode)) {
        video.maxduration = test.intValue();
    }
    test = rvideo.get("protocol");
    if (test != null && !(test instanceof MissingNode)) {
        video.protocol.add(test.intValue());
    }
    test = rvideo.get("protocols");
    if (test != null && !(test instanceof MissingNode)) {
        ArrayNode array = (ArrayNode) test;
        for (JsonNode member : array) {
            video.protocol.add(member.intValue());
        }
    }
    test = rvideo.get("mimes");
    if (test != null && !(test instanceof MissingNode)) {
        ArrayNode array = (ArrayNode) test;
        for (JsonNode member : array) {
            video.mimeTypes.add(member.textValue());
        }
    }
    nativead = false;
}
Also used : NativeVideo(com.xrtb.nativeads.creative.NativeVideo) JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

MissingNode (com.fasterxml.jackson.databind.node.MissingNode)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)8 TextNode (com.fasterxml.jackson.databind.node.TextNode)5 IntNode (com.fasterxml.jackson.databind.node.IntNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)2 NativeVideo (com.xrtb.nativeads.creative.NativeVideo)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SecurityQuestionsAuthenticationContext (com.evolveum.midpoint.model.api.context.SecurityQuestionsAuthenticationContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 SecurityQuestionAnswerType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType)1 SecurityQuestionDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionDefinitionType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 BinaryNode (com.fasterxml.jackson.databind.node.BinaryNode)1 BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)1