Search in sources :

Example 16 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project eap-additional-testsuite by jboss-set.

the class JaxbProviderDeserializationSecurityCheckTestCase method testApplicationContext.

@Test
public void testApplicationContext() throws Exception {
    String result = performCall("rest/jaxb/appcontext");
    try {
        BogusApplicationContext jaxbModel = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false).readValue(result, BogusApplicationContext.class);
        Assert.fail("Should prevente json deserialization because of security reasons.");
    } catch (JsonMappingException e) {
        Assert.assertTrue("Should prevente json deserialization because of security reasons.", e.getMessage().contains("Illegal type"));
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) BogusApplicationContext(org.springframework.jacksontest.BogusApplicationContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ATTest(org.jboss.eap.additional.testsuite.annotations.ATTest) Test(org.junit.Test)

Example 17 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project eap-additional-testsuite by jboss-set.

the class SecurityDeserializationTestCase method testSecuirtyDatabind3.

@Test
@Ignore
public void testSecuirtyDatabind3() throws Exception {
    final String JSON = aposToQuotes("{'v':['java.rmi.server.UnicastRemoteObject','/tmp/foobar.txt']}");
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping();
    try {
        PolyWrapper sc = mapper.readValue(JSON, PolyWrapper.class);
        fail("Should not be able to deserialize because of security prevention.");
    } catch (JsonMappingException e) {
        assertTrue("Fail because of security issues...", e.getMessage().contains("prevented for security reasons"));
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project BIMserver by opensourceBIM.

the class DownloadDescriptor method getCacheKey.

public String getCacheKey() {
    Hasher hasher = hf.newHasher();
    // TODO This serializerOid actually makes the cache a per-user cache... Maybe not the most useful feature
    hasher.putLong(serializerOid);
    for (long roid : roids) {
        hasher.putLong(roid);
    }
    if (jsonQuery != null) {
        // TODO This is based on the incoming JSON (if there is any), this should be replaced at some point by a canonical-form
        hasher.putString(jsonQuery, Charsets.UTF_8);
        HashCode hashcode = hasher.hash();
        return hashcode.toString();
    } else {
        // TODO This does not work because the toJson function is not complete
        ObjectNode json = new JsonQueryObjectModelConverter(packageMetaData).toJson(query);
        try {
            StringWriter stringWriter = new StringWriter();
            OBJECT_MAPPER.writeValue(stringWriter, json);
            System.out.println(query.toString());
            hasher.putString(stringWriter.toString(), Charsets.UTF_8);
            HashCode hashcode = hasher.hash();
            return hashcode.toString();
        } catch (JsonGenerationException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StringWriter(java.io.StringWriter) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException)

Example 19 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project BIMserver by opensourceBIM.

the class JsonQueryObjectModelConverter method getDefineFromFile.

// TODO thread safety and cache invalidation on file updates
public Include getDefineFromFile(String includeName) throws QueryException {
    Include include = CACHED_DEFINES.get(includeName);
    if (include != null) {
        return include;
    }
    String namespaceString = includeName.substring(0, includeName.indexOf(":"));
    String singleIncludeName = includeName.substring(includeName.indexOf(":") + 1);
    URL resource;
    try {
        resource = getClass().getClassLoader().loadClass("org.bimserver.database.queries.StartFrame").getResource("json/" + namespaceString + ".json");
        if (resource == null) {
            throw new QueryException("Could not find '" + namespaceString + "' namespace in predefined queries");
        }
    } catch (ClassNotFoundException e1) {
        throw new QueryException("Could not find '" + namespaceString + "' namespace in predefined queries");
    }
    OBJECT_MAPPER.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    try {
        ObjectNode predefinedQuery = OBJECT_MAPPER.readValue(resource, ObjectNode.class);
        JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(packageMetaData);
        Query query = converter.parseJson(namespaceString, predefinedQuery);
        Include define = query.getDefine(singleIncludeName);
        if (define == null) {
            throw new QueryException("Could not find '" + singleIncludeName + "' in defines in namespace " + query.getName());
        }
        CACHED_DEFINES.put(includeName, define);
        return define;
    } catch (JsonParseException e) {
        throw new QueryException(e);
    } catch (JsonMappingException e) {
        throw new QueryException(e);
    } catch (IOException e) {
        throw new QueryException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) URL(java.net.URL)

Example 20 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project BIMserver by opensourceBIM.

the class GetNrPrimitivesDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
    if (packageMetaData == null) {
        throw new UserException("Schema not fond");
    }
    try {
        Query query = new Query("test", packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(packageMetaData.getEClassIncludingDependencies("GeometryInfo"), true);
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), bimServer, query, java.util.Collections.singleton(roid), packageMetaData);
        HashMapVirtualObject next = queryObjectProvider.next();
        long totalPrimitives = 0;
        while (next != null) {
            int nrPrimitives = (int) next.get("primitiveCount");
            totalPrimitives += nrPrimitives;
            next = queryObjectProvider.next();
        }
        return totalPrimitives;
    } catch (QueryException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : OldQuery(org.bimserver.database.OldQuery) Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)147 IOException (java.io.IOException)75 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)62 JsonParseException (com.fasterxml.jackson.core.JsonParseException)53 Test (org.junit.Test)28 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)23 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 File (java.io.File)14 Map (java.util.Map)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 InputStream (java.io.InputStream)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 List (java.util.List)7 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 Test (org.junit.jupiter.api.Test)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)5