/** * Serializes the given object to JSON, thereby using no custom {@link StdSerializer}s. * @param _object * @return */ public static String asJsonString(final Object _object) { return JacksonUtil.asJsonString(_object, null); }
/** * Reads the configuration setting vulas.backend.artifactMaps. * @return */ private static ArtifactMaps buildMaps(String _json) { ArtifactMaps maps = new ArtifactMaps(); if(_json!=null) { maps = (ArtifactMaps)JacksonUtil.asObject(_json, ArtifactMaps.class); } return maps; }
public synchronized ConstructId[] getArtifactBugConstructsIntersection(String _qString,List<ConstructId> c, String packaging) throws BackendConnectionException{ String json = null; BasicHttpRequest bhr = new BasicHttpRequest(Service.CIA, HttpMethod.POST, PathBuilder.libConstructIdsIntersect(_qString,packaging), null); bhr.setPayload(JacksonUtil.asJsonString(c), "application/json", false); final HttpResponse response = bhr.send(); ConstructId[] intersection = null; if ( response.isOk() ){ json = response.getBody(); intersection= (ConstructId[])JacksonUtil.asObject(json, ConstructId[].class); } return intersection; }
public Space createSpace(GoalContext _goal_context, Space _space) throws BackendConnectionException { final BasicHttpRequest r = new BasicHttpRequest(HttpMethod.POST, PathBuilder.spaces(), null); r.setGoalContext(_goal_context); r.setPayload(JacksonUtil.asJsonString(_space), null, true); final HttpResponse response = r.send(); // Read and return the response to the caller (including the server-side generated space token) Space created_space = null; if(response!=null && response.isCreated()) { try { created_space = (Space)JacksonUtil.asObject(response.getBody(), Space.class); } catch (Exception e) { throw new BackendConnectionException("Cannot deseriale the newly created space: " + e.getMessage(), e); } } return created_space; }
@SuppressWarnings("unchecked") public T read(Path _path) { T object = null; if(FileUtil.isAccessibleFile(_path)) { try { final String json = FileUtil.readFile(_path); object = (T)JacksonUtil.asObject(json, this.clazz); } catch (IOException e) { log.error("Error reading from file [" + _path + "]: " + e.getMessage(), e); } catch (ClassCastException e) { log.error("Error reading from file [" + _path + "]: " + e.getMessage(), e); } catch (Exception e) { log.error("Error reading from file [" + _path + "]: " + e.getMessage(), e); } } return object; } }
public boolean write(T _object, Path _path) { boolean success = false; if(_object!=null && _path!=null) { // Serialize final String json = JacksonUtil.asJsonString(_object); // Write try { FileUtil.writeToFile(_path.toFile(), json); success = true; } catch (IOException e) { log.error("Error writing to file [" + _path + "]: " + e.getMessage(), e); } } return success; } }
public VulnerableDependency[] getVulnDeps(Boolean unconfirmedOnly) throws BackendConnectionException { final Map<String,String> params = new HashMap<String,String>(); params.put("unconfirmedOnly", unconfirmedOnly.toString()); final BasicHttpRequest req = new BasicHttpRequest(HttpMethod.GET, PathBuilder.vulnDeps(), params); final VulnerableDependency[] vulndeps = (VulnerableDependency[])JacksonUtil.asObject(req.send().getBody(), VulnerableDependency[].class); return vulndeps; }
@Override public String toJson(){ final Map<Class<?>, StdSerializer<?>> custom_serializers = new HashMap<Class<?>, StdSerializer<?>>(); custom_serializers.put(ASTConstructBodySignature.class, new ASTConstructBodySignatureSerializer()); return JacksonUtil.asJsonString(this, custom_serializers); /*StringBuilder buffer = new StringBuilder(); buffer.append("{\"ast\":[ "); if(fRoot.isRoot()){ buffer.append("{"); buildJsonElement(fRoot,buffer); if(fRoot.isLeaf()) buffer.append("}"); else{ buffer.append(",\"C\" : [" ); JSON(fRoot,buffer); buffer.append("]}"); } } buffer.append("]}"); //close off the ast array opened above return buffer.toString();*/ }
public AffectedLibrary[] getBugAffectedLibraries(String _bugId, String _source) throws BackendConnectionException { final HashMap<String, String> params = new HashMap<String, String>(); params.put("source", _source); final String json = new BasicHttpRequest(HttpMethod.GET, PathBuilder.bugAffectedLibs(_bugId), params).send().getBody(); return (AffectedLibrary[])JacksonUtil.asObject(json, AffectedLibrary[].class); }
public JsonObject toJSON(boolean _addAlsoAttackSurface){ // create GSON object with the right constructID final JsonObject rootObj = new JsonParser().parse(JacksonUtil.asJsonString(this.getConstructId())).getAsJsonObject(); // add JAR URL if(this.jarUrl!=null) rootObj.addProperty("jarUrl", this.jarUrl); // add JAR ID if(this.archiveID!=null) rootObj.addProperty("archiveID", this.archiveID); // add list if(_addAlsoAttackSurface && this.getListSize()>0){ JsonArray myArray = new JsonArray(); for(NodeMetaInformation element : this.attackSurface){ JsonObject child = element.toJSON(_addAlsoAttackSurface); myArray.add(child); } rootObj.add("attackSurface", myArray); } return rootObj; }
public Set<Dependency> getAppDeps(GoalContext _ctx, Application _app) throws BackendConnectionException { if(!cacheAppDependencies.containsKey(_app)) { final Set<Dependency> deps = new HashSet<Dependency>(); final boolean app_exists = this.isAppExisting(_ctx, _app); if(app_exists) { final String json = new BasicHttpRequest(HttpMethod.GET, PathBuilder.appDeps(_app), null) .setGoalContext(_ctx) .send() .getBody(); final Dependency[] deps_array = (Dependency[])JacksonUtil.asObject(json, Dependency[].class); deps.addAll(Arrays.asList(deps_array)); } cacheAppDependencies.put(_app, deps); BackendConnector.log.info("[" + deps.size() + "] dependencies for app " + _app + " received from backend"); } return cacheAppDependencies.get(_app); }
final Map<Class<?>, StdSerializer<?>> custom_serializers = new HashMap<Class<?>, StdSerializer<?>>(); custom_serializers.put(ASTSignatureChange.class, new ASTSignatureChangeSerializer()); return JacksonUtil.asJsonString(this, custom_serializers);
public Set<VulnerableDependency> getAppVulnDeps(GoalContext _ctx, Application _app, boolean _include_historical, boolean _include_affected, boolean _include_affected_unconfirmed) throws BackendConnectionException { final Set<VulnerableDependency> vuln_deps = new HashSet<VulnerableDependency>(); final boolean app_exists = this.isAppExisting(_ctx, _app); if(app_exists) { final String json = new BasicHttpRequest(HttpMethod.GET, PathBuilder.appVulnDeps(_app, _include_historical, _include_affected, _include_affected_unconfirmed), null) .setGoalContext(_ctx) .send() .getBody(); final VulnerableDependency[] vuln_deps_array = (VulnerableDependency[])JacksonUtil.asObject(json, VulnerableDependency[].class); vuln_deps.addAll(Arrays.asList(vuln_deps_array)); } BackendConnector.log.info("[" + vuln_deps.size() + "] vulnerable dependencies for app " + _app + " received from backend"); return vuln_deps; }
final JsonObject json_app = parser.parse(JacksonUtil.asJsonString(this.app_ctx)).getAsJsonObject(); final JsonArray json_paths = new JsonArray(); for (com.sap.psr.vulas.shared.json.model.ConstructId cid : path) { path_node_obj = new JsonObject(); path_node_obj.add("constructId", parser.parse(JacksonUtil.asJsonString(cid))); final NodeMetaInformation nmi = this.callgraph.getInformationForConstructId(cid); path_node_obj.addProperty("lib", nmi.getArchiveId());
public Set<ConstructId> getAppConstructIds(GoalContext _ctx, Application _app) throws BackendConnectionException { if(!cacheAppConstructs.containsKey(_app)) { final boolean app_exists = this.isAppExisting(_ctx, _app); final Set<ConstructId> constructs = new HashSet<ConstructId>(); if(app_exists) { final String json = new BasicHttpRequest(HttpMethod.GET, PathBuilder.appConstructIds(_app), null) .setGoalContext(_ctx) .send() .getBody(); final ConstructId[] backend_app_construct_ids = (ConstructId[])JacksonUtil.asObject(json, ConstructId[].class); for(ConstructId backend_app_construct_id: backend_app_construct_ids) { try { constructs.add(backend_app_construct_id); } catch (IllegalArgumentException e) { BackendConnector.log.error("Error while transforming backend to client entity: " + e.getMessage(), e); } } cacheAppConstructs.put(_app, constructs); BackendConnector.log.info("[" + backend_app_construct_ids.length + "] app constructs received from backend, [" + constructs.size() + "] transformed to client representation"); } } return cacheAppConstructs.get(_app); }
if (jar_url == null) jar_url = nmi.getJarUrl(); json_constructs.add(new JsonParser().parse(JacksonUtil.asJsonString(nmi.getConstructId())).getAsJsonObject()); from = touch_point.get(0); to = touch_point.get(1); json_tp.add("from", new JsonParser().parse(JacksonUtil.asJsonString(from.getConstructId())).getAsJsonObject()); json_tp.add("to", new JsonParser().parse(JacksonUtil.asJsonString(to.getConstructId())).getAsJsonObject()); json_tp.addProperty("source", this.source.toString()); if (sha1.equals(to.getArchiveId())) {
public Library[] getBugLibraries(String _bugId) throws BackendConnectionException{ final String json = new BasicHttpRequest(HttpMethod.GET, PathBuilder.bugLibraryVersions(_bugId), null).send().getBody(); final Library[] libs = (Library[])JacksonUtil.asObject(json, Library[].class); BackendConnector.log.info("Libraries for bug " + _bugId + " received from backend"); return libs; }
if ( (n++)>0 ) json.append(","); json.append("{"); json.append("\"app\":").append(JacksonUtil.asJsonString(app_ctx)).append(","); json.append("\"bug\":\"").append(bugid).append("\","); json.append("\"executionId\":\"").append(exe.getId()).append("\",");
public Artifact[] getAllArtifactsGroupArtifact(String _g, String _a) throws BackendConnectionException{ String json = null; Artifact[] result = null; json = new BasicHttpRequest(Service.CIA, HttpMethod.GET, PathBuilder.artifactsGroupVersion(_g,_a), null).send().getBody(); BackendConnector.log.info("artifacts for " + _g + ":" + _a + " received from backend"); if(json!=null) result = (Artifact[])JacksonUtil.asObject(json, Artifact[].class); return result; }
public void modifySpace(GoalContext _goal_context, Space _space) throws BackendConnectionException { final BasicHttpRequest r = new BasicHttpRequest(HttpMethod.PUT, PathBuilder.space(_space), null); r.setGoalContext(_goal_context); r.setPayload(JacksonUtil.asJsonString(_space), null, true); r.send(); }