From 36b82a148801fd0b797d3b818c96a87387968415 Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 5 Jan 2021 14:15:09 +0100 Subject: [PATCH] #1731 Database initialisation refactoring --- .../connector/cortex/CortexModule.scala | 7 ++-- .../cortex/controllers/v0/ActionCtrl.scala | 4 +-- .../controllers/v0/AnalyzerTemplateCtrl.scala | 2 +- .../controllers/v0/CortexQueryExecutor.scala | 4 +-- .../cortex/controllers/v0/JobCtrl.scala | 2 +- .../cortex/controllers/v0/ResponderCtrl.scala | 2 +- .../models/CortexSchemaDefinition.scala | 3 ++ .../connector/cortex/services/ActionSrv.scala | 2 +- .../cortex/services/AnalyzerTemplateSrv.scala | 2 +- .../connector/cortex/services/JobSrv.scala | 2 +- .../cortex/services/ResponderSrv.scala | 2 +- .../cortex/services/ServiceHelper.scala | 2 +- .../controllers/v0/AnalyzerCtrlTest.scala | 4 --- .../v0/AnalyzerTemplateCtrlTest.scala | 4 --- .../cortex/controllers/v0/JobCtrlTest.scala | 1 - .../cortex/services/ActionSrvTest.scala | 1 - .../cortex/services/AnalyzerSrvTest.scala | 1 - .../cortex/services/JobSrvTest.scala | 1 - .../cortex/services/ResponderSrvTest.scala | 1 - .../cortex/services/ServiceHelperTest.scala | 1 - .../thehive/migration/th4/NoAuditSrv.scala | 10 +++--- .../thp/thehive/migration/th4/Output.scala | 33 ++++++++++--------- .../misp/controllers/v0/MispCtrl.scala | 2 +- .../misp/services/MispImportSrv.scala | 11 ++++--- .../app/org/thp/thehive/ClusterSetup.scala | 7 ++++ .../app/org/thp/thehive/TheHiveModule.scala | 14 ++++---- .../thp/thehive/controllers/dav/Router.scala | 3 +- .../thehive/controllers/v0/AlertCtrl.scala | 5 +-- .../controllers/v0/AttachmentCtrl.scala | 2 +- .../thehive/controllers/v0/AuditCtrl.scala | 6 ++-- .../controllers/v0/AuthenticationCtrl.scala | 2 +- .../thp/thehive/controllers/v0/CaseCtrl.scala | 4 +-- .../controllers/v0/CaseTemplateCtrl.scala | 2 +- .../thehive/controllers/v0/ConfigCtrl.scala | 2 +- .../controllers/v0/CustomFieldCtrl.scala | 2 +- .../controllers/v0/DashboardCtrl.scala | 2 +- .../thehive/controllers/v0/DescribeCtrl.scala | 4 +-- .../thp/thehive/controllers/v0/ListCtrl.scala | 2 +- .../thp/thehive/controllers/v0/LogCtrl.scala | 2 +- .../controllers/v0/ObservableCtrl.scala | 4 +-- .../controllers/v0/ObservableTypeCtrl.scala | 2 +- .../controllers/v0/OrganisationCtrl.scala | 2 +- .../thp/thehive/controllers/v0/PageCtrl.scala | 2 +- .../thehive/controllers/v0/ProfileCtrl.scala | 2 +- .../thehive/controllers/v0/ShareCtrl.scala | 4 +-- .../thehive/controllers/v0/StatsCtrl.scala | 2 +- .../thehive/controllers/v0/StatusCtrl.scala | 2 +- .../thehive/controllers/v0/StreamCtrl.scala | 2 +- .../thp/thehive/controllers/v0/TagCtrl.scala | 30 ++++++++--------- .../thp/thehive/controllers/v0/TaskCtrl.scala | 2 +- .../controllers/v0/TheHiveQueryExecutor.scala | 2 +- .../thp/thehive/controllers/v0/UserCtrl.scala | 4 +-- .../thehive/controllers/v1/AlertCtrl.scala | 2 +- .../thehive/controllers/v1/AuditCtrl.scala | 2 +- .../controllers/v1/AuthenticationCtrl.scala | 2 +- .../controllers/v1/CaseTemplateCtrl.scala | 2 +- .../controllers/v1/CustomFieldCtrl.scala | 3 +- .../thehive/controllers/v1/DescribeCtrl.scala | 6 ++-- .../thp/thehive/controllers/v1/LogCtrl.scala | 2 +- .../controllers/v1/ObservableCtrl.scala | 2 +- .../controllers/v1/ObservableTypeCtrl.scala | 2 +- .../controllers/v1/OrganisationCtrl.scala | 2 +- .../thehive/controllers/v1/ProfileCtrl.scala | 2 +- .../thehive/controllers/v1/Properties.scala | 2 +- .../thp/thehive/controllers/v1/TaskCtrl.scala | 2 +- .../controllers/v1/TheHiveQueryExecutor.scala | 2 +- .../thp/thehive/controllers/v1/UserCtrl.scala | 2 +- .../org/thp/thehive/services/AlertSrv.scala | 2 +- .../thp/thehive/services/AttachmentSrv.scala | 2 +- .../org/thp/thehive/services/AuditSrv.scala | 6 ++-- .../org/thp/thehive/services/CaseSrv.scala | 3 +- .../thehive/services/CaseTemplateSrv.scala | 5 ++- .../thp/thehive/services/ConfigContext.scala | 4 +-- .../org/thp/thehive/services/ConfigSrv.scala | 2 +- .../thp/thehive/services/CustomFieldSrv.scala | 5 ++- .../thp/thehive/services/DashboardSrv.scala | 2 +- .../org/thp/thehive/services/DataSrv.scala | 5 ++- .../thehive/services/ImpactStatusSrv.scala | 5 ++- .../thp/thehive/services/KeyValueSrv.scala | 2 +- .../thehive/services/LocalKeyAuthSrv.scala | 4 +-- .../services/LocalPasswordAuthSrv.scala | 5 ++- .../thp/thehive/services/LocalUserSrv.scala | 2 +- .../app/org/thp/thehive/services/LogSrv.scala | 2 +- .../thp/thehive/services/ObservableSrv.scala | 2 -- .../thehive/services/ObservableTypeSrv.scala | 5 ++- .../thehive/services/OrganisationSrv.scala | 5 ++- .../org/thp/thehive/services/PageSrv.scala | 3 +- .../org/thp/thehive/services/ProfileSrv.scala | 5 ++- .../thp/thehive/services/ReportTagSrv.scala | 2 +- .../services/ResolutionStatusSrv.scala | 5 ++- .../org/thp/thehive/services/RoleSrv.scala | 6 ++-- .../org/thp/thehive/services/ShareSrv.scala | 8 +++-- .../org/thp/thehive/services/StreamSrv.scala | 6 ++-- .../thp/thehive/services/TOTPAuthSrv.scala | 4 +-- .../app/org/thp/thehive/services/TagSrv.scala | 4 +-- .../org/thp/thehive/services/TaskSrv.scala | 2 +- .../org/thp/thehive/services/UserSrv.scala | 4 +-- .../notification/NotificationActor.scala | 2 +- .../test/org/thp/thehive/TestAppBuilder.scala | 2 -- .../controllers/v0/StreamCtrlTest.scala | 5 +-- 100 files changed, 186 insertions(+), 198 deletions(-) diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/CortexModule.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/CortexModule.scala index ccbdf83079..66d37ae178 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/CortexModule.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/CortexModule.scala @@ -2,10 +2,10 @@ package org.thp.thehive.connector.cortex import com.google.inject.AbstractModule import net.codingwell.scalaguice.{ScalaModule, ScalaMultibinder} -import org.thp.scalligraph.models.{Database, Schema} +import org.thp.scalligraph.models.{Schema, UpdatableSchema} import org.thp.scalligraph.query.QueryExecutor import org.thp.thehive.connector.cortex.controllers.v0.{CortexQueryExecutor => CortexQueryExecutorV0} -import org.thp.thehive.connector.cortex.models.{CortexSchemaDefinition, DatabaseProvider} +import org.thp.thehive.connector.cortex.models.CortexSchemaDefinition import org.thp.thehive.connector.cortex.services.notification.notifiers.{RunAnalyzerProvider, RunResponderProvider} import org.thp.thehive.connector.cortex.services.{Connector, CortexActor} import org.thp.thehive.services.notification.notifiers.NotifierProvider @@ -24,14 +24,13 @@ class CortexModule(environment: Environment, configuration: Configuration) exten queryExecutorBindings.addBinding.to[CortexQueryExecutorV0] val connectorBindings = ScalaMultibinder.newSetBinder[TheHiveConnector](binder) connectorBindings.addBinding.to[Connector] - val schemaBindings = ScalaMultibinder.newSetBinder[Schema](binder) + val schemaBindings = ScalaMultibinder.newSetBinder[UpdatableSchema](binder) schemaBindings.addBinding.to[CortexSchemaDefinition] val notifierBindings = ScalaMultibinder.newSetBinder[NotifierProvider](binder) notifierBindings.addBinding.to[RunResponderProvider] notifierBindings.addBinding.to[RunAnalyzerProvider] - bind[Database].annotatedWithName("with-thehive-cortex-schema").toProvider[DatabaseProvider] bindActor[CortexActor]("cortex-actor") () } diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ActionCtrl.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ActionCtrl.scala index 5e3da7c817..9a744a7610 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ActionCtrl.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ActionCtrl.scala @@ -26,7 +26,7 @@ import scala.reflect.runtime.{universe => ru} @Singleton class ActionCtrl @Inject() ( override val entrypoint: Entrypoint, - @Named("with-thehive-schema") override val db: Database, + override val db: Database, actionSrv: ActionSrv, entityHelper: EntityHelper, caseSrv: CaseSrv, @@ -76,7 +76,7 @@ class ActionCtrl @Inject() ( } @Singleton -class PublicAction @Inject() (actionSrv: ActionSrv, @Named("with-thehive-schema") db: Database) extends PublicData { +class PublicAction @Inject() (actionSrv: ActionSrv, db: Database) extends PublicData { override val entityName: String = "action" override val initialQuery: Query = diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerTemplateCtrl.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerTemplateCtrl.scala index 8dea87e972..d4b06c51e3 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerTemplateCtrl.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerTemplateCtrl.scala @@ -26,7 +26,7 @@ import scala.util.{Failure, Success} @Singleton class AnalyzerTemplateCtrl @Inject() ( override val entrypoint: Entrypoint, - @Named("with-thehive-cortex-schema") override val db: Database, + override val db: Database, analyzerTemplateSrv: AnalyzerTemplateSrv, @Named("v0") override val queryExecutor: QueryExecutor, override val publicData: PublicAnalyzerTemplate diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/CortexQueryExecutor.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/CortexQueryExecutor.scala index 6231600670..dd243580ef 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/CortexQueryExecutor.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/CortexQueryExecutor.scala @@ -19,8 +19,8 @@ import org.thp.thehive.services.ObservableOps._ import scala.reflect.runtime.{universe => ru} @Singleton -class CortexQueryExecutor @Inject() ( - @Named("with-thehive-cortex-schema") implicit override val db: Database, +class CortexQueryExecutor @Inject() (implicit + override val db: Database, job: PublicJob, report: PublicAnalyzerTemplate, action: PublicAction, diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala index e844845d15..f426992bcf 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrl.scala @@ -25,7 +25,7 @@ import scala.concurrent.{ExecutionContext, Future} @Singleton class JobCtrl @Inject() ( override val entrypoint: Entrypoint, - @Named("with-thehive-cortex-schema") override val db: Database, + override val db: Database, jobSrv: JobSrv, observableSrv: ObservableSrv, errorHandler: ErrorHandler, diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ResponderCtrl.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ResponderCtrl.scala index 17ab8b76e3..8da314b540 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ResponderCtrl.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ResponderCtrl.scala @@ -16,7 +16,7 @@ import scala.concurrent.ExecutionContext @Singleton class ResponderCtrl @Inject() ( entrypoint: Entrypoint, - @Named("with-thehive-cortex-schema") implicit val db: Database, + implicit val db: Database, responderSrv: ResponderSrv, implicit val ex: ExecutionContext ) { diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/models/CortexSchemaDefinition.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/models/CortexSchemaDefinition.scala index ef457c42e8..ea1e67eb7a 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/models/CortexSchemaDefinition.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/models/CortexSchemaDefinition.scala @@ -4,7 +4,9 @@ import javax.inject.{Inject, Singleton} import org.reflections.Reflections import org.reflections.scanners.SubTypesScanner import org.reflections.util.ConfigurationBuilder +import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.models._ +import org.thp.thehive.services.LocalUserSrv import play.api.Logger import scala.collection.JavaConverters._ @@ -39,4 +41,5 @@ class CortexSchemaDefinition @Inject() () extends Schema with UpdatableSchema { } .toSeq } + override val authContext: AuthContext = LocalUserSrv.getSystemAuthContext } diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ActionSrv.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ActionSrv.scala index 49d52a63d6..c95b23c396 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ActionSrv.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ActionSrv.scala @@ -39,7 +39,7 @@ class ActionSrv @Inject() ( logSrv: LogSrv, connector: Connector, implicit val schema: Schema, - @Named("with-thehive-cortex-schema") implicit val db: Database, + implicit val db: Database, implicit val ec: ExecutionContext, auditSrv: CortexAuditSrv ) extends VertexSrv[Action] { diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/AnalyzerTemplateSrv.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/AnalyzerTemplateSrv.scala index cfdb010ebd..1b64a7757b 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/AnalyzerTemplateSrv.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/AnalyzerTemplateSrv.scala @@ -24,7 +24,7 @@ import scala.util.{Failure, Try} @Singleton class AnalyzerTemplateSrv @Inject() (implicit - @Named("with-thehive-cortex-schema") db: Database, + db: Database, auditSrv: CortexAuditSrv, organisationSrv: OrganisationSrv ) extends VertexSrv[AnalyzerTemplate] { diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/JobSrv.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/JobSrv.scala index c3deb46ba2..fd552203ab 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/JobSrv.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/JobSrv.scala @@ -45,7 +45,7 @@ class JobSrv @Inject() ( reportTagSrv: ReportTagSrv, serviceHelper: ServiceHelper, auditSrv: CortexAuditSrv, - @Named("with-thehive-schema") implicit val db: Database, + implicit val db: Database, implicit val ec: ExecutionContext, implicit val mat: Materializer ) extends VertexSrv[Job] { diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ResponderSrv.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ResponderSrv.scala index 18ded91397..13cfcd97ef 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ResponderSrv.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ResponderSrv.scala @@ -17,7 +17,7 @@ import scala.util.{Failure, Success} @Singleton class ResponderSrv @Inject() ( connector: Connector, - @Named("with-thehive-cortex-schema") db: Database, + db: Database, entityHelper: EntityHelper, serviceHelper: ServiceHelper, implicit val ec: ExecutionContext diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ServiceHelper.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ServiceHelper.scala index 0ce824fc26..da5b35325f 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ServiceHelper.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/services/ServiceHelper.scala @@ -16,7 +16,7 @@ import play.api.Logger @Singleton class ServiceHelper @Inject() ( - @Named("with-thehive-cortex-schema") db: Database, + db: Database, organisationSrv: OrganisationSrv ) { diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerCtrlTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerCtrlTest.scala index d4ba90febb..4a746a4173 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerCtrlTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerCtrlTest.scala @@ -7,10 +7,6 @@ import org.thp.thehive.{BasicDatabaseProvider, TestAppBuilder} import play.api.test.{FakeRequest, PlaySpecification} class AnalyzerCtrlTest extends PlaySpecification with TestAppBuilder { - override def appConfigure: AppBuilder = - super - .appConfigure - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-cortex-schema") "analyzer controller" should { "list analyzers" in testApp { app => diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerTemplateCtrlTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerTemplateCtrlTest.scala index 1abf23b16f..a2913e6a96 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerTemplateCtrlTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/AnalyzerTemplateCtrlTest.scala @@ -13,10 +13,6 @@ import play.api.test.{FakeRequest, PlaySpecification} import scala.util.Random class AnalyzerTemplateCtrlTest extends PlaySpecification with TestAppBuilder { - override def appConfigure: AppBuilder = - super - .appConfigure - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-cortex-schema") "report controller" should { // "create, fetch, update and delete a template" in testApp {app => diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrlTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrlTest.scala index 15ffbdbb95..5ff9107d65 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrlTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/controllers/v0/JobCtrlTest.scala @@ -23,7 +23,6 @@ class JobCtrlTest extends PlaySpecification with TestAppBuilder { .bind[Connector, TestConnector] .bindToProvider[Schema, TheHiveCortexSchemaProvider] .bindNamedToProvider[QueryExecutor, TheHiveCortexQueryExecutorProvider]("v0") - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-cortex-schema") ) "job controller" should { diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ActionSrvTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ActionSrvTest.scala index 66980decaa..72778010d0 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ActionSrvTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ActionSrvTest.scala @@ -33,7 +33,6 @@ class ActionSrvTest extends PlaySpecification with TestAppBuilder { .bind[Connector, TestConnector] .bindToProvider[Schema, TheHiveCortexSchemaProvider] ) - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-cortex-schema") def testAppBuilder[A](body: AppBuilder => A): A = testApp { app => diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/AnalyzerSrvTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/AnalyzerSrvTest.scala index 43fd62587d..dfe2ff26bc 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/AnalyzerSrvTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/AnalyzerSrvTest.scala @@ -22,7 +22,6 @@ class AnalyzerSrvTest extends PlaySpecification with TestAppBuilder { .bind[Connector, TestConnector] .bindToProvider[Schema, TheHiveCortexSchemaProvider] ) - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-cortex-schema") implicit val authContext: AuthContext = DummyUserSrv(userId = "certuser@thehive.local", organisation = "cert", permissions = Permissions.all).authContext diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/JobSrvTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/JobSrvTest.scala index e0c2aabcb9..e54b68463f 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/JobSrvTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/JobSrvTest.scala @@ -31,7 +31,6 @@ class JobSrvTest extends PlaySpecification with TestAppBuilder { .bindActor[CortexActor]("cortex-actor") .bindToProvider[CortexClient, TestCortexClientProvider] .bind[Connector, TestConnector] - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-cortex-schema") .`override`(_.bindToProvider[Schema, TheHiveCortexSchemaProvider]) "job service" should { diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ResponderSrvTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ResponderSrvTest.scala index 528b0c8b2c..306d6b2ba7 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ResponderSrvTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ResponderSrvTest.scala @@ -27,7 +27,6 @@ class ResponderSrvTest extends PlaySpecification with TestAppBuilder { .bind[Connector, TestConnector] .bindToProvider[Schema, TheHiveCortexSchemaProvider] ) - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-cortex-schema") "responder service" should { "fetch responders by type" in testApp { app => diff --git a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ServiceHelperTest.scala b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ServiceHelperTest.scala index 99051a0cb8..5ca18cc68f 100644 --- a/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ServiceHelperTest.scala +++ b/cortex/connector/src/test/scala/org/thp/thehive/connector/cortex/services/ServiceHelperTest.scala @@ -22,7 +22,6 @@ class ServiceHelperTest extends PlaySpecification with TestAppBuilder { .bind[Connector, TestConnector] .bindToProvider[Schema, TheHiveCortexSchemaProvider] ) - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-cortex-schema") "service helper" should { "filter properly organisations according to supplied config" in testApp { app => diff --git a/migration/src/main/scala/org/thp/thehive/migration/th4/NoAuditSrv.scala b/migration/src/main/scala/org/thp/thehive/migration/th4/NoAuditSrv.scala index ed415e4d2c..e248d25c1c 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/th4/NoAuditSrv.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/th4/NoAuditSrv.scala @@ -17,12 +17,12 @@ import scala.util.{Success, Try} class NoAuditSrv @Inject() ( userSrvProvider: Provider[UserSrv], @Named("notification-actor") notificationActor: ActorRef, - eventSrv: EventSrv -)(implicit @Named("with-thehive-schema") db: Database) - extends AuditSrv(userSrvProvider, notificationActor, eventSrv)(db) { + eventSrv: EventSrv, + db: Database +) extends AuditSrv(userSrvProvider, notificationActor, eventSrv, db) { - override def create(audit: Audit, context: Option[Product with Entity], `object`: Option[Product with Entity])( - implicit graph: Graph, + override def create(audit: Audit, context: Option[Product with Entity], `object`: Option[Product with Entity])(implicit + graph: Graph, authContext: AuthContext ): Try[Unit] = Success(()) diff --git a/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala b/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala index 42be27c782..e1efedba2a 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala @@ -3,7 +3,8 @@ package org.thp.thehive.migration.th4 import akka.actor.ActorSystem import akka.stream.Materializer import com.google.inject.Guice -import javax.inject.{Inject, Named, Provider, Singleton} + +import javax.inject.{Inject, Provider, Singleton} import net.codingwell.scalaguice.ScalaModule import org.apache.tinkerpop.gremlin.process.traversal.P import org.thp.scalligraph._ @@ -15,6 +16,7 @@ import org.thp.scalligraph.traversal.{Graph, Traversal} import org.thp.scalligraph.traversal.TraversalOps._ import org.thp.thehive.connector.cortex.models.{CortexSchemaDefinition, TheHiveCortexSchemaProvider} import org.thp.thehive.connector.cortex.services.{ActionSrv, JobSrv} +import org.thp.thehive.controllers.v1.Conversion._ import org.thp.thehive.dto.v1.InputCustomFieldValue import org.thp.thehive.migration import org.thp.thehive.migration.IdMapping @@ -31,7 +33,6 @@ import play.api.{Configuration, Environment, Logger} import scala.collection.JavaConverters._ import scala.concurrent.ExecutionContext import scala.util.{Failure, Success, Try} -import org.thp.thehive.controllers.v1.Conversion._ object Output { @@ -54,8 +55,7 @@ object Output { bind[AuditSrv].to[NoAuditSrv] bind[Database].to[JanusDatabase] - bind[Database].annotatedWithName("with-thehive-schema").toProvider[BasicDatabaseProvider] - bind[Database].annotatedWithName("with-thehive-cortex-schema").toProvider[BasicDatabaseProvider] + bind[Database].toProvider[BasicDatabaseProvider] bind[Configuration].toInstance(configuration) bind[Environment].toInstance(Environment.simple()) bind[ApplicationLifecycle].to[DefaultApplicationLifecycle] @@ -74,7 +74,7 @@ object Output { def apply(configuration: Configuration)(implicit actorSystem: ActorSystem): Output = { if (configuration.getOptional[Boolean]("dropDatabase").contains(true)) { Logger(getClass).info("Drop database") - new JanusDatabase(configuration, actorSystem).drop() + new JanusDatabase(configuration, actorSystem, fullTextIndexAvailable = false).drop() } buildApp(configuration).getInstance(classOf[Output]) } @@ -109,7 +109,7 @@ class Output @Inject() ( resolutionStatusSrv: ResolutionStatusSrv, jobSrv: JobSrv, actionSrv: ActionSrv, - @Named("with-thehive-schema") db: Database, + db: Database, cache: SyncCacheApi ) extends migration.Output { lazy val logger: Logger = Logger(getClass) @@ -232,11 +232,11 @@ class Output @Inject() ( | ${alerts.size} alerts""".stripMargin) } - def startMigration(): Try[Unit] = { - db match { - case jdb: JanusDatabase => jdb.dropOtherConnections.recover { case error => logger.error(s"Fail to remove other connection", error) } - case _ => - } + def startMigration(): Try[Unit] = +// db match { +// case jdb: JanusDatabase => jdb.dropOtherConnections.recover { case error => logger.error(s"Fail to remove other connection", error) } +// case _ => +// } if (db.version("thehive") == 0) db.createSchemaFrom(theHiveSchema)(LocalUserSrv.getSystemAuthContext) .flatMap(_ => db.setVersion(theHiveSchema.name, theHiveSchema.operations.lastVersion)) @@ -245,13 +245,12 @@ class Output @Inject() ( .map(_ => retrieveExistingData()) else theHiveSchema - .update(db)(LocalUserSrv.getSystemAuthContext) - .flatMap(_ => cortexSchema.update(db)(LocalUserSrv.getSystemAuthContext)) + .update(db) + .flatMap(_ => cortexSchema.update(db)) .map { _ => retrieveExistingData() db.removeAllIndexes() } - } def endMigration(): Try[Unit] = { db.addSchemaIndexes(theHiveSchema) @@ -496,7 +495,11 @@ class Output @Inject() ( override def createCase(inputCase: InputCase): Try[IdMapping] = authTransaction(inputCase.metaData.createdBy) { implicit graph => implicit authContext => logger.debug(s"Create case #${inputCase.`case`.number}") - caseSrv.createEntity(inputCase.`case`).map { createdCase => + val organisationIds = inputCase.organisations.flatMap { + case (orgName, _) => getOrganisation(orgName).map(_._id).toOption + } + val `case` = inputCase.`case`.copy(organisationIds = organisationIds.toSeq) + caseSrv.createEntity(`case`).map { createdCase => updateMetaData(createdCase, inputCase.metaData) inputCase .user diff --git a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/controllers/v0/MispCtrl.scala b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/controllers/v0/MispCtrl.scala index ddccfd7d66..c00640ac3e 100644 --- a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/controllers/v0/MispCtrl.scala +++ b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/controllers/v0/MispCtrl.scala @@ -23,7 +23,7 @@ class MispCtrl @Inject() ( mispExportSrv: MispExportSrv, alertSrv: AlertSrv, caseSrv: CaseSrv, - @Named("with-thehive-schema") db: Database, + db: Database, @Named("misp-actor") mispActor: ActorRef, implicit val ec: ExecutionContext ) { diff --git a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/MispImportSrv.scala b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/MispImportSrv.scala index 98601460ef..a708f7feff 100644 --- a/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/MispImportSrv.scala +++ b/misp/connector/src/main/scala/org/thp/thehive/connector/misp/services/MispImportSrv.scala @@ -11,7 +11,7 @@ import org.thp.scalligraph.models._ import org.thp.scalligraph.traversal.Graph import org.thp.scalligraph.traversal.TraversalOps._ import org.thp.scalligraph.utils.FunctionalCondition._ -import org.thp.scalligraph.{EntityName, RichSeq} +import org.thp.scalligraph.{EntityId, EntityName, RichSeq} import org.thp.thehive.controllers.v1.Conversion._ import org.thp.thehive.models._ import org.thp.thehive.services.AlertOps._ @@ -37,15 +37,15 @@ class MispImportSrv @Inject() ( observableTypeSrv: ObservableTypeSrv, attachmentSrv: AttachmentSrv, caseTemplateSrv: CaseTemplateSrv, + db: Database, auditSrv: AuditSrv, - @Named("with-thehive-schema") db: Database, implicit val ec: ExecutionContext, implicit val mat: Materializer ) { lazy val logger: Logger = Logger(getClass) - def eventToAlert(client: TheHiveMispClient, event: Event): Try[Alert] = + def eventToAlert(client: TheHiveMispClient, event: Event, organisationId: EntityId): Try[Alert] = client .currentOrganisationName .map { mispOrganisation => @@ -70,7 +70,8 @@ class MispImportSrv @Inject() ( .getOrElse(2), pap = 2, read = false, - follow = true + follow = true, + organisationId = organisationId ) } @@ -335,7 +336,7 @@ class MispImportSrv @Inject() ( caseTemplate: Option[CaseTemplate with Entity] )(implicit graph: Graph, authContext: AuthContext): Try[(Alert with Entity, JsObject)] = { logger.debug(s"updateOrCreateAlert ${client.name}#${event.id} for organisation ${organisation.name}") - eventToAlert(client, event).flatMap { alert => + eventToAlert(client, event, organisation._id).flatMap { alert => organisationSrv .get(organisation) .alerts diff --git a/thehive/app/org/thp/thehive/ClusterSetup.scala b/thehive/app/org/thp/thehive/ClusterSetup.scala index 7a60a7f625..6f487b627f 100644 --- a/thehive/app/org/thp/thehive/ClusterSetup.scala +++ b/thehive/app/org/thp/thehive/ClusterSetup.scala @@ -4,6 +4,8 @@ import akka.actor.{Actor, ActorSystem, Props} import akka.cluster.Cluster import akka.cluster.ClusterEvent.{InitialStateAsEvents, MemberEvent, _} import com.google.inject.Injector +import javax.inject.{Inject, Provider, Singleton} +import org.thp.scalligraph.SingleInstance import play.api.{Configuration, Logger} import javax.inject.{Inject, Singleton} @@ -43,3 +45,8 @@ class ClusterListener extends Actor { case MemberDowned(member) => logger.debug(s"Member is downed: $member") } } + +@Singleton +class SingleInstanceProvider @Inject() (configuration: Configuration) extends Provider[SingleInstance] { + override def get(): SingleInstance = new SingleInstance(configuration.get[Seq[String]]("akka.cluster.seed-nodes").isEmpty) +} diff --git a/thehive/app/org/thp/thehive/TheHiveModule.scala b/thehive/app/org/thp/thehive/TheHiveModule.scala index 4c752f9926..33f2c1424c 100644 --- a/thehive/app/org/thp/thehive/TheHiveModule.scala +++ b/thehive/app/org/thp/thehive/TheHiveModule.scala @@ -3,12 +3,13 @@ package org.thp.thehive import akka.actor.ActorRef import com.google.inject.AbstractModule import net.codingwell.scalaguice.{ScalaModule, ScalaMultibinder} +import org.thp.scalligraph.SingleInstance import org.thp.scalligraph.auth._ -import org.thp.scalligraph.janus.JanusDatabase -import org.thp.scalligraph.models.{Database, Schema} +import org.thp.scalligraph.janus.{JanusDatabase, JanusDatabaseProvider} +import org.thp.scalligraph.models.{Database, UpdatableSchema} import org.thp.scalligraph.services.{GenIntegrityCheckOps, HadoopStorageSrv, S3StorageSrv} import org.thp.thehive.controllers.v0.QueryExecutorVersion0Provider -import org.thp.thehive.models.{DatabaseProvider, TheHiveSchemaDefinition} +import org.thp.thehive.models.TheHiveSchemaDefinition import org.thp.thehive.services.notification.notifiers._ import org.thp.thehive.services.notification.triggers._ import org.thp.thehive.services.{UserSrv => _, _} @@ -63,10 +64,9 @@ class TheHiveModule(environment: Environment, configuration: Configuration) exte notifierBindings.addBinding.to[WebhookProvider] configuration.get[String]("db.provider") match { - case "janusgraph" => bind[Database].to[JanusDatabase] + case "janusgraph" => bind[Database].toProvider[JanusDatabaseProvider] case other => sys.error(s"Authentication provider [$other] is not recognized") } - bind[Database].annotatedWithName("with-thehive-schema").toProvider[DatabaseProvider] configuration.get[String]("storage.provider") match { case "localfs" => bind(classOf[StorageSrv]).to(classOf[LocalFileSystemStorageSrv]) @@ -83,7 +83,7 @@ class TheHiveModule(environment: Environment, configuration: Configuration) exte queryExecutorBindings.addBinding.to[TheHiveQueryExecutorV1] bind[QueryExecutor].annotatedWithName("v0").toProvider[QueryExecutorVersion0Provider] ScalaMultibinder.newSetBinder[Connector](binder) - val schemaBindings = ScalaMultibinder.newSetBinder[Schema](binder) + val schemaBindings = ScalaMultibinder.newSetBinder[UpdatableSchema](binder) schemaBindings.addBinding.to[TheHiveSchemaDefinition] bindActor[ConfigActor]("config-actor") @@ -105,6 +105,8 @@ class TheHiveModule(environment: Environment, configuration: Configuration) exte bind[ActorRef].annotatedWithName("flow-actor").toProvider[FlowActorProvider] + bind[SingleInstance].toProvider[SingleInstanceProvider] + bind[ClusterSetup].asEagerSingleton() () } diff --git a/thehive/app/org/thp/thehive/controllers/dav/Router.scala b/thehive/app/org/thp/thehive/controllers/dav/Router.scala index b746ba3ab7..1f8725fb73 100644 --- a/thehive/app/org/thp/thehive/controllers/dav/Router.scala +++ b/thehive/app/org/thp/thehive/controllers/dav/Router.scala @@ -20,8 +20,7 @@ import scala.util.matching.Regex import scala.xml.{Node, NodeSeq} @Singleton -class Router @Inject() (entrypoint: Entrypoint, vfs: VFS, @Named("with-thehive-schema") db: Database, attachmentSrv: AttachmentSrv) - extends SimpleRouter { +class Router @Inject() (entrypoint: Entrypoint, vfs: VFS, db: Database, attachmentSrv: AttachmentSrv) extends SimpleRouter { lazy val logger: Logger = Logger(getClass) object PROPFIND { diff --git a/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala index 6c79f2f0e8..950b25a2bc 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/AlertCtrl.scala @@ -40,7 +40,7 @@ class AlertCtrl @Inject() ( userSrv: UserSrv, caseSrv: CaseSrv, override val publicData: PublicAlert, - @Named("with-thehive-schema") implicit val db: Database, + implicit val db: Database, @Named("v0") override val queryExecutor: QueryExecutor ) extends QueryCtrl { def create: Action[AnyContent] = @@ -331,7 +331,8 @@ class PublicAlert @Inject() ( alertSrv: AlertSrv, organisationSrv: OrganisationSrv, customFieldSrv: CustomFieldSrv, - @Named("with-thehive-schema") db: Database + tagSrv: TagSrv, + db: Database ) extends PublicData { override val entityName: String = "alert" override val initialQuery: Query = diff --git a/thehive/app/org/thp/thehive/controllers/v0/AttachmentCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/AttachmentCtrl.scala index 7ca3615bd2..26bd6a5121 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/AttachmentCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/AttachmentCtrl.scala @@ -25,7 +25,7 @@ class AttachmentCtrl @Inject() ( entrypoint: Entrypoint, appConfig: ApplicationConfig, attachmentSrv: AttachmentSrv, - @Named("with-thehive-schema") db: Database + db: Database ) { val forbiddenChar: Seq[Char] = Seq('/', '\n', '\r', '\t', '\u0000', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':', ';') diff --git a/thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala index 9ced6e86b6..fa146c71a9 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala @@ -26,7 +26,7 @@ class AuditCtrl @Inject() ( auditSrv: AuditSrv, @Named("flow-actor") flowActor: ActorRef, override val publicData: PublicAudit, - @Named("with-thehive-schema") implicit override val db: Database, + implicit override val db: Database, implicit val ec: ExecutionContext, @Named("v0") override val queryExecutor: QueryExecutor ) extends AuditRenderer @@ -52,7 +52,7 @@ class AuditCtrl @Inject() ( .deepMerge( Json.obj( "base" -> Json.obj("object" -> obj, "rootId" -> audit.context._id), - "summary" -> jsonSummary(auditSrv, audit.requestId) + "summary" -> JsObject.empty //jsonSummary(auditSrv, audit.requestId) ) ) } @@ -64,7 +64,7 @@ class AuditCtrl @Inject() ( } @Singleton -class PublicAudit @Inject() (auditSrv: AuditSrv, @Named("with-thehive-schema") db: Database) extends PublicData { +class PublicAudit @Inject() (auditSrv: AuditSrv, db: Database) extends PublicData { override val getQuery: ParamQuery[EntityIdOrName] = Query.initWithParam[EntityIdOrName, Traversal.V[Audit]]( "getAudit", FieldsParser[EntityIdOrName], diff --git a/thehive/app/org/thp/thehive/controllers/v0/AuthenticationCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/AuthenticationCtrl.scala index 7c679074f2..79ffe5e6d1 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/AuthenticationCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/AuthenticationCtrl.scala @@ -19,7 +19,7 @@ class AuthenticationCtrl @Inject() ( authSrv: AuthSrv, requestOrganisation: RequestOrganisation, userSrv: UserSrv, - @Named("with-thehive-schema") db: Database, + db: Database, implicit val ec: ExecutionContext ) { diff --git a/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala index cf8a35cf67..f2f42db1c8 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala @@ -35,7 +35,7 @@ class CaseCtrl @Inject() ( userSrv: UserSrv, override val publicData: PublicCase, @Named("v0") override val queryExecutor: QueryExecutor, - @Named("with-thehive-schema") implicit override val db: Database + implicit override val db: Database ) extends CaseRenderer with QueryCtrl { def create: Action[AnyContent] = @@ -190,7 +190,7 @@ class PublicCase @Inject() ( organisationSrv: OrganisationSrv, userSrv: UserSrv, customFieldSrv: CustomFieldSrv, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) extends PublicData with CaseRenderer { override val entityName: String = "case" diff --git a/thehive/app/org/thp/thehive/controllers/v0/CaseTemplateCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/CaseTemplateCtrl.scala index 796eafbc7e..e346dd83e5 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/CaseTemplateCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/CaseTemplateCtrl.scala @@ -31,7 +31,7 @@ class CaseTemplateCtrl @Inject() ( userSrv: UserSrv, auditSrv: AuditSrv, override val publicData: PublicCaseTemplate, - @Named("with-thehive-schema") implicit override val db: Database, + implicit override val db: Database, @Named("v0") override val queryExecutor: QueryExecutor ) extends QueryCtrl { def create: Action[AnyContent] = diff --git a/thehive/app/org/thp/thehive/controllers/v0/ConfigCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/ConfigCtrl.scala index 3de29d0a34..630fa3a814 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/ConfigCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/ConfigCtrl.scala @@ -26,7 +26,7 @@ class ConfigCtrl @Inject() ( organisationSrv: OrganisationSrv, userSrv: UserSrv, entrypoint: Entrypoint, - @Named("with-thehive-schema") db: Database + db: Database ) { lazy val logger: Logger = Logger(getClass) diff --git a/thehive/app/org/thp/thehive/controllers/v0/CustomFieldCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/CustomFieldCtrl.scala index d4293f404d..5ae48ebb51 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/CustomFieldCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/CustomFieldCtrl.scala @@ -19,7 +19,7 @@ import scala.util.Success @Singleton class CustomFieldCtrl @Inject() ( override val entrypoint: Entrypoint, - @Named("with-thehive-schema") override val db: Database, + override val db: Database, customFieldSrv: CustomFieldSrv, override val publicData: PublicCustomField, @Named("v0") override val queryExecutor: QueryExecutor diff --git a/thehive/app/org/thp/thehive/controllers/v0/DashboardCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/DashboardCtrl.scala index 578990253f..31e0e76e92 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/DashboardCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/DashboardCtrl.scala @@ -24,7 +24,7 @@ class DashboardCtrl @Inject() ( override val entrypoint: Entrypoint, dashboardSrv: DashboardSrv, userSrv: UserSrv, - @Named("with-thehive-schema") implicit val db: Database, + implicit val db: Database, override val publicData: PublicDashboard, @Named("v0") override val queryExecutor: QueryExecutor ) extends QueryCtrl { diff --git a/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala index 6e844f4eb3..bcc41ea37a 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala @@ -41,7 +41,7 @@ class DescribeCtrl @Inject() ( userCtrl: UserCtrl, customFieldSrv: CustomFieldSrv, injector: Injector, - @Named("with-thehive-schema") db: Database, + db: Database, applicationConfig: ApplicationConfig ) { @@ -209,7 +209,7 @@ class DescribeCtrl @Inject() ( case _ => None } - def propertyToJson(model: String, prop: PublicProperty[_, _]): Seq[PropertyDescription] = + def propertyToJson(model: String, prop: PublicProperty): Seq[PropertyDescription] = customDescription(model, prop.propertyName).getOrElse { prop.mapping.domainTypeClass match { case c if c == classOf[Boolean] || c == classOf[JBoolean] => Seq(PropertyDescription(prop.propertyName, "boolean")) diff --git a/thehive/app/org/thp/thehive/controllers/v0/ListCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/ListCtrl.scala index dfec8da9ca..2a6ee600bb 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/ListCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/ListCtrl.scala @@ -18,7 +18,7 @@ import scala.util.{Failure, Success} @Singleton class ListCtrl @Inject() ( entrypoint: Entrypoint, - @Named("with-thehive-schema") db: Database, + db: Database, customFieldSrv: CustomFieldSrv, observableTypeSrv: ObservableTypeSrv ) { diff --git a/thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala index a2b2b47a2b..4361ae7162 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/LogCtrl.scala @@ -20,7 +20,7 @@ import play.api.mvc.{Action, AnyContent, Results} @Singleton class LogCtrl @Inject() ( override val entrypoint: Entrypoint, - @Named("with-thehive-schema") override val db: Database, + override val db: Database, logSrv: LogSrv, taskSrv: TaskSrv, @Named("v0") override val queryExecutor: QueryExecutor, diff --git a/thehive/app/org/thp/thehive/controllers/v0/ObservableCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/ObservableCtrl.scala index c925f0935d..c6330b4481 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/ObservableCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/ObservableCtrl.scala @@ -8,7 +8,7 @@ import org.thp.scalligraph.controllers._ import org.thp.scalligraph.models.{Database, Entity, UMapping} import org.thp.scalligraph.query._ import org.thp.scalligraph.traversal.TraversalOps._ -import org.thp.scalligraph.traversal.{Converter, IteratorOutput, Traversal} +import org.thp.scalligraph.traversal.{IteratorOutput, Traversal} import org.thp.thehive.controllers.v0.Conversion._ import org.thp.thehive.dto.v0.{InputAttachment, InputObservable} import org.thp.thehive.models._ @@ -33,7 +33,7 @@ import scala.util.{Failure, Success} class ObservableCtrl @Inject() ( configuration: Configuration, override val entrypoint: Entrypoint, - @Named("with-thehive-schema") override val db: Database, + override val db: Database, observableSrv: ObservableSrv, observableTypeSrv: ObservableTypeSrv, caseSrv: CaseSrv, diff --git a/thehive/app/org/thp/thehive/controllers/v0/ObservableTypeCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/ObservableTypeCtrl.scala index ce4e22dab1..a3998ad0fc 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/ObservableTypeCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/ObservableTypeCtrl.scala @@ -16,7 +16,7 @@ import play.api.mvc.{Action, AnyContent, Results} @Singleton class ObservableTypeCtrl @Inject() ( override val entrypoint: Entrypoint, - @Named("with-thehive-schema") override val db: Database, + override val db: Database, observableTypeSrv: ObservableTypeSrv, @Named("v0") override val queryExecutor: QueryExecutor, override val publicData: PublicObservableType diff --git a/thehive/app/org/thp/thehive/controllers/v0/OrganisationCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/OrganisationCtrl.scala index fdc5c9445c..60f9b53473 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/OrganisationCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/OrganisationCtrl.scala @@ -22,7 +22,7 @@ class OrganisationCtrl @Inject() ( override val entrypoint: Entrypoint, organisationSrv: OrganisationSrv, userSrv: UserSrv, - @Named("with-thehive-schema") implicit override val db: Database, + implicit override val db: Database, @Named("v0") override val queryExecutor: QueryExecutor, override val publicData: PublicOrganisation ) extends QueryCtrl { diff --git a/thehive/app/org/thp/thehive/controllers/v0/PageCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/PageCtrl.scala index db97600f86..ff6317cd8e 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/PageCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/PageCtrl.scala @@ -19,7 +19,7 @@ import play.api.mvc._ class PageCtrl @Inject() ( override val entrypoint: Entrypoint, pageSrv: PageSrv, - @Named("with-thehive-schema") override val db: Database, + override val db: Database, @Named("v0") override val queryExecutor: QueryExecutor, override val publicData: PublicPage ) extends QueryCtrl { diff --git a/thehive/app/org/thp/thehive/controllers/v0/ProfileCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/ProfileCtrl.scala index da4a28d934..d075ca7788 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/ProfileCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/ProfileCtrl.scala @@ -21,7 +21,7 @@ class ProfileCtrl @Inject() ( override val entrypoint: Entrypoint, profileSrv: ProfileSrv, override val publicData: PublicProfile, - @Named("with-thehive-schema") implicit val db: Database, + implicit val db: Database, @Named("v0") override val queryExecutor: QueryExecutor ) extends QueryCtrl { def create: Action[AnyContent] = diff --git a/thehive/app/org/thp/thehive/controllers/v0/ShareCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/ShareCtrl.scala index a792e0104b..585139a635 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/ShareCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/ShareCtrl.scala @@ -29,7 +29,7 @@ class ShareCtrl @Inject() ( taskSrv: TaskSrv, observableSrv: ObservableSrv, profileSrv: ProfileSrv, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) { def shareCase(caseId: String): Action[AnyContent] = @@ -164,7 +164,7 @@ class ShareCtrl @Inject() ( .richShare .getOrFail("Share") profile <- profileSrv.getOrFail(EntityIdOrName(profile)) - _ <- shareSrv.update(richShare.share, profile) + _ <- shareSrv.updateProfile(richShare.share, profile) } yield Results.Ok } diff --git a/thehive/app/org/thp/thehive/controllers/v0/StatsCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/StatsCtrl.scala index be261c5bea..d6d941a656 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/StatsCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/StatsCtrl.scala @@ -26,7 +26,7 @@ class StatsCtrl @Inject() ( tagCtrl: TagCtrl, pageCtrl: PageCtrl, queryExecutor: TheHiveQueryExecutor, - @Named("with-thehive-schema") db: Database + db: Database ) { lazy val logger: Logger = Logger(getClass) diff --git a/thehive/app/org/thp/thehive/controllers/v0/StatusCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/StatusCtrl.scala index 9e03134ae1..2b43b3fb4a 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/StatusCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/StatusCtrl.scala @@ -24,7 +24,7 @@ class StatusCtrl @Inject() ( authSrv: AuthSrv, userSrv: UserSrv, connectors: immutable.Set[Connector], - @Named("with-thehive-schema") db: Database + db: Database ) { val passwordConfig: ConfigItem[String, String] = appConfig.item[String]("datastore.attachment.password", "Password used to protect attachment ZIP") diff --git a/thehive/app/org/thp/thehive/controllers/v0/StreamCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/StreamCtrl.scala index d3281d63f5..caf6af4da9 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/StreamCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/StreamCtrl.scala @@ -23,7 +23,7 @@ class StreamCtrl @Inject() ( val caseSrv: CaseSrv, val taskSrv: TaskSrv, val userSrv: UserSrv, - @Named("with-thehive-schema") implicit val db: Database, + implicit val db: Database, implicit val schema: Schema, implicit val ec: ExecutionContext ) extends AuditRenderer { diff --git a/thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala index 45a85f7abf..43cb21a415 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/TagCtrl.scala @@ -21,7 +21,7 @@ import scala.util.Try class TagCtrl @Inject() ( override val entrypoint: Entrypoint, - @Named("with-thehive-schema") override val db: Database, + override val db: Database, tagSrv: TagSrv, @Named("v0") override val queryExecutor: QueryExecutor, override val publicData: PublicTag @@ -134,20 +134,20 @@ class PublicTag @Inject() (tagSrv: TagSrv) extends PublicData { .property("value", UMapping.string.optional)(_.field.readonly) .property("description", UMapping.string.optional)(_.field.readonly) .property("text", UMapping.string)( - _.select(_.displayName) - .filter((_, tags) => - 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]) + _.select(_.displayName) // FIXME add filter +// .filter((_, tags) => +// 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]) .readonly ) .build diff --git a/thehive/app/org/thp/thehive/controllers/v0/TaskCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/TaskCtrl.scala index bba39dac4b..e8dca8455b 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/TaskCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/TaskCtrl.scala @@ -21,7 +21,7 @@ import play.api.mvc.{Action, AnyContent, Results} @Singleton class TaskCtrl @Inject() ( override val entrypoint: Entrypoint, - @Named("with-thehive-schema") override val db: Database, + override val db: Database, taskSrv: TaskSrv, caseSrv: CaseSrv, userSrv: UserSrv, diff --git a/thehive/app/org/thp/thehive/controllers/v0/TheHiveQueryExecutor.scala b/thehive/app/org/thp/thehive/controllers/v0/TheHiveQueryExecutor.scala index e5379bba12..f3afbd6ca0 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/TheHiveQueryExecutor.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/TheHiveQueryExecutor.scala @@ -36,7 +36,7 @@ object OutputParam { @Singleton class TheHiveQueryExecutor @Inject() ( - @Named("with-thehive-schema") override val db: Database, + override val db: Database, alert: PublicAlert, audit: PublicAudit, `case`: PublicCase, diff --git a/thehive/app/org/thp/thehive/controllers/v0/UserCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/UserCtrl.scala index 37ec7b53e5..6669dd0d76 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/UserCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/UserCtrl.scala @@ -28,7 +28,7 @@ class UserCtrl @Inject() ( authSrv: AuthSrv, organisationSrv: OrganisationSrv, auditSrv: AuditSrv, - @Named("with-thehive-schema") implicit override val db: Database, + override val db: Database, @Named("v0") override val queryExecutor: QueryExecutor, override val publicData: PublicUser ) extends QueryCtrl { @@ -226,7 +226,7 @@ class UserCtrl @Inject() ( } @Singleton -class PublicUser @Inject() (userSrv: UserSrv, organisationSrv: OrganisationSrv, @Named("with-thehive-schema") db: Database) extends PublicData { +class PublicUser @Inject() (userSrv: UserSrv, organisationSrv: OrganisationSrv, db: Database) extends PublicData { override val entityName: String = "user" override val initialQuery: Query = Query.init[Traversal.V[User]]("listUser", (graph, authContext) => organisationSrv.get(authContext.organisation)(graph).users) diff --git a/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala index 448aed37f6..c4de7dd6f5 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/AlertCtrl.scala @@ -31,7 +31,7 @@ class AlertCtrl @Inject() ( caseTemplateSrv: CaseTemplateSrv, userSrv: UserSrv, organisationSrv: OrganisationSrv, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) extends QueryableCtrl with AlertRenderer { diff --git a/thehive/app/org/thp/thehive/controllers/v1/AuditCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/AuditCtrl.scala index e3c315eb91..ae586dd903 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/AuditCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/AuditCtrl.scala @@ -18,7 +18,7 @@ import scala.util.Success @Singleton class AuditCtrl @Inject() ( entrypoint: Entrypoint, - @Named("with-thehive-schema") db: Database, + db: Database, properties: Properties, auditSrv: AuditSrv, implicit val schema: Schema diff --git a/thehive/app/org/thp/thehive/controllers/v1/AuthenticationCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/AuthenticationCtrl.scala index 8b114353f3..5c4746c467 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/AuthenticationCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/AuthenticationCtrl.scala @@ -22,7 +22,7 @@ class AuthenticationCtrl @Inject() ( authSrv: AuthSrv, requestOrganisation: RequestOrganisation, userSrv: UserSrv, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) { def login: Action[AnyContent] = diff --git a/thehive/app/org/thp/thehive/controllers/v1/CaseTemplateCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/CaseTemplateCtrl.scala index ac31a52866..dda8c608a3 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/CaseTemplateCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/CaseTemplateCtrl.scala @@ -23,7 +23,7 @@ class CaseTemplateCtrl @Inject() ( properties: Properties, caseTemplateSrv: CaseTemplateSrv, organisationSrv: OrganisationSrv, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) extends QueryableCtrl { override val entityName: String = "caseTemplate" diff --git a/thehive/app/org/thp/thehive/controllers/v1/CustomFieldCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/CustomFieldCtrl.scala index 1e5c47e94a..339916df21 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/CustomFieldCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/CustomFieldCtrl.scala @@ -15,8 +15,7 @@ import play.api.mvc.{Action, AnyContent, Results} import scala.util.Success @Singleton -class CustomFieldCtrl @Inject() (entrypoint: Entrypoint, @Named("with-thehive-schema") db: Database, customFieldSrv: CustomFieldSrv) - extends QueryableCtrl { +class CustomFieldCtrl @Inject() (entrypoint: Entrypoint, db: Database, customFieldSrv: CustomFieldSrv) extends QueryableCtrl { override val entityName: String = "CustomField" override val initialQuery: Query = Query.init[Traversal.V[CustomField]]("listCustomField", (graph, _) => customFieldSrv.startTraversal(graph)) diff --git a/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala index 6c1c6dc4f9..005810eb83 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala @@ -44,7 +44,7 @@ class DescribeCtrl @Inject() ( impactStatusSrv: ImpactStatusSrv, resolutionStatusSrv: ResolutionStatusSrv, injector: Injector, - @Named("with-thehive-schema") db: Database, + db: Database, applicationConfig: ApplicationConfig ) { @@ -209,7 +209,7 @@ class DescribeCtrl @Inject() ( case _ => None } - def propertyToJson(model: String, prop: PublicProperty[_, _]): Seq[PropertyDescription] = + def propertyToJson(model: String, prop: PublicProperty): Seq[PropertyDescription] = customDescription(model, prop.propertyName).getOrElse { prop.mapping.domainTypeClass match { case c if c == classOf[Boolean] || c == classOf[JBoolean] => Seq(PropertyDescription(prop.propertyName, "boolean")) @@ -219,7 +219,7 @@ class DescribeCtrl @Inject() ( case c if c == classOf[String] => Seq(PropertyDescription(prop.propertyName, "string")) case c if c == classOf[EntityId] => Seq(PropertyDescription(prop.propertyName, "string")) case _ => - logger.warn(s"Unrecognized property $prop. Add a custom description") + logger.warn(s"Unrecognized property ${prop.propertyName}:${prop.mapping.domainTypeClass.getSimpleName}. Add a custom description") Seq(PropertyDescription(prop.propertyName, "unknown")) } } diff --git a/thehive/app/org/thp/thehive/controllers/v1/LogCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/LogCtrl.scala index 2627780719..599a3afde3 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/LogCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/LogCtrl.scala @@ -21,7 +21,7 @@ import play.api.mvc.{Action, AnyContent, Results} @Singleton class LogCtrl @Inject() ( entrypoint: Entrypoint, - @Named("with-thehive-schema") db: Database, + db: Database, properties: Properties, logSrv: LogSrv, taskSrv: TaskSrv, diff --git a/thehive/app/org/thp/thehive/controllers/v1/ObservableCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/ObservableCtrl.scala index 49c9f3e3b2..d5581c8e17 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/ObservableCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/ObservableCtrl.scala @@ -34,7 +34,7 @@ import scala.util.{Failure, Success} @Singleton class ObservableCtrl @Inject() ( entrypoint: Entrypoint, - @Named("with-thehive-schema") db: Database, + db: Database, properties: Properties, observableSrv: ObservableSrv, observableTypeSrv: ObservableTypeSrv, diff --git a/thehive/app/org/thp/thehive/controllers/v1/ObservableTypeCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/ObservableTypeCtrl.scala index 3d7353b0b6..d0300c929e 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/ObservableTypeCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/ObservableTypeCtrl.scala @@ -16,7 +16,7 @@ import play.api.mvc.{Action, AnyContent, Results} @Singleton class ObservableTypeCtrl @Inject() ( val entrypoint: Entrypoint, - @Named("with-thehive-schema") db: Database, + db: Database, observableTypeSrv: ObservableTypeSrv ) extends QueryableCtrl { override val entityName: String = "ObservableType" diff --git a/thehive/app/org/thp/thehive/controllers/v1/OrganisationCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/OrganisationCtrl.scala index 115327a732..4a6d8295b2 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/OrganisationCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/OrganisationCtrl.scala @@ -21,7 +21,7 @@ class OrganisationCtrl @Inject() ( properties: Properties, organisationSrv: OrganisationSrv, userSrv: UserSrv, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) extends QueryableCtrl { override val entityName: String = "organisation" diff --git a/thehive/app/org/thp/thehive/controllers/v1/ProfileCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/ProfileCtrl.scala index f9d4e5dcb2..2ac9ccd655 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/ProfileCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/ProfileCtrl.scala @@ -21,7 +21,7 @@ class ProfileCtrl @Inject() ( entrypoint: Entrypoint, properties: Properties, profileSrv: ProfileSrv, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) extends QueryableCtrl { override val getQuery: ParamQuery[EntityIdOrName] = Query.initWithParam[EntityIdOrName, Traversal.V[Profile]]( diff --git a/thehive/app/org/thp/thehive/controllers/v1/Properties.scala b/thehive/app/org/thp/thehive/controllers/v1/Properties.scala index fff921827f..0e9dac3ff6 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Properties.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Properties.scala @@ -36,7 +36,7 @@ class Properties @Inject() ( caseTemplateSrv: CaseTemplateSrv, observableSrv: ObservableSrv, customFieldSrv: CustomFieldSrv, - @Named("with-thehive-schema") db: Database + db: Database ) { lazy val metaProperties: PublicProperties = diff --git a/thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala index 55be07a869..9b24ae4d9f 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TaskCtrl.scala @@ -22,7 +22,7 @@ import scala.util.Success @Singleton class TaskCtrl @Inject() ( entrypoint: Entrypoint, - @Named("with-thehive-schema") db: Database, + db: Database, properties: Properties, taskSrv: TaskSrv, caseSrv: CaseSrv, diff --git a/thehive/app/org/thp/thehive/controllers/v1/TheHiveQueryExecutor.scala b/thehive/app/org/thp/thehive/controllers/v1/TheHiveQueryExecutor.scala index bbc3b86b81..c3bf678b18 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TheHiveQueryExecutor.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TheHiveQueryExecutor.scala @@ -34,7 +34,7 @@ class TheHiveQueryExecutor @Inject() ( userCtrl: UserCtrl, // dashboardCtrl: DashboardCtrl, properties: Properties, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) extends QueryExecutor { lazy val controllers: Seq[QueryableCtrl] = diff --git a/thehive/app/org/thp/thehive/controllers/v1/UserCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/UserCtrl.scala index 676094fa54..698b0a44ae 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/UserCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/UserCtrl.scala @@ -34,7 +34,7 @@ class UserCtrl @Inject() ( profileSrv: ProfileSrv, auditSrv: AuditSrv, attachmentSrv: AttachmentSrv, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) extends QueryableCtrl { override val entityName: String = "user" diff --git a/thehive/app/org/thp/thehive/services/AlertSrv.scala b/thehive/app/org/thp/thehive/services/AlertSrv.scala index 2f2e28be13..3641a858d4 100644 --- a/thehive/app/org/thp/thehive/services/AlertSrv.scala +++ b/thehive/app/org/thp/thehive/services/AlertSrv.scala @@ -34,7 +34,7 @@ class AlertSrv @Inject() ( observableSrv: ObservableSrv, auditSrv: AuditSrv )(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[Alert] { val alertTagSrv = new EdgeSrv[AlertTag, Alert, Tag] diff --git a/thehive/app/org/thp/thehive/services/AttachmentSrv.scala b/thehive/app/org/thp/thehive/services/AttachmentSrv.scala index dbded9f0fa..68f8decef9 100644 --- a/thehive/app/org/thp/thehive/services/AttachmentSrv.scala +++ b/thehive/app/org/thp/thehive/services/AttachmentSrv.scala @@ -24,7 +24,7 @@ import scala.util.Try @Singleton class AttachmentSrv @Inject() (configuration: Configuration, storageSrv: StorageSrv)(implicit - @Named("with-thehive-schema") db: Database, + db: Database, mat: Materializer ) extends VertexSrv[Attachment] { diff --git a/thehive/app/org/thp/thehive/services/AuditSrv.scala b/thehive/app/org/thp/thehive/services/AuditSrv.scala index dea8177165..1ef20273a8 100644 --- a/thehive/app/org/thp/thehive/services/AuditSrv.scala +++ b/thehive/app/org/thp/thehive/services/AuditSrv.scala @@ -28,9 +28,9 @@ case class PendingAudit(audit: Audit, context: Option[Product with Entity], `obj class AuditSrv @Inject() ( userSrvProvider: Provider[UserSrv], @Named("notification-actor") notificationActor: ActorRef, - eventSrv: EventSrv -)(implicit @Named("with-thehive-schema") db: Database) - extends VertexSrv[Audit] { auditSrv => + eventSrv: EventSrv, + db: Database +) extends VertexSrv[Audit] { auditSrv => lazy val userSrv: UserSrv = userSrvProvider.get val auditUserSrv = new EdgeSrv[AuditUser, Audit, User] val auditedSrv = new EdgeSrv[Audited, Audit, Product] diff --git a/thehive/app/org/thp/thehive/services/CaseSrv.scala b/thehive/app/org/thp/thehive/services/CaseSrv.scala index 4bd14077a7..729412d845 100644 --- a/thehive/app/org/thp/thehive/services/CaseSrv.scala +++ b/thehive/app/org/thp/thehive/services/CaseSrv.scala @@ -40,8 +40,7 @@ class CaseSrv @Inject() ( resolutionStatusSrv: ResolutionStatusSrv, impactStatusSrv: ImpactStatusSrv, @Named("integrity-check-actor") integrityCheckActor: ActorRef -)(implicit @Named("with-thehive-schema") db: Database) - extends VertexSrv[Case] { +) extends VertexSrv[Case] { val caseTagSrv = new EdgeSrv[CaseTag, Case, Tag] val caseImpactStatusSrv = new EdgeSrv[CaseImpactStatus, Case, ImpactStatus] diff --git a/thehive/app/org/thp/thehive/services/CaseTemplateSrv.scala b/thehive/app/org/thp/thehive/services/CaseTemplateSrv.scala index a5c95caed9..61d96849d5 100644 --- a/thehive/app/org/thp/thehive/services/CaseTemplateSrv.scala +++ b/thehive/app/org/thp/thehive/services/CaseTemplateSrv.scala @@ -29,8 +29,7 @@ class CaseTemplateSrv @Inject() ( taskSrv: TaskSrv, auditSrv: AuditSrv, @Named("integrity-check-actor") integrityCheckActor: ActorRef -)(implicit @Named("with-thehive-schema") db: Database) - extends VertexSrv[CaseTemplate] { +) extends VertexSrv[CaseTemplate] { val caseTemplateTagSrv = new EdgeSrv[CaseTemplateTag, CaseTemplate, Tag] val caseTemplateCustomFieldSrv = new EdgeSrv[CaseTemplateCustomField, CaseTemplate, CustomField] @@ -245,7 +244,7 @@ object CaseTemplateOps { } class CaseTemplateIntegrityCheckOps @Inject() ( - @Named("with-thehive-schema") val db: Database, + val db: Database, val service: CaseTemplateSrv, organisationSrv: OrganisationSrv ) extends IntegrityCheckOps[CaseTemplate] { diff --git a/thehive/app/org/thp/thehive/services/ConfigContext.scala b/thehive/app/org/thp/thehive/services/ConfigContext.scala index 7ef17ea550..52c8ab8a32 100644 --- a/thehive/app/org/thp/thehive/services/ConfigContext.scala +++ b/thehive/app/org/thp/thehive/services/ConfigContext.scala @@ -10,7 +10,7 @@ import play.api.libs.json.JsValue import scala.util.Try @Singleton -class UserConfigContext @Inject() (@Named("with-thehive-schema") db: Database, configSrv: ConfigSrv) extends ConfigContext[AuthContext] { +class UserConfigContext @Inject() (db: Database, configSrv: ConfigSrv) extends ConfigContext[AuthContext] { override def defaultPath(path: String): String = s"user.defaults.$path" override def getValue(context: AuthContext, path: String): Option[JsValue] = @@ -36,7 +36,7 @@ class UserConfigContext @Inject() (@Named("with-thehive-schema") db: Database, c } @Singleton -class OrganisationConfigContext @Inject() (@Named("with-thehive-schema") db: Database, configSrv: ConfigSrv) extends ConfigContext[AuthContext] { +class OrganisationConfigContext @Inject() (db: Database, configSrv: ConfigSrv) extends ConfigContext[AuthContext] { override def defaultPath(path: String): String = s"organisation.defaults.$path" override def getValue(context: AuthContext, path: String): Option[JsValue] = diff --git a/thehive/app/org/thp/thehive/services/ConfigSrv.scala b/thehive/app/org/thp/thehive/services/ConfigSrv.scala index 2ecc87e57e..9e672630ec 100644 --- a/thehive/app/org/thp/thehive/services/ConfigSrv.scala +++ b/thehive/app/org/thp/thehive/services/ConfigSrv.scala @@ -21,7 +21,7 @@ import scala.util.Try class ConfigSrv @Inject() ( organisationSrv: OrganisationSrv, userSrv: UserSrv -)(@Named("with-thehive-schema") implicit val db: Database) +)(implicit val db: Database) extends VertexSrv[Config] { val organisationConfigSrv = new EdgeSrv[OrganisationConfig, Organisation, Config] val userConfigSrv = new EdgeSrv[UserConfig, User, Config] diff --git a/thehive/app/org/thp/thehive/services/CustomFieldSrv.scala b/thehive/app/org/thp/thehive/services/CustomFieldSrv.scala index a7b3ce8873..4f92cabc11 100644 --- a/thehive/app/org/thp/thehive/services/CustomFieldSrv.scala +++ b/thehive/app/org/thp/thehive/services/CustomFieldSrv.scala @@ -21,7 +21,7 @@ import scala.util.{Success, Try} @Singleton class CustomFieldSrv @Inject() (auditSrv: AuditSrv, organisationSrv: OrganisationSrv, @Named("integrity-check-actor") integrityCheckActor: ActorRef)( - implicit @Named("with-thehive-schema") db: Database + implicit db: Database ) extends VertexSrv[CustomField] { override def createEntity(e: CustomField)(implicit graph: Graph, authContext: AuthContext): Try[CustomField with Entity] = { @@ -174,8 +174,7 @@ object CustomFieldOps { } -class CustomFieldIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: CustomFieldSrv) - extends IntegrityCheckOps[CustomField] { +class CustomFieldIntegrityCheckOps @Inject() (val db: Database, val service: CustomFieldSrv) extends IntegrityCheckOps[CustomField] { override def resolve(entities: Seq[CustomField with Entity])(implicit graph: Graph): Try[Unit] = entities match { case head :: tail => diff --git a/thehive/app/org/thp/thehive/services/DashboardSrv.scala b/thehive/app/org/thp/thehive/services/DashboardSrv.scala index 04ad39bf00..f17f35084b 100644 --- a/thehive/app/org/thp/thehive/services/DashboardSrv.scala +++ b/thehive/app/org/thp/thehive/services/DashboardSrv.scala @@ -19,7 +19,7 @@ import scala.util.{Success, Try} @Singleton class DashboardSrv @Inject() (organisationSrv: OrganisationSrv, userSrv: UserSrv, auditSrv: AuditSrv)(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[Dashboard] { val organisationDashboardSrv = new EdgeSrv[OrganisationDashboard, Organisation, Dashboard] val dashboardUserSrv = new EdgeSrv[DashboardUser, Dashboard, User] diff --git a/thehive/app/org/thp/thehive/services/DataSrv.scala b/thehive/app/org/thp/thehive/services/DataSrv.scala index 06f8d376f5..eb0512cea9 100644 --- a/thehive/app/org/thp/thehive/services/DataSrv.scala +++ b/thehive/app/org/thp/thehive/services/DataSrv.scala @@ -17,8 +17,7 @@ import org.thp.thehive.services.DataOps._ import scala.util.{Success, Try} @Singleton -class DataSrv @Inject() (@Named("integrity-check-actor") integrityCheckActor: ActorRef)(implicit @Named("with-thehive-schema") db: Database) - extends VertexSrv[Data] { +class DataSrv @Inject() (@Named("integrity-check-actor") integrityCheckActor: ActorRef) extends VertexSrv[Data] { override def createEntity(e: Data)(implicit graph: Graph, authContext: AuthContext): Try[Data with Entity] = super.createEntity(e).map { data => integrityCheckActor ! EntityAdded("Data") @@ -56,7 +55,7 @@ object DataOps { } -class DataIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: DataSrv) extends IntegrityCheckOps[Data] { +class DataIntegrityCheckOps @Inject() (val db: Database, val service: DataSrv) extends IntegrityCheckOps[Data] { override def resolve(entities: Seq[Data with Entity])(implicit graph: Graph): Try[Unit] = entities match { case head :: tail => diff --git a/thehive/app/org/thp/thehive/services/ImpactStatusSrv.scala b/thehive/app/org/thp/thehive/services/ImpactStatusSrv.scala index de87fc5fc8..581cc6c86b 100644 --- a/thehive/app/org/thp/thehive/services/ImpactStatusSrv.scala +++ b/thehive/app/org/thp/thehive/services/ImpactStatusSrv.scala @@ -16,7 +16,7 @@ import scala.util.{Failure, Success, Try} @Singleton class ImpactStatusSrv @Inject() (@Named("integrity-check-actor") integrityCheckActor: ActorRef)(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[ImpactStatus] { override def getByName(name: String)(implicit graph: Graph): Traversal.V[ImpactStatus] = @@ -45,8 +45,7 @@ object ImpactStatusOps { } } -class ImpactStatusIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: ImpactStatusSrv) - extends IntegrityCheckOps[ImpactStatus] { +class ImpactStatusIntegrityCheckOps @Inject() (val db: Database, val service: ImpactStatusSrv) extends IntegrityCheckOps[ImpactStatus] { override def resolve(entities: Seq[ImpactStatus with Entity])(implicit graph: Graph): Try[Unit] = entities match { case head :: tail => diff --git a/thehive/app/org/thp/thehive/services/KeyValueSrv.scala b/thehive/app/org/thp/thehive/services/KeyValueSrv.scala index 7bd5b9544b..b0288c08d1 100644 --- a/thehive/app/org/thp/thehive/services/KeyValueSrv.scala +++ b/thehive/app/org/thp/thehive/services/KeyValueSrv.scala @@ -10,6 +10,6 @@ import org.thp.thehive.models.KeyValue import scala.util.Try @Singleton -class KeyValueSrv @Inject() ()(implicit @Named("with-thehive-schema") db: Database) extends VertexSrv[KeyValue] { +class KeyValueSrv @Inject() () extends VertexSrv[KeyValue] { def create(e: KeyValue)(implicit graph: Graph, authContext: AuthContext): Try[KeyValue with Entity] = createEntity(e) } diff --git a/thehive/app/org/thp/thehive/services/LocalKeyAuthSrv.scala b/thehive/app/org/thp/thehive/services/LocalKeyAuthSrv.scala index ca3c63febd..da7132b7f2 100644 --- a/thehive/app/org/thp/thehive/services/LocalKeyAuthSrv.scala +++ b/thehive/app/org/thp/thehive/services/LocalKeyAuthSrv.scala @@ -15,7 +15,7 @@ import scala.concurrent.ExecutionContext import scala.util.{Failure, Random, Success, Try} class LocalKeyAuthSrv( - @Named("with-thehive-schema") db: Database, + db: Database, userSrv: UserSrv, localUserSrv: LocalUserSrv, authSrv: AuthSrv, @@ -69,7 +69,7 @@ class LocalKeyAuthSrv( @Singleton class LocalKeyAuthProvider @Inject() ( - @Named("with-thehive-schema") db: Database, + db: Database, userSrv: UserSrv, localUserSrv: LocalUserSrv, authSrvProvider: Provider[AuthSrv], diff --git a/thehive/app/org/thp/thehive/services/LocalPasswordAuthSrv.scala b/thehive/app/org/thp/thehive/services/LocalPasswordAuthSrv.scala index adaec1a90b..1f743ef73c 100644 --- a/thehive/app/org/thp/thehive/services/LocalPasswordAuthSrv.scala +++ b/thehive/app/org/thp/thehive/services/LocalPasswordAuthSrv.scala @@ -19,7 +19,7 @@ object LocalPasswordAuthSrv { SecureHash.createHash(password) } -class LocalPasswordAuthSrv(@Named("with-thehive-schema") db: Database, userSrv: UserSrv, localUserSrv: LocalUserSrv) extends AuthSrv { +class LocalPasswordAuthSrv(db: Database, userSrv: UserSrv, localUserSrv: LocalUserSrv) extends AuthSrv { val name = "local" override val capabilities: Set[AuthCapability.Value] = Set(AuthCapability.changePassword, AuthCapability.setPassword) lazy val logger: Logger = Logger(getClass) @@ -68,8 +68,7 @@ class LocalPasswordAuthSrv(@Named("with-thehive-schema") db: Database, userSrv: } @Singleton -class LocalPasswordAuthProvider @Inject() (@Named("with-thehive-schema") db: Database, userSrv: UserSrv, localUserSrv: LocalUserSrv) - extends AuthSrvProvider { +class LocalPasswordAuthProvider @Inject() (db: Database, userSrv: UserSrv, localUserSrv: LocalUserSrv) extends AuthSrvProvider { override val name: String = "local" override def apply(config: Configuration): Try[AuthSrv] = Success(new LocalPasswordAuthSrv(db, userSrv, localUserSrv)) } diff --git a/thehive/app/org/thp/thehive/services/LocalUserSrv.scala b/thehive/app/org/thp/thehive/services/LocalUserSrv.scala index 356879d506..0ecf406be4 100644 --- a/thehive/app/org/thp/thehive/services/LocalUserSrv.scala +++ b/thehive/app/org/thp/thehive/services/LocalUserSrv.scala @@ -16,7 +16,7 @@ import scala.util.{Failure, Success, Try} @Singleton class LocalUserSrv @Inject() ( - @Named("with-thehive-schema") db: Database, + db: Database, userSrv: UserSrv, organisationSrv: OrganisationSrv, profileSrv: ProfileSrv, diff --git a/thehive/app/org/thp/thehive/services/LogSrv.scala b/thehive/app/org/thp/thehive/services/LogSrv.scala index 665475e18f..f70a4957e1 100644 --- a/thehive/app/org/thp/thehive/services/LogSrv.scala +++ b/thehive/app/org/thp/thehive/services/LogSrv.scala @@ -20,7 +20,7 @@ import scala.util.{Success, Try} @Singleton class LogSrv @Inject() (attachmentSrv: AttachmentSrv, auditSrv: AuditSrv, taskSrv: TaskSrv, userSrv: UserSrv)(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[Log] { val taskLogSrv = new EdgeSrv[TaskLog, Task, Log] val logAttachmentSrv = new EdgeSrv[LogAttachment, Log, Attachment] diff --git a/thehive/app/org/thp/thehive/services/ObservableSrv.scala b/thehive/app/org/thp/thehive/services/ObservableSrv.scala index a1ba3891f3..8eb9502f69 100644 --- a/thehive/app/org/thp/thehive/services/ObservableSrv.scala +++ b/thehive/app/org/thp/thehive/services/ObservableSrv.scala @@ -30,8 +30,6 @@ class ObservableSrv @Inject() ( caseSrvProvider: Provider[CaseSrv], auditSrv: AuditSrv, alertSrvProvider: Provider[AlertSrv] -)(implicit - @Named("with-thehive-schema") db: Database ) extends VertexSrv[Observable] { lazy val caseSrv: CaseSrv = caseSrvProvider.get lazy val alertSrv: AlertSrv = alertSrvProvider.get diff --git a/thehive/app/org/thp/thehive/services/ObservableTypeSrv.scala b/thehive/app/org/thp/thehive/services/ObservableTypeSrv.scala index 55830804dd..837d2d5503 100644 --- a/thehive/app/org/thp/thehive/services/ObservableTypeSrv.scala +++ b/thehive/app/org/thp/thehive/services/ObservableTypeSrv.scala @@ -16,7 +16,7 @@ import scala.util.{Failure, Success, Try} @Singleton class ObservableTypeSrv @Inject() (@Named("integrity-check-actor") integrityCheckActor: ActorRef)(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[ObservableType] { val observableObservableTypeSrv = new EdgeSrv[ObservableObservableType, Observable, ObservableType] @@ -56,8 +56,7 @@ object ObservableTypeOps { } } -class ObservableTypeIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: ObservableTypeSrv) - extends IntegrityCheckOps[ObservableType] { +class ObservableTypeIntegrityCheckOps @Inject() (val db: Database, val service: ObservableTypeSrv) extends IntegrityCheckOps[ObservableType] { override def resolve(entities: Seq[ObservableType with Entity])(implicit graph: Graph): Try[Unit] = entities match { case head :: tail => diff --git a/thehive/app/org/thp/thehive/services/OrganisationSrv.scala b/thehive/app/org/thp/thehive/services/OrganisationSrv.scala index dbcdd2f4ab..beedc840ab 100644 --- a/thehive/app/org/thp/thehive/services/OrganisationSrv.scala +++ b/thehive/app/org/thp/thehive/services/OrganisationSrv.scala @@ -28,7 +28,7 @@ class OrganisationSrv @Inject() ( userSrv: UserSrv, @Named("integrity-check-actor") integrityCheckActor: ActorRef )(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[Organisation] { val organisationOrganisationSrv = new EdgeSrv[OrganisationOrganisation, Organisation, Organisation] @@ -194,8 +194,7 @@ object OrganisationOps { } -class OrganisationIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: OrganisationSrv) - extends IntegrityCheckOps[Organisation] { +class OrganisationIntegrityCheckOps @Inject() (val db: Database, val service: OrganisationSrv) extends IntegrityCheckOps[Organisation] { override def resolve(entities: Seq[Organisation with Entity])(implicit graph: Graph): Try[Unit] = entities match { case head :: tail => diff --git a/thehive/app/org/thp/thehive/services/PageSrv.scala b/thehive/app/org/thp/thehive/services/PageSrv.scala index d0799b230d..c0ad897191 100644 --- a/thehive/app/org/thp/thehive/services/PageSrv.scala +++ b/thehive/app/org/thp/thehive/services/PageSrv.scala @@ -15,8 +15,7 @@ import play.api.libs.json.Json import scala.util.Try @Singleton -class PageSrv @Inject() (implicit @Named("with-thehive-schema") db: Database, organisationSrv: OrganisationSrv, auditSrv: AuditSrv) - extends VertexSrv[Page] { +class PageSrv @Inject() (implicit db: Database, organisationSrv: OrganisationSrv, auditSrv: AuditSrv) extends VertexSrv[Page] { val organisationPageSrv = new EdgeSrv[OrganisationPage, Organisation, Page] diff --git a/thehive/app/org/thp/thehive/services/ProfileSrv.scala b/thehive/app/org/thp/thehive/services/ProfileSrv.scala index 8acf62c77a..e63c849628 100644 --- a/thehive/app/org/thp/thehive/services/ProfileSrv.scala +++ b/thehive/app/org/thp/thehive/services/ProfileSrv.scala @@ -23,7 +23,7 @@ class ProfileSrv @Inject() ( organisationSrvProvider: Provider[OrganisationSrv], @Named("integrity-check-actor") integrityCheckActor: ActorRef )(implicit - @Named("with-thehive-schema") val db: Database + val db: Database ) extends VertexSrv[Profile] { lazy val organisationSrv: OrganisationSrv = organisationSrvProvider.get lazy val orgAdmin: Profile with Entity = db.roTransaction(graph => getOrFail(EntityName(Profile.orgAdmin.name))(graph)).get @@ -83,8 +83,7 @@ object ProfileOps { } -class ProfileIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: ProfileSrv) - extends IntegrityCheckOps[Profile] { +class ProfileIntegrityCheckOps @Inject() (val db: Database, val service: ProfileSrv) extends IntegrityCheckOps[Profile] { override def resolve(entities: Seq[Profile with Entity])(implicit graph: Graph): Try[Unit] = entities match { case head :: tail => diff --git a/thehive/app/org/thp/thehive/services/ReportTagSrv.scala b/thehive/app/org/thp/thehive/services/ReportTagSrv.scala index 198c581164..64b9ca2390 100644 --- a/thehive/app/org/thp/thehive/services/ReportTagSrv.scala +++ b/thehive/app/org/thp/thehive/services/ReportTagSrv.scala @@ -14,7 +14,7 @@ import org.thp.thehive.services.ReportTagOps._ import scala.util.Try @Singleton -class ReportTagSrv @Inject() (observableSrv: ObservableSrv)(implicit @Named("with-thehive-schema") db: Database) extends VertexSrv[ReportTag] { +class ReportTagSrv @Inject() (observableSrv: ObservableSrv) extends VertexSrv[ReportTag] { val observableReportTagSrv = new EdgeSrv[ObservableReportTag, Observable, ReportTag] def updateTags(observable: Observable with Entity, origin: String, reportTags: Seq[ReportTag])(implicit diff --git a/thehive/app/org/thp/thehive/services/ResolutionStatusSrv.scala b/thehive/app/org/thp/thehive/services/ResolutionStatusSrv.scala index 4fee51ac77..4df09d7e11 100644 --- a/thehive/app/org/thp/thehive/services/ResolutionStatusSrv.scala +++ b/thehive/app/org/thp/thehive/services/ResolutionStatusSrv.scala @@ -16,7 +16,7 @@ import scala.util.{Failure, Success, Try} @Singleton class ResolutionStatusSrv @Inject() (@Named("integrity-check-actor") integrityCheckActor: ActorRef)(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[ResolutionStatus] { override def getByName(name: String)(implicit graph: Graph): Traversal.V[ResolutionStatus] = @@ -45,8 +45,7 @@ object ResolutionStatusOps { } } -class ResolutionStatusIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: ResolutionStatusSrv) - extends IntegrityCheckOps[ResolutionStatus] { +class ResolutionStatusIntegrityCheckOps @Inject() (val db: Database, val service: ResolutionStatusSrv) extends IntegrityCheckOps[ResolutionStatus] { override def resolve(entities: Seq[ResolutionStatus with Entity])(implicit graph: Graph): Try[Unit] = entities match { case head :: tail => diff --git a/thehive/app/org/thp/thehive/services/RoleSrv.scala b/thehive/app/org/thp/thehive/services/RoleSrv.scala index fe07c936ee..409df6fab8 100644 --- a/thehive/app/org/thp/thehive/services/RoleSrv.scala +++ b/thehive/app/org/thp/thehive/services/RoleSrv.scala @@ -12,14 +12,14 @@ import org.thp.thehive.services.RoleOps._ import scala.util.Try @Singleton -class RoleSrv @Inject() (@Named("with-thehive-schema") implicit val db: Database) extends VertexSrv[Role] { +class RoleSrv @Inject() (implicit val db: Database) extends VertexSrv[Role] { val roleOrganisationSrv = new EdgeSrv[RoleOrganisation, Role, Organisation] val userRoleSrv = new EdgeSrv[UserRole, User, Role] val roleProfileSrv = new EdgeSrv[RoleProfile, Role, Profile] - def create(user: User with Entity, organisation: Organisation with Entity, profile: Profile with Entity)( - implicit graph: Graph, + def create(user: User with Entity, organisation: Organisation with Entity, profile: Profile with Entity)(implicit + graph: Graph, authContext: AuthContext ): Try[Role with Entity] = for { diff --git a/thehive/app/org/thp/thehive/services/ShareSrv.scala b/thehive/app/org/thp/thehive/services/ShareSrv.scala index 49b523dd03..a4f6754aaf 100644 --- a/thehive/app/org/thp/thehive/services/ShareSrv.scala +++ b/thehive/app/org/thp/thehive/services/ShareSrv.scala @@ -21,8 +21,7 @@ import org.thp.thehive.services.TaskOps._ import scala.util.{Failure, Try} @Singleton -class ShareSrv @Inject() ( - @Named("with-thehive-schema") implicit val db: Database, +class ShareSrv @Inject() (implicit auditSrv: AuditSrv, caseSrvProvider: Provider[CaseSrv], taskSrv: TaskSrv, @@ -59,6 +58,7 @@ class ShareSrv @Inject() ( _ <- organisationShareSrv.create(OrganisationShare(), organisation, createdShare) _ <- shareCaseSrv.create(ShareCase(), createdShare, `case`) _ <- shareProfileSrv.create(ShareProfile(), createdShare, profile) + _ <- caseSrv.get(`case`).addValue(_.organisationIds, organisation._id).getOrFail("Case") _ <- auditSrv.share.shareCase(`case`, organisation, profile) } yield createdShare } @@ -72,7 +72,7 @@ class ShareSrv @Inject() ( def get(task: Task with Entity, organisationName: EntityIdOrName)(implicit graph: Graph): Traversal.V[Share] = taskSrv.get(task).share(organisationName) - def update( + def updateProfile( share: Share with Entity, profile: Profile with Entity )(implicit graph: Graph, authContext: AuthContext): Try[ShareProfile with Entity] = { @@ -92,7 +92,9 @@ class ShareSrv @Inject() ( for { case0 <- get(shareId).`case`.getOrFail("Case") organisation <- get(shareId).organisation.getOrFail("Organisation") + case0 <- get(shareId).`case`.removeValue(_.organisationIds, organisation._id).getOrFail("Case") _ <- auditSrv.share.unshareCase(case0, organisation) + // TODO delete all descendant of share linked only to this share } yield get(shareId).remove() /** diff --git a/thehive/app/org/thp/thehive/services/StreamSrv.scala b/thehive/app/org/thp/thehive/services/StreamSrv.scala index e3a89c3e22..efe6e751a6 100644 --- a/thehive/app/org/thp/thehive/services/StreamSrv.scala +++ b/thehive/app/org/thp/thehive/services/StreamSrv.scala @@ -45,11 +45,11 @@ class StreamActor( graceDuration: FiniteDuration, keepAlive: FiniteDuration, auditSrv: AuditSrv, - @Named("with-thehive-schema") db: Database + db: Database ) extends Actor { import context.dispatcher - lazy val logger: Logger = Logger(s"${getClass.getName}.$self") + lazy val logger: Logger = Logger(getClass) override def receive: Receive = { val keepAliveTimer = context.system.scheduler.scheduleOnce(keepAlive, self, PoisonPill) @@ -136,7 +136,7 @@ class StreamSrv @Inject() ( appConfig: ApplicationConfig, eventSrv: EventSrv, auditSrv: AuditSrv, - @Named("with-thehive-schema") db: Database, + db: Database, system: ActorSystem, implicit val ec: ExecutionContext ) { diff --git a/thehive/app/org/thp/thehive/services/TOTPAuthSrv.scala b/thehive/app/org/thp/thehive/services/TOTPAuthSrv.scala index 35ecf31076..0868844235 100644 --- a/thehive/app/org/thp/thehive/services/TOTPAuthSrv.scala +++ b/thehive/app/org/thp/thehive/services/TOTPAuthSrv.scala @@ -23,7 +23,7 @@ class TOTPAuthSrv( appConfig: ApplicationConfig, availableAuthProviders: immutable.Set[AuthSrvProvider], userSrv: UserSrv, - @Named("with-thehive-schema") db: Database + db: Database ) extends MultiAuthSrv(configuration, appConfig, availableAuthProviders) { override val name: String = "totp" @@ -102,7 +102,7 @@ class TOTPAuthSrvProvider @Inject() ( appConfig: ApplicationConfig, authProviders: immutable.Set[AuthSrvProvider], userSrv: UserSrv, - @Named("with-thehive-schema") db: Database + db: Database ) extends Provider[AuthSrv] { override def get(): AuthSrv = new TOTPAuthSrv(configuration, appConfig, authProviders, userSrv, db) } diff --git a/thehive/app/org/thp/thehive/services/TagSrv.scala b/thehive/app/org/thp/thehive/services/TagSrv.scala index a9313493a9..f5354c3932 100644 --- a/thehive/app/org/thp/thehive/services/TagSrv.scala +++ b/thehive/app/org/thp/thehive/services/TagSrv.scala @@ -17,7 +17,7 @@ import scala.util.{Success, Try} @Singleton class TagSrv @Inject() (appConfig: ApplicationConfig, @Named("integrity-check-actor") integrityCheckActor: ActorRef)(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[Tag] { val autoCreateConfig: ConfigItem[Boolean, Boolean] = @@ -87,7 +87,7 @@ object TagOps { } -class TagIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: TagSrv) extends IntegrityCheckOps[Tag] { +class TagIntegrityCheckOps @Inject() (val db: Database, val service: TagSrv) extends IntegrityCheckOps[Tag] { override def resolve(entities: Seq[Tag with Entity])(implicit graph: Graph): Try[Unit] = { firstCreatedEntity(entities).foreach { diff --git a/thehive/app/org/thp/thehive/services/TaskSrv.scala b/thehive/app/org/thp/thehive/services/TaskSrv.scala index 6057da5c15..e639d98767 100644 --- a/thehive/app/org/thp/thehive/services/TaskSrv.scala +++ b/thehive/app/org/thp/thehive/services/TaskSrv.scala @@ -20,7 +20,7 @@ import scala.util.{Failure, Success, Try} @Singleton class TaskSrv @Inject() (caseSrvProvider: Provider[CaseSrv], auditSrv: AuditSrv, organisationSrv: OrganisationSrv)(implicit - @Named("with-thehive-schema") db: Database + db: Database ) extends VertexSrv[Task] { lazy val caseSrv: CaseSrv = caseSrvProvider.get diff --git a/thehive/app/org/thp/thehive/services/UserSrv.scala b/thehive/app/org/thp/thehive/services/UserSrv.scala index 49b71933cb..4018e902cb 100644 --- a/thehive/app/org/thp/thehive/services/UserSrv.scala +++ b/thehive/app/org/thp/thehive/services/UserSrv.scala @@ -34,7 +34,7 @@ class UserSrv @Inject() ( auditSrv: AuditSrv, attachmentSrv: AttachmentSrv, @Named("integrity-check-actor") integrityCheckActor: ActorRef, - @Named("with-thehive-schema") implicit val db: Database + implicit val db: Database ) extends VertexSrv[User] { val defaultUserDomain: Option[String] = configuration.getOptional[String]("auth.defaultUserDomain") val fullUserNameRegex: Pattern = "[\\p{Graph}&&[^@.]](?:[\\p{Graph}&&[^@]]*)*@\\p{Alnum}+(?:[\\p{Alnum}-.])*".r.pattern @@ -338,7 +338,7 @@ object UserOps { @Singleton class UserIntegrityCheckOps @Inject() ( - @Named("with-thehive-schema") val db: Database, + val db: Database, val service: UserSrv, profileSrv: ProfileSrv, organisationSrv: OrganisationSrv, diff --git a/thehive/app/org/thp/thehive/services/notification/NotificationActor.scala b/thehive/app/org/thp/thehive/services/notification/NotificationActor.scala index afa6052eb7..dea78f6c93 100644 --- a/thehive/app/org/thp/thehive/services/notification/NotificationActor.scala +++ b/thehive/app/org/thp/thehive/services/notification/NotificationActor.scala @@ -83,7 +83,7 @@ class NotificationActor @Inject() ( userSrv: UserSrv, notificationSrv: NotificationSrv, cache: SyncCacheApi, - @Named("with-thehive-schema") implicit val db: Database, + implicit val db: Database, implicit val schema: Schema ) extends Actor { import context.dispatcher diff --git a/thehive/test/org/thp/thehive/TestAppBuilder.scala b/thehive/test/org/thp/thehive/TestAppBuilder.scala index e46cae76ec..33421b29dc 100644 --- a/thehive/test/org/thp/thehive/TestAppBuilder.scala +++ b/thehive/test/org/thp/thehive/TestAppBuilder.scala @@ -81,7 +81,6 @@ trait TestAppBuilder { |akka.cluster.jmx.multi-mbeans-in-same-jvm: on |""".stripMargin) .bind[Database, janus.JanusDatabase] - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-schema") app[DatabaseBuilder].build()(app[Database], app[UserSrv].getSystemAuthContext) app[Database].close() @@ -90,7 +89,6 @@ trait TestAppBuilder { } val app = appConfigure .bind[Database, janus.JanusDatabase] - .bindNamedToProvider[Database, BasicDatabaseProvider]("with-thehive-schema") .addConfiguration(s""" |db { | provider: janusgraph diff --git a/thehive/test/org/thp/thehive/controllers/v0/StreamCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/StreamCtrlTest.scala index 3fc3885aa5..087ca405e3 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/StreamCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/StreamCtrlTest.scala @@ -33,10 +33,11 @@ class StreamCtrlTest extends PlaySpecification with TestAppBuilder { // Add an event app[Database].tryTransaction { implicit graph => + val organisation = app[OrganisationSrv].getOrFail(EntityName("cert")).get app[CaseSrv].create( - Case(0, s"case audit", s"desc audit", 1, new Date(), None, flag = false, 1, 1, CaseStatus.Open, None), + Case(0, s"case audit", s"desc audit", 1, new Date(), None, flag = false, 1, 1, CaseStatus.Open, None, Seq(organisation._id)), None, - app[OrganisationSrv].getOrFail(EntityName("cert")).get, + organisation, Set.empty, Seq.empty, None,