Skip to content

Commit

Permalink
#1590 Fix tag property for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 13, 2020
1 parent a324406 commit fd9cca6
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 5 deletions.
16 changes: 15 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AlertCtrl @Inject() (
.get(request.organisation)
.orFail(AuthorizationError("Operation not permitted"))
richObservables <- observables.toTry(createObservable).map(_.flatten)
richAlert <- alertSrv.create(request.body("alert").toAlert, organisation, inputAlert.tags, customFields, caseTemplate)
richAlert <- alertSrv.create(inputAlert.toAlert, organisation, inputAlert.tags, customFields, caseTemplate)
_ <- auditSrv.mergeAudits(richObservables.toTry(o => alertSrv.addObservable(richAlert.alert, o)))(_ => Success(()))
createdObservables = alertSrv.get(richAlert.alert).observables.richObservable.toSeq
} yield Results.Created((richAlert -> createdObservables).toJson)
Expand Down Expand Up @@ -369,6 +369,20 @@ class PublicAlert @Inject() (
.property("lastSyncDate", UMapping.date.optional)(_.field.updatable)
.property("tags", UMapping.string.set)(
_.select(_.tags.displayName)
.filter((_, cases) =>
cases
.tags
.graphMap[String, String, Converter.Identity[String]](
{ v =>
val namespace = UMapping.string.getProperty(v, "namespace")
val predicate = UMapping.string.getProperty(v, "predicate")
val value = UMapping.string.optional.getProperty(v, "value")
Tag(namespace, predicate, value, None, 0).toString
},
Converter.identity[String]
)
)
.converter(_ => Converter.identity[String])
.custom { (_, value, vertex, _, graph, authContext) =>
alertSrv
.get(vertex)(graph)
Expand Down
14 changes: 14 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ class PublicCase @Inject() (
.property("endDate", UMapping.date.optional)(_.field.updatable)
.property("tags", UMapping.string.set)(
_.select(_.tags.displayName)
.filter((_, cases) =>
cases
.tags
.graphMap[String, String, Converter.Identity[String]](
{ v =>
val namespace = UMapping.string.getProperty(v, "namespace")
val predicate = UMapping.string.getProperty(v, "predicate")
val value = UMapping.string.optional.getProperty(v, "value")
Tag(namespace, predicate, value, None, 0).toString
},
Converter.identity[String]
)
)
.converter(_ => Converter.identity[String])
.custom { (_, value, vertex, _, graph, authContext) =>
caseSrv
.get(vertex)(graph)
Expand Down
18 changes: 16 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v0/CaseTemplateCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import org.thp.scalligraph.controllers._
import org.thp.scalligraph.models.{Database, UMapping}
import org.thp.scalligraph.query._
import org.thp.scalligraph.traversal.TraversalOps._
import org.thp.scalligraph.traversal.{IteratorOutput, Traversal}
import org.thp.scalligraph.traversal.{Converter, IteratorOutput, Traversal}
import org.thp.scalligraph.{AttributeCheckingError, BadRequestError, EntityIdOrName, RichSeq}
import org.thp.thehive.controllers.v0.Conversion._
import org.thp.thehive.dto.v0.{InputCaseTemplate, InputTask}
import org.thp.thehive.models.{CaseTemplate, Permissions, RichCaseTemplate}
import org.thp.thehive.models.{CaseTemplate, Permissions, RichCaseTemplate, Tag}
import org.thp.thehive.services.CaseTemplateOps._
import org.thp.thehive.services.OrganisationOps._
import org.thp.thehive.services.TagOps._
Expand Down Expand Up @@ -115,6 +115,20 @@ class PublicCaseTemplate @Inject() (
.property("severity", UMapping.int.optional)(_.field.updatable)
.property("tags", UMapping.string.set)(
_.select(_.tags.displayName)
.filter((_, cases) =>
cases
.tags
.graphMap[String, String, Converter.Identity[String]](
{ v =>
val namespace = UMapping.string.getProperty(v, "namespace")
val predicate = UMapping.string.getProperty(v, "predicate")
val value = UMapping.string.optional.getProperty(v, "value")
Tag(namespace, predicate, value, None, 0).toString
},
Converter.identity[String]
)
)
.converter(_ => Converter.identity[String])
.custom { (_, value, vertex, _, graph, authContext) =>
caseTemplateSrv
.get(vertex)(graph)
Expand Down
16 changes: 15 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v0/ObservableCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.thp.scalligraph.controllers._
import org.thp.scalligraph.models.{Database, UMapping}
import org.thp.scalligraph.query._
import org.thp.scalligraph.traversal.TraversalOps._
import org.thp.scalligraph.traversal.{IteratorOutput, Traversal}
import org.thp.scalligraph.traversal.{Converter, IteratorOutput, Traversal}
import org.thp.thehive.controllers.v0.Conversion._
import org.thp.thehive.dto.v0.InputObservable
import org.thp.thehive.models._
Expand Down Expand Up @@ -210,6 +210,20 @@ class PublicObservable @Inject() (
.property("sighted", UMapping.boolean)(_.field.updatable)
.property("tags", UMapping.string.set)(
_.select(_.tags.displayName)
.filter((_, cases) =>
cases
.tags
.graphMap[String, String, Converter.Identity[String]](
{ v =>
val namespace = UMapping.string.getProperty(v, "namespace")
val predicate = UMapping.string.getProperty(v, "predicate")
val value = UMapping.string.optional.getProperty(v, "value")
Tag(namespace, predicate, value, None, 0).toString
},
Converter.identity[String]
)
)
.converter(_ => Converter.identity[String])
.custom { (_, value, vertex, _, graph, authContext) =>
observableSrv
.get(vertex)(graph)
Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AlertCtrl @Inject() (
for {
organisation <- userSrv.current.organisations(Permissions.manageAlert).getOrFail("Organisation")
customFields = inputAlert.customFieldValue.map(cf => cf.name -> cf.value).toMap
richAlert <- alertSrv.create(request.body("alert").toAlert, organisation, inputAlert.tags, customFields, caseTemplate)
richAlert <- alertSrv.create(inputAlert.toAlert, organisation, inputAlert.tags, customFields, caseTemplate)
} yield Results.Created(richAlert.toJson)
}

Expand Down
56 changes: 56 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ class Properties @Inject() (
.property("lastSyncDate", UMapping.date.optional)(_.field.updatable)
.property("tags", UMapping.string.set)(
_.select(_.tags.displayName)
.filter((_, cases) =>
cases
.tags
.graphMap[String, String, Converter.Identity[String]](
{ v =>
val namespace = UMapping.string.getProperty(v, "namespace")
val predicate = UMapping.string.getProperty(v, "predicate")
val value = UMapping.string.optional.getProperty(v, "value")
Tag(namespace, predicate, value, None, 0).toString
},
Converter.identity[String]
)
)
.converter(_ => Converter.identity[String])
.custom { (_, value, vertex, _, graph, authContext) =>
alertSrv
.get(vertex)(graph)
Expand Down Expand Up @@ -101,6 +115,20 @@ class Properties @Inject() (
.property("number", UMapping.int)(_.field.readonly)
.property("tags", UMapping.string.set)(
_.select(_.tags.displayName)
.filter((_, cases) =>
cases
.tags
.graphMap[String, String, Converter.Identity[String]](
{ v =>
val namespace = UMapping.string.getProperty(v, "namespace")
val predicate = UMapping.string.getProperty(v, "predicate")
val value = UMapping.string.optional.getProperty(v, "value")
Tag(namespace, predicate, value, None, 0).toString
},
Converter.identity[String]
)
)
.converter(_ => Converter.identity[String])
.custom { (_, value, vertex, _, graph, authContext) =>
caseSrv
.get(vertex)(graph)
Expand Down Expand Up @@ -206,6 +234,20 @@ class Properties @Inject() (
.property("severity", UMapping.int.optional)(_.field.updatable)
.property("tags", UMapping.string.set)(
_.select(_.tags.displayName)
.filter((_, cases) =>
cases
.tags
.graphMap[String, String, Converter.Identity[String]](
{ v =>
val namespace = UMapping.string.getProperty(v, "namespace")
val predicate = UMapping.string.getProperty(v, "predicate")
val value = UMapping.string.optional.getProperty(v, "value")
Tag(namespace, predicate, value, None, 0).toString
},
Converter.identity[String]
)
)
.converter(_ => Converter.identity[String])
.custom { (_, value, vertex, _, graph, authContext) =>
caseTemplateSrv
.get(vertex)(graph)
Expand Down Expand Up @@ -295,6 +337,20 @@ class Properties @Inject() (
.property("sighted", UMapping.boolean)(_.field.updatable)
.property("tags", UMapping.string.set)(
_.select(_.tags.displayName)
.filter((_, cases) =>
cases
.tags
.graphMap[String, String, Converter.Identity[String]](
{ v =>
val namespace = UMapping.string.getProperty(v, "namespace")
val predicate = UMapping.string.getProperty(v, "predicate")
val value = UMapping.string.optional.getProperty(v, "value")
Tag(namespace, predicate, value, None, 0).toString
},
Converter.identity[String]
)
)
.converter(_ => Converter.identity[String])
.custom { (_, value, vertex, _, graph, authContext) =>
observableSrv
.getOrFail(vertex)(graph)
Expand Down

0 comments on commit fd9cca6

Please # to comment.