From bc0f84ed159fec19f34cce07ebeb15d938f6ba68 Mon Sep 17 00:00:00 2001 From: To-om Date: Thu, 2 Jul 2020 08:56:21 +0200 Subject: [PATCH] #1404 Add debug and missing config --- .../services/IntegrityCheckActor.scala | 7 +++- .../org/thp/thehive/services/UserSrv.scala | 20 +++++++---- thehive/conf/reference.conf | 34 +++++++++++-------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala b/thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala index ce1fc463ed..208c9db491 100644 --- a/thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala +++ b/thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala @@ -11,7 +11,7 @@ import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models.{Database, Schema} import org.thp.scalligraph.services.{GenIntegrityCheckOps, IntegrityCheckOps} import org.thp.thehive.GuiceAkkaExtension -import play.api.Configuration +import play.api.{Configuration, Logger} import scala.collection.JavaConverters._ import scala.collection.immutable @@ -27,6 +27,7 @@ class IntegrityCheckActor() extends Actor { case class Check(name: String) import IntegrityCheckActor._ + lazy val logger: Logger = Logger(getClass) lazy val injector: Injector = GuiceAkkaExtension(context.system).injector lazy val configuration: Configuration = injector.getInstance(classOf[Configuration]) lazy val integrityCheckOps: immutable.Set[IntegrityCheckOps[_ <: Product]] = injector @@ -63,9 +64,11 @@ class IntegrityCheckActor() extends Actor { override def receive: Receive = receive(Map.empty) def receive(states: Map[String, (Boolean, Cancellable)]): Receive = { case EntityAdded(name) => + logger.debug(s"An entity $name has been created") context.system.scheduler.scheduleOnce(initialDelay(name), self, NeedCheck(name))(context.system.dispatcher) () case NeedCheck(name) if !states.contains(name) => // initial check + logger.debug(s"Initial integrity check of $name") check(name) val timer = context.system.scheduler.scheduleAtFixedRate(Duration.Zero, interval(name), self, Check(name))(context.system.dispatcher) context.become(receive(states + (name -> (false -> timer)))) @@ -75,10 +78,12 @@ class IntegrityCheckActor() extends Actor { context.become(receive(states + (name -> (true -> timer)))) } case Check(name) if states.get(name).fold(false)(_._1) => // stats.needCheck == true + logger.debug(s"Integrity check of $name") check(name) val timer = states(name)._2 context.become(receive(states + (name -> (false -> timer)))) case Check(name) => + logger.debug(s"Pause integrity checks of $name, wait new add") states(name)._2.cancel() context.become(receive(states - name)) } diff --git a/thehive/app/org/thp/thehive/services/UserSrv.scala b/thehive/app/org/thp/thehive/services/UserSrv.scala index 6a144ce71b..754941b494 100644 --- a/thehive/app/org/thp/thehive/services/UserSrv.scala +++ b/thehive/app/org/thp/thehive/services/UserSrv.scala @@ -320,12 +320,20 @@ class UserIntegrityCheckOps @Inject() ( override def initialCheck()(implicit graph: Graph, authContext: AuthContext): Unit = { super.initialCheck() - for { - adminUser <- service.getOrFail(User.init.login) - adminProfile <- profileSrv.getOrFail(Profile.admin.name) - adminOrganisation <- organisationSrv.getOrFail(Organisation.administration.name) - _ <- roleSrv.create(adminUser, adminOrganisation, adminProfile) - } yield () + val adminUserIsCreated = service + .get(User.init.login) + .role + .filter(_.profile.getByName(Profile.admin.name)) + .organisation + .getByName(Organisation.administration.name) + .exists() + if (!adminUserIsCreated) + for { + adminUser <- service.getOrFail(User.init.login) + adminProfile <- profileSrv.getOrFail(Profile.admin.name) + adminOrganisation <- organisationSrv.getOrFail(Organisation.administration.name) + _ <- roleSrv.create(adminUser, adminOrganisation, adminProfile) + } yield () () } diff --git a/thehive/conf/reference.conf b/thehive/conf/reference.conf index 5b3bc075c8..c1570c2c6d 100644 --- a/thehive/conf/reference.conf +++ b/thehive/conf/reference.conf @@ -112,33 +112,37 @@ For user {{user.login}} } integrityCheck { - profile { + default { initialDelay: 1 minute interval: 10 minutes } + profile { + initialDelay: 10 seconds + interval: 1 minutes + } organisation { - initialDelay: 1 minute - interval: 10 minutes + initialDelay: 30 seconds + interval: 1 minutes } tag { - initialDelay: 1 minute - interval: 10 minutes + initialDelay: 5 minute + interval: 30 minutes } user { - initialDelay: 1 minute - interval: 10 minutes + initialDelay: 30 seconds + interval: 1 minutes } impactStatus { - initialDelay: 1 minute - interval: 10 minutes + initialDelay: 30 seconds + interval: 1 minutes } resolutionStatus { - initialDelay: 1 minute - interval: 10 minutes + initialDelay: 30 seconds + interval: 1 minutes } observableType { - initialDelay: 1 minute - interval: 10 minutes + initialDelay: 30 seconds + interval: 1 minutes } customField { initialDelay: 1 minute @@ -149,8 +153,8 @@ integrityCheck { interval: 10 minutes } data { - initialDelay: 1 minute - interval: 10 minutes + initialDelay: 5 minute + interval: 30 minutes } case { initialDelay: 1 minute