@@ -44,6 +44,7 @@ public class Directive implements Comparable<Directive>, Serializable {
44
44
private Stack <String > trace ;
45
45
private String disabledBy ;
46
46
private String type ;
47
+ private String fileURI ;
47
48
48
49
public Directive (CompileContext ctx , Individual resource ) {
49
50
@@ -58,6 +59,13 @@ public Directive(CompileContext ctx, Individual resource) {
58
59
this .type = resource .getPropertyValue (OntCWAF .DIR_TYPE ).asLiteral ().getString ();
59
60
}
60
61
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
+
61
69
if (resource .hasOntClass (OntCWAF .MOD_SEC_RULE )) {
62
70
if (resource .hasProperty (OntCWAF .RULE_ID )) {
63
71
setId (resource .getPropertyValue (OntCWAF .RULE_ID ).asLiteral ().getInt ());
@@ -191,9 +199,9 @@ public String toString() {
191
199
", ifLevel=" + ifLevel +
192
200
", location='" + (location == null ? "global" : location ) + '\'' +
193
201
", virtualHost='" + (virtualHost == null ? "" : virtualHost ) + '\'' +
194
- ", lineNum=" + lineNum +
195
202
", id=" + id +
196
203
", tags=" + tags +
204
+ ", in " + fileURI + ":" + lineNum +
197
205
(EC == "true" ? "" : ", EC=" + EC ) +
198
206
"}\t \t " + name + "\t \t (" + argsString + ")" + (disabledBy == null ? "" : " disabled by " + disabledBy );
199
207
}
@@ -259,6 +267,7 @@ public Individual toEntityIndividual(OntModel model) {
259
267
ind .addLiteral (OntCWAF .ARGUMENTS , String .join (" " , args ));
260
268
ind .addProperty (OntCWAF .INSTANCE_OF , resource );
261
269
ind .addLiteral (OntCWAF .STACK_TRACE , trace .toString ());
270
+ ind .addProperty (OntCWAF .CONTAINED_IN , fileURI );
262
271
return ind ;
263
272
}
264
273
}
0 commit comments