Skip to content

Commit

Permalink
#1708 Fix notification serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Dec 15, 2020
1 parent b3438cd commit 553736a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ akka {
actor {
serializers {
cortex-schema-updater = "org.thp.thehive.connector.cortex.models.SchemaUpdaterSerializer"
cortex-jobs = "org.thp.thehive.connector.cortex.services.CortexSerializer"
}

serialization-bindings {
"org.thp.thehive.connector.cortex.models.SchemaUpdaterMessage" = cortex-schema-updater
"org.thp.thehive.connector.cortex.services.CortexActorMessage" = cortex-jobs
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package org.thp.thehive.connector.cortex.services

import java.util.Date
import akka.actor._
import akka.pattern.pipe

import javax.inject.Inject
import org.thp.client.ApplicationError
import org.thp.cortex.dto.v0.{JobStatus, JobType, OutputJob}
import org.thp.scalligraph.EntityId
import org.thp.scalligraph.auth.AuthContext
import play.api.Logger
import play.api.libs.json.{Json, OFormat}

import java.util.Date
import javax.inject.Inject
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package org.thp.thehive.connector.misp.controllers.v0

import akka.actor.ActorRef
import com.google.inject.name.Named

import javax.inject.{Inject, Singleton}
import org.thp.scalligraph.EntityIdOrName
import org.thp.scalligraph.controllers.Entrypoint
import org.thp.scalligraph.models.Database
import org.thp.scalligraph.traversal.TraversalOps._
import org.thp.thehive.connector.misp.services.{MispActor, MispExportSrv, Synchro}
import org.thp.thehive.connector.misp.services.{MispExportSrv, Synchro}
import org.thp.thehive.models.Permissions
import org.thp.thehive.services.AlertOps._
import org.thp.thehive.services.CaseOps._
import org.thp.thehive.services.{AlertSrv, CaseSrv}
import play.api.mvc.{Action, AnyContent, Results}

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Success

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class NotificationSerializer extends Serializer {
*/
def toBinary(o: AnyRef): Array[Byte] =
o match {
case m: NotificationExecution => Json.toBytes(Json.toJson(m))
case m: AuditNotificationMessage => Json.toBytes(Json.toJson(m))
case _ => Array.empty[Byte] // Not serializable
case m: NotificationExecution => 0.toByte +: Json.toBytes(Json.toJson(m))
case m: AuditNotificationMessage => 1.toByte +: Json.toBytes(Json.toJson(m))
case _ => throw new NotSerializableException
}

/**
Expand All @@ -26,11 +26,9 @@ class NotificationSerializer extends Serializer {
*/
@throws(classOf[NotSerializableException])
def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef =
manifest
.flatMap {
case c if c == classOf[NotificationExecution] => Json.parse(bytes).asOpt[NotificationExecution]
case c if c == classOf[AuditNotificationMessage] => Json.parse(bytes).asOpt[AuditNotificationMessage]
case _ => None
}
.getOrElse(throw new NotSerializableException)
bytes(0) match {
case 0 => Json.parse(bytes.tail).asOpt[NotificationExecution]
case 1 => Json.parse(bytes.tail).asOpt[AuditNotificationMessage]
case _ => throw new NotSerializableException
}
}

0 comments on commit 553736a

Please sign in to comment.