List of usage examples for org.jdom2.output XMLOutputter outputString
public final String outputString(EntityRef entity)
From source file:org.fiware.cybercaptor.server.rest.RestJsonAPI.java
License:Open Source License
/** * Simulate the remediation id_remediation of the path id, and compute the new attack graph * * @param request the HTTP Request * @param id the identifier of the attack path for which the remediations will be computed * @param id_remediation the identifier of the remediation to simulate * @return the HTTP Response/* w ww .j a v a 2s . c o m*/ */ @GET @Path("attack_path/{id}/remediation/{id-remediation}") @Produces(MediaType.APPLICATION_JSON) public Response simulateRemediationInAttackGraph(@Context HttpServletRequest request, @PathParam("id") int id, @PathParam("id-remediation") int id_remediation) throws Exception { Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring")); Database db = ((Database) request.getSession(true).getAttribute("database")); if (monitoring == null) { return RestApplication.returnErrorMessage(request, "The monitoring object is empty. Did you forget to " + "initialize it ?"); } if (db == null) { return RestApplication.returnErrorMessage(request, "The database object is empty. Did you forget to " + "initialize it ?"); } int numberAttackPaths = monitoring.getAttackPathList().size(); if (id >= numberAttackPaths) { return RestApplication.returnErrorMessage(request, "The attack path " + id + " does not exist. There are only" + numberAttackPaths + " attack paths (0 to " + (numberAttackPaths - 1) + ")"); } List<DeployableRemediation> remediations = monitoring.getAttackPathList().get(id).getDeployableRemediations( monitoring.getInformationSystem(), db.getConn(), monitoring.getPathToCostParametersFolder()); int numberRemediations = remediations.size(); if (id_remediation >= numberRemediations) { return RestApplication.returnErrorMessage(request, "The remediation " + id_remediation + " does not exist. There are only" + numberRemediations + " remediations (0 to " + (numberRemediations - 1) + ")"); } DeployableRemediation deployableRemediation = remediations.get(id_remediation); AttackGraph simulatedAttackGraph; try { simulatedAttackGraph = monitoring.getAttackGraph().clone(); for (int i = 0; i < deployableRemediation.getActions().size(); i++) { Vertex vertexToDelete = deployableRemediation.getActions().get(i).getRemediationAction() .getRelatedVertex(); simulatedAttackGraph.deleteVertex(simulatedAttackGraph.vertices.get(vertexToDelete.id)); } AttackPathManagement.scoreAttackPaths(simulatedAttackGraph, monitoring.getAttackGraph().getNumberOfVertices()); Element attackGraphXML = simulatedAttackGraph.toDomElement(); XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(attackGraphXML))); } catch (Exception e) { e.printStackTrace(); } return RestApplication.returnErrorMessage(request, "Error during the simulation of the remediation."); }
From source file:org.fiware.cybercaptor.server.rest.RestJsonAPI.java
License:Open Source License
/** * Get the whole attack graph// w ww.j a v a2 s . com * * @param request the HTTP Request * @return the HTTP Response */ @GET @Path("attack_graph") @Produces(MediaType.APPLICATION_JSON) public Response getAttackGraph(@Context HttpServletRequest request) { Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring")); if (monitoring == null) { return RestApplication.returnErrorMessage(request, "The monitoring object is empty. Did you forget to " + "initialize it ?"); } Element attackGraphXML = monitoring.getAttackGraph().toDomElement(); XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(attackGraphXML))); }
From source file:org.fiware.cybercaptor.server.rest.RestJsonConfiguration.java
License:Open Source License
/** * Get the global cost parameters/* ww w.j av a 2 s. c o m*/ * * @param request the HTTP Request * @return the HTTP Response */ @GET @Path("/remediation-cost-parameters/global") @Produces(MediaType.APPLICATION_JSON) public Response getGlobalCostParameters(@Context HttpServletRequest request) { String costParametersFolderPath = ProjectProperties.getProperty("cost-parameters-path"); GlobalParameters globalParameters = new GlobalParameters(); try { globalParameters.loadFromXMLFile(costParametersFolderPath + "/" + GlobalParameters.FILE_NAME); } catch (Exception e) { return RestApplication.returnErrorMessage(request, "The global parameters " + "can not be load: " + e.getMessage()); } XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(globalParameters.toDomElement()))); }
From source file:org.fiware.cybercaptor.server.rest.RestJsonConfiguration.java
License:Open Source License
/** * Generic function to build the HTTP Reponse for operational cost parameters (snort rule, firewall rule, patch...) * * @param request the HTTP Request * @param costParameterFileName the filename of the file to get * @return the HTTP response//w w w .java2 s. com */ private Response buildResponseForOperationalCostParameters(HttpServletRequest request, String costParameterFileName) { String costParametersFolderPath = ProjectProperties.getProperty("cost-parameters-path"); OperationalCostParameters operationalCostParameters = new OperationalCostParameters(); try { operationalCostParameters.loadFromXMLFile(costParametersFolderPath + "/" + costParameterFileName); } catch (Exception e) { return RestApplication.returnErrorMessage(request, "The operational cost parameters " + "can not be load: " + e.getMessage()); } XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(operationalCostParameters.toDomElement()))); }
From source file:org.fnppl.opensdx.keyserverfe.ActiveUser.java
License:Open Source License
private static String buildSessionXml(Hashtable<String, Object> hash) { Element e = new Element("sessiondata"); Enumeration<String> en = hash.keys(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); Object value = hash.get(key); if (value instanceof String) { e.addContent((new Element(key)).setText((String) value)); } else if (value instanceof Long) { e.addContent((new Element(key)).setText("" + value)); } else if (value instanceof Boolean) { e.addContent((new Element(key)).setText("" + value)); } else if (value instanceof Integer) { e.addContent((new Element(key)).setText("" + value)); } else if (value instanceof Element) { Element ke = (Element) ((Element) value).clone(); ke.setName(key);//dirty?! e.addContent(ke);//from w w w .j a va 2 s . com } } org.jdom2.output.XMLOutputter xout = new org.jdom2.output.XMLOutputter(); return xout.outputString(e); }
From source file:org.fnppl.opensdx.keyserverfe.Helper.java
License:Open Source License
public static String buildSessionXml(Hashtable hash) { Element e = new Element("sessiondata"); Enumeration en = hash.keys(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); Object value = hash.get(key); if (value instanceof String) { e.addContent((new Element(key)).setText((String) value)); }/*from w ww .j a v a 2s. c om*/ } org.jdom2.output.XMLOutputter xout = new org.jdom2.output.XMLOutputter(); return xout.outputString(e); }
From source file:org.fnppl.opensdx.keyserverfe.MyAction.java
License:Open Source License
public final static String getStringXML(Element e, String encoding) { org.jdom2.output.Format f = org.jdom2.output.Format.getCompactFormat(); f.setEncoding(encoding);/*from ww w.j av a 2s . c o m*/ XMLOutputter xout = new XMLOutputter(f); return xout.outputString(e); }
From source file:org.fnppl.opensdx.keyserverfe.MyAction.java
License:Open Source License
public final static String getCuteXML(Element e) { org.jdom2.output.Format f = org.jdom2.output.Format.getPrettyFormat(); f.setEncoding("UTF-8"); XMLOutputter xout = new XMLOutputter(f); return xout.outputString(e); }
From source file:org.fnppl.opensdx.xml.Document.java
License:Open Source License
public byte[] toByteArray() { try {//from w w w .j av a 2 s . c o m Format f = Format.getPrettyFormat(); f.setEncoding("UTF-8"); XMLOutputter outp = new XMLOutputter(f); return outp.outputString(base).getBytes("UTF-8"); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.graphwalker.StatisticsManager.java
License:Open Source License
public String getCurrentStatisticXml() { XMLOutputter outputter = new XMLOutputter(); return outputter.outputString(getCurrentStatistic()); }