Skip to content

Commit

Permalink
added containing file in entities
Browse files Browse the repository at this point in the history
  • Loading branch information
wiauxb committed Aug 20, 2024
1 parent 1e99544 commit 900aa06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cwaf-ontology/src/main/java/be/uclouvain/model/Directive.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Directive implements Comparable<Directive>, Serializable {
private Stack<String> trace;
private String disabledBy;
private String type;
private String fileURI;

public Directive(CompileContext ctx, Individual resource) {

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

// Retrieve the directive's file
ctx.getInfModel().listStatements(null, OntCWAF.CONTAINS_DIRECTIVE, resource).forEachRemaining( stmt -> {
if (stmt.getSubject().hasProperty(OntCWAF.FILE_PATH)) {
this.fileURI = stmt.getSubject().getURI();
}
});

if (resource.hasOntClass(OntCWAF.MOD_SEC_RULE)) {
if (resource.hasProperty(OntCWAF.RULE_ID)) {
setId(resource.getPropertyValue(OntCWAF.RULE_ID).asLiteral().getInt());
Expand Down Expand Up @@ -191,9 +199,9 @@ public String toString() {
", ifLevel=" + ifLevel +
", location='" + (location == null ? "global" : location) + '\'' +
", virtualHost='" + (virtualHost== null ? "" : virtualHost) + '\'' +
", lineNum=" + lineNum +
", id=" + id +
", tags=" + tags +
", in " + fileURI + ":" + lineNum +
(EC == "true" ? "" : ", EC=" + EC) +
"}\t\t" + name + "\t\t(" + argsString + ")" + (disabledBy == null ? "" : " disabled by " + disabledBy);
}
Expand Down Expand Up @@ -259,6 +267,7 @@ public Individual toEntityIndividual(OntModel model) {
ind.addLiteral(OntCWAF.ARGUMENTS, String.join(" ", args));
ind.addProperty(OntCWAF.INSTANCE_OF, resource);
ind.addLiteral(OntCWAF.STACK_TRACE, trace.toString());
ind.addProperty(OntCWAF.CONTAINED_IN, fileURI);
return ind;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static OntModel parseConfig(String filePath) throws IOException {
}

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

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

0 comments on commit 900aa06

Please sign in to comment.