Skip to content

Commit 900aa06

Browse files
committed
added containing file in entities
1 parent 1e99544 commit 900aa06

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

cwaf-ontology/src/main/java/be/uclouvain/model/Directive.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class Directive implements Comparable<Directive>, Serializable {
4444
private Stack<String> trace;
4545
private String disabledBy;
4646
private String type;
47+
private String fileURI;
4748

4849
public Directive(CompileContext ctx, Individual resource) {
4950

@@ -58,6 +59,13 @@ public Directive(CompileContext ctx, Individual resource) {
5859
this.type = resource.getPropertyValue(OntCWAF.DIR_TYPE).asLiteral().getString();
5960
}
6061

62+
// Retrieve the directive's file
63+
ctx.getInfModel().listStatements(null, OntCWAF.CONTAINS_DIRECTIVE, resource).forEachRemaining( stmt -> {
64+
if (stmt.getSubject().hasProperty(OntCWAF.FILE_PATH)) {
65+
this.fileURI = stmt.getSubject().getURI();
66+
}
67+
});
68+
6169
if (resource.hasOntClass(OntCWAF.MOD_SEC_RULE)) {
6270
if (resource.hasProperty(OntCWAF.RULE_ID)) {
6371
setId(resource.getPropertyValue(OntCWAF.RULE_ID).asLiteral().getInt());
@@ -191,9 +199,9 @@ public String toString() {
191199
", ifLevel=" + ifLevel +
192200
", location='" + (location == null ? "global" : location) + '\'' +
193201
", virtualHost='" + (virtualHost== null ? "" : virtualHost) + '\'' +
194-
", lineNum=" + lineNum +
195202
", id=" + id +
196203
", tags=" + tags +
204+
", in " + fileURI + ":" + lineNum +
197205
(EC == "true" ? "" : ", EC=" + EC) +
198206
"}\t\t" + name + "\t\t(" + argsString + ")" + (disabledBy == null ? "" : " disabled by " + disabledBy);
199207
}
@@ -259,6 +267,7 @@ public Individual toEntityIndividual(OntModel model) {
259267
ind.addLiteral(OntCWAF.ARGUMENTS, String.join(" ", args));
260268
ind.addProperty(OntCWAF.INSTANCE_OF, resource);
261269
ind.addLiteral(OntCWAF.STACK_TRACE, trace.toString());
270+
ind.addProperty(OntCWAF.CONTAINED_IN, fileURI);
262271
return ind;
263272
}
264273
}

cwaf-ontology/src/main/java/be/uclouvain/service/Parser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public static OntModel parseConfig(String filePath) throws IOException {
4242
}
4343

4444
private static Individual parseConfigFile(String filePath, OntModel model, Bag file_bag) throws IOException{
45-
//TODO handle "\" for multiline directives
4645

4746
//Check if file is already in the bag
4847
for (Iterator<RDFNode> i = file_bag.iterator(); i.hasNext();) {

0 commit comments

Comments
 (0)