diff --git a/client-common/src/main/scala/org/thp/client/Authentication.scala b/client-common/src/main/scala/org/thp/client/Authentication.scala index 39ff9e52c4..c20887eb57 100644 --- a/client-common/src/main/scala/org/thp/client/Authentication.scala +++ b/client-common/src/main/scala/org/thp/client/Authentication.scala @@ -19,14 +19,15 @@ object Authentication { } yield PasswordAuthentication(username, password) case "bearer" => (json \ "key").validate[String].map(KeyAuthentication(_, "Bearer ")) case "key" => (json \ "key").validate[String].map(KeyAuthentication(_, "")) + case "none" => JsSuccess(NoAuthentication) case other => JsError(s"Unknown authentication type: $other") } } val writes: Writes[Authentication] = Writes[Authentication] { case PasswordAuthentication(username, password) => Json.obj("type" -> "basic", "username" -> username, "password" -> password) - case KeyAuthentication(key, "") => Json.obj("type" -> "key", "key" -> key) - case KeyAuthentication(key, "Bearer ") => Json.obj("type" -> "bearer", "key" -> key) + case KeyAuthentication(key, "") => Json.obj("type" -> "key", "key" -> key) + case KeyAuthentication(key, "Bearer ") => Json.obj("type" -> "bearer", "key" -> key) } implicit val format: Format[Authentication] = Format(reads, writes) } diff --git a/thehive/app/org/thp/thehive/services/notification/notifiers/Webhook.scala b/thehive/app/org/thp/thehive/services/notification/notifiers/Webhook.scala index d920b869dc..69db24a794 100644 --- a/thehive/app/org/thp/thehive/services/notification/notifiers/Webhook.scala +++ b/thehive/app/org/thp/thehive/services/notification/notifiers/Webhook.scala @@ -2,7 +2,7 @@ package org.thp.thehive.services.notification.notifiers import akka.stream.Materializer import org.apache.tinkerpop.gremlin.structure.Vertex -import org.thp.client.{ProxyWS, ProxyWSConfig} +import org.thp.client.{Authentication, ProxyWS, ProxyWSConfig} import org.thp.scalligraph.models.{Entity, UMapping} import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.scalligraph.traversal.TraversalOps._ @@ -31,6 +31,7 @@ case class WebhookNotification( name: String, url: String, version: Int = 0, + auth: Authentication, wsConfig: ProxyWSConfig = ProxyWSConfig(), includedTheHiveOrganisations: Seq[String] = Seq("*"), excludedTheHiveOrganisations: Seq[String] = Nil @@ -259,7 +260,7 @@ class Webhook( val async = for { message <- Future.fromTry(buildMessage(config.version, audit)) _ = logger.debug(s"Request webhook with message $message") - resp <- ws.url(config.url).post(message) + resp <- config.auth(ws.url(config.url)).post(message) } yield if (resp.status >= 400) logger.warn(s"Webhook call on ${config.url} returns ${resp.status} ${resp.statusText}") else () async.andThen { case _ => ws.close() } }