Skip to content

Commit

Permalink
#1708 Add serializer for integrity check messages
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Dec 11, 2020
1 parent f087c2f commit d0ce48c
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CaseSrv @Inject() (

override def createEntity(e: Case)(implicit graph: Graph, authContext: AuthContext): Try[Case with Entity] =
super.createEntity(e).map { `case` =>
integrityCheckActor ! IntegrityCheckActor.EntityAdded("Case")
integrityCheckActor ! EntityAdded("Case")
`case`
}

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/CaseTemplateSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CaseTemplateSrv @Inject() (
startTraversal.getByName(name)

override def createEntity(e: CaseTemplate)(implicit graph: Graph, authContext: AuthContext): Try[CaseTemplate with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("CaseTemplate")
integrityCheckActor ! EntityAdded("CaseTemplate")
super.createEntity(e)
}

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/CustomFieldSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CustomFieldSrv @Inject() (auditSrv: AuditSrv, organisationSrv: Organisatio
) extends VertexSrv[CustomField] {

override def createEntity(e: CustomField)(implicit graph: Graph, authContext: AuthContext): Try[CustomField with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("CustomField")
integrityCheckActor ! EntityAdded("CustomField")
super.createEntity(e)
}

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/DataSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DataSrv @Inject() (@Named("integrity-check-actor") integrityCheckActor: Ac
extends VertexSrv[Data] {
override def createEntity(e: Data)(implicit graph: Graph, authContext: AuthContext): Try[Data with Entity] =
super.createEntity(e).map { data =>
integrityCheckActor ! IntegrityCheckActor.EntityAdded("Data")
integrityCheckActor ! EntityAdded("Data")
data
}

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/ImpactStatusSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ImpactStatusSrv @Inject() (@Named("integrity-check-actor") integrityCheckA
startTraversal.getByName(name)

override def createEntity(e: ImpactStatus)(implicit graph: Graph, authContext: AuthContext): Try[ImpactStatus with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("ImpactStatus")
integrityCheckActor ! EntityAdded("ImpactStatus")
super.createEntity(e)
}

Expand Down
10 changes: 3 additions & 7 deletions thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import scala.collection.immutable
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.util.Success

object IntegrityCheckActor {
case class EntityAdded(name: String)
}
sealed trait IntegrityCheckMessage
case class EntityAdded(name: String) extends IntegrityCheckMessage

class IntegrityCheckActor() extends Actor {
case class NeedCheck(name: String)
case class Check(name: String)
import IntegrityCheckActor._

lazy val logger: Logger = Logger(getClass)
lazy val injector: Injector = GuiceAkkaExtension(context.system).injector
Expand All @@ -44,10 +42,8 @@ class IntegrityCheckActor() extends Actor {
def interval(name: String): FiniteDuration =
configuration.getOptional[FiniteDuration](s"integrityCheck.$name.interval").getOrElse(defaultInitalDelay)

lazy val integrityCheckMap: Map[String, IntegrityCheckOps[_]] = {

lazy val integrityCheckMap: Map[String, IntegrityCheckOps[_]] =
integrityCheckOps.map(d => d.name -> d).toMap
}
def check(name: String): Unit = integrityCheckMap.get(name).foreach(_.check())

override def preStart(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.thp.thehive.services

import akka.serialization.Serializer

import java.io.NotSerializableException

class IntegrityCheckSerializer extends Serializer {
override def identifier: Int = -604584588

override def includeManifest: Boolean = false

override def toBinary(o: AnyRef): Array[Byte] =
o match {
case EntityAdded(name) => 0.toByte +: name.getBytes
case _ => throw new NotSerializableException
}

override def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef =
bytes(0) match {
case 0 => EntityAdded(new String(bytes.tail))
case _ => throw new NotSerializableException
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ObservableTypeSrv @Inject() (@Named("integrity-check-actor") integrityChec
override def exists(e: ObservableType)(implicit graph: Graph): Boolean = startTraversal.getByName(e.name).exists

override def createEntity(e: ObservableType)(implicit graph: Graph, authContext: AuthContext): Try[ObservableType with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("ObservableType")
integrityCheckActor ! EntityAdded("ObservableType")
super.createEntity(e)
}

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/OrganisationSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OrganisationSrv @Inject() (
val organisationShareSrv = new EdgeSrv[OrganisationShare, Organisation, Share]

override def createEntity(e: Organisation)(implicit graph: Graph, authContext: AuthContext): Try[Organisation with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("Organisation")
integrityCheckActor ! EntityAdded("Organisation")
super.createEntity(e)
}

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/ProfileSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProfileSrv @Inject() (
lazy val orgAdmin: Profile with Entity = db.roTransaction(graph => getOrFail(EntityName(Profile.orgAdmin.name))(graph)).get

override def createEntity(e: Profile)(implicit graph: Graph, authContext: AuthContext): Try[Profile with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("Profile")
integrityCheckActor ! EntityAdded("Profile")
super.createEntity(e)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ResolutionStatusSrv @Inject() (@Named("integrity-check-actor") integrityCh
startTraversal.getByName(name)

override def createEntity(e: ResolutionStatus)(implicit graph: Graph, authContext: AuthContext): Try[ResolutionStatus with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("Resolution")
integrityCheckActor ! EntityAdded("Resolution")
super.createEntity(e)
}

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/TagSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TagSrv @Inject() (appConfig: ApplicationConfig, @Named("integrity-check-ac
}

override def createEntity(e: Tag)(implicit graph: Graph, authContext: AuthContext): Try[Tag with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("Tag")
integrityCheckActor ! EntityAdded("Tag")
super.createEntity(e)
}

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/UserSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UserSrv @Inject() (
val userAttachmentSrv = new EdgeSrv[UserAttachment, User, Attachment]

override def createEntity(e: User)(implicit graph: Graph, authContext: AuthContext): Try[User with Entity] = {
integrityCheckActor ! IntegrityCheckActor.EntityAdded("User")
integrityCheckActor ! EntityAdded("User")
super.createEntity(e)
}

Expand Down

0 comments on commit d0ce48c

Please sign in to comment.