1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2018 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.api.technical
21 
22 import akka.actor.ExtendedActorSystem
23 import akka.actor.typed.ActorSystem
24 import akka.actor.typed.scaladsl.adapter.ClassicActorSystemOps
25 import grizzled.slf4j.Logging
26 import org.make.api.proposal.ProposalSerializers
27 import org.make.api.sessionhistory.SessionHistorySerializers
28 import org.make.api.technical.MakeEventSerializer.allSerializers
29 import org.make.api.technical.job.JobSerializers
30 import org.make.api.technical.security.{SecurityConfigurationExtension, SecurityHelper}
31 import org.make.api.userhistory.UserHistorySerializers
32 import spray.json.{JsObject, JsString, JsValue}
33 import stamina.{Persister, StaminaAkkaSerializer}
34 
35 class MakeEventSerializer(system: ActorSystem[_], serializerName: String)
36     extends StaminaAkkaSerializer(allSerializers(system).toList)
37     with Logging {
38 
39   def this(system: ExtendedActorSystem) = this(system.toTyped, "make-serializer")
40   def this(system: ExtendedActorSystem, serializerName: String) = this(system.toTyped, serializerName)
41 
42   logger.debug(s"Creating make event serializer with name $serializerName")
43 }
44 
45 object MakeEventSerializer {
46   def allSerializers(system: ActorSystem[_]): Seq[Persister[_, _]] = {
47     val conf = SecurityConfigurationExtension(system)
48     ProposalSerializers(conf).serializers ++
49       UserHistorySerializers(conf).serializers ++
50       SessionHistorySerializers(conf).serializers ++
51       JobSerializers.serializers
52   }
53 
54   def setIpAddressAndHash(salt: String)(context: JsObject): JsObject = {
55     val fields: Map[String, JsValue] = context.fields
56     @SuppressWarnings(Array("org.wartremover.warts.AsInstanceOf"))
57     val maybeIp = fields.get("ipAddress").map(_.asInstanceOf[JsString].value)
58     JsObject(
59       fields ++
60         maybeIp.map(ip => "ipAddress" -> JsString(IpAndHash.obfuscateIp(ip))) ++
61         maybeIp.map(ip => "ipAddressHash" -> JsString(SecurityHelper.generateHash(ip, salt)))
62     )
63   }
64 }
Line Stmt Id Pos Tree Symbol Tests Code
39 10024 1611 - 1611 Literal <nosymbol> org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest ()
39 13516 1611 - 1650 Apply org.make.api.technical.MakeEventSerializer.<init> org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest MakeEventSerializer.this.<init>(akka.actor.typed.scaladsl.adapter.`package`.ClassicActorSystemOps(system).toTyped, "make-serializer")
39 14951 1632 - 1649 Literal <nosymbol> org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest "make-serializer"
39 8951 1616 - 1630 Select akka.actor.typed.scaladsl.adapter.ClassicActorSystemOps.toTyped org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest akka.actor.typed.scaladsl.adapter.`package`.ClassicActorSystemOps(system).toTyped
40 11966 1717 - 1753 Apply org.make.api.technical.MakeEventSerializer.<init> MakeEventSerializer.this.<init>(akka.actor.typed.scaladsl.adapter.`package`.ClassicActorSystemOps(system).toTyped, serializerName)
40 15737 1722 - 1736 Select akka.actor.typed.scaladsl.adapter.ClassicActorSystemOps.toTyped akka.actor.typed.scaladsl.adapter.`package`.ClassicActorSystemOps(system).toTyped
40 10548 1717 - 1717 Literal <nosymbol> ()
42 16468 1757 - 1830 Apply grizzled.slf4j.Logger.debug org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest MakeEventSerializer.this.logger.debug(("Creating make event serializer with name ".+(MakeEventSerializer.this.serializerName): String))
47 12759 1949 - 1987 Apply akka.actor.typed.ExtensionId.apply org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.api.technical.security.SecurityConfigurationExtension.apply(system)
49 9172 2039 - 2079 Select org.make.api.userhistory.UserHistorySerializers.serializers org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.api.userhistory.UserHistorySerializers.apply(conf).serializers
50 15333 2089 - 2132 Select org.make.api.sessionhistory.SessionHistorySerializers.serializers org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.api.sessionhistory.SessionHistorySerializers.apply(conf).serializers
50 9672 1992 - 2168 Apply scala.collection.IterableOps.++ org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.api.proposal.ProposalSerializers.apply(conf).serializers.++[stamina.json.JsonPersister[_, _]](org.make.api.userhistory.UserHistorySerializers.apply(conf).serializers).++[stamina.json.JsonPersister[_, _]](org.make.api.sessionhistory.SessionHistorySerializers.apply(conf).serializers).++[stamina.json.JsonPersister[_, _]](org.make.api.technical.job.JobSerializers.serializers)
51 13531 2142 - 2168 Select org.make.api.technical.job.JobSerializers.serializers org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.api.technical.job.JobSerializers.serializers
55 15751 2286 - 2300 Select spray.json.JsObject.fields org.make.api.technical.crm.crmservicecomponenttest,org.make.api.userhistory.userhistorytest context.fields
57 16484 2386 - 2445 Apply scala.Option.map org.make.api.userhistory.userhistorytest,org.make.api.technical.crm.crmservicecomponenttest fields.get("ipAddress").map[String](((x$1: spray.json.JsValue) => x$1.asInstanceOf[spray.json.JsString].value))
57 10448 2414 - 2444 Select spray.json.JsString.value org.make.api.userhistory.userhistorytest,org.make.api.technical.crm.crmservicecomponenttest x$1.asInstanceOf[spray.json.JsString].value
57 12327 2397 - 2408 Literal <nosymbol> org.make.api.userhistory.userhistorytest,org.make.api.technical.crm.crmservicecomponenttest "ipAddress"
58 14945 2450 - 2656 Apply spray.json.JsObject.apply org.make.api.technical.crm.crmservicecomponenttest,org.make.api.userhistory.userhistorytest spray.json.JsObject.apply(fields.++[spray.json.JsValue](maybeIp.map[(String, spray.json.JsString)](((ip: String) => scala.Predef.ArrowAssoc[String]("ipAddress").->[spray.json.JsString](spray.json.JsString.apply(IpAndHash.obfuscateIp(ip)))))).++[spray.json.JsValue](maybeIp.map[(String, spray.json.JsString)](((ip: String) => scala.Predef.ArrowAssoc[String]("ipAddressHash").->[spray.json.JsString](spray.json.JsString.apply(org.make.api.technical.security.SecurityHelper.generateHash(ip, salt)))))))
60 9686 2484 - 2553 Apply scala.Option.map org.make.api.userhistory.userhistorytest,org.make.api.technical.crm.crmservicecomponenttest maybeIp.map[(String, spray.json.JsString)](((ip: String) => scala.Predef.ArrowAssoc[String]("ipAddress").->[spray.json.JsString](spray.json.JsString.apply(IpAndHash.obfuscateIp(ip)))))
60 9210 2466 - 2650 Apply scala.collection.MapOps.++ org.make.api.technical.crm.crmservicecomponenttest,org.make.api.userhistory.userhistorytest fields.++[spray.json.JsValue](maybeIp.map[(String, spray.json.JsString)](((ip: String) => scala.Predef.ArrowAssoc[String]("ipAddress").->[spray.json.JsString](spray.json.JsString.apply(IpAndHash.obfuscateIp(ip)))))).++[spray.json.JsValue](maybeIp.map[(String, spray.json.JsString)](((ip: String) => scala.Predef.ArrowAssoc[String]("ipAddressHash").->[spray.json.JsString](spray.json.JsString.apply(org.make.api.technical.security.SecurityHelper.generateHash(ip, salt))))))
60 12658 2502 - 2513 Literal <nosymbol> org.make.api.technical.crm.crmservicecomponenttest,org.make.api.userhistory.userhistorytest "ipAddress"
60 13432 2502 - 2552 Apply scala.Predef.ArrowAssoc.-> org.make.api.technical.crm.crmservicecomponenttest,org.make.api.userhistory.userhistorytest scala.Predef.ArrowAssoc[String]("ipAddress").->[spray.json.JsString](spray.json.JsString.apply(IpAndHash.obfuscateIp(ip)))
60 15074 2517 - 2552 Apply spray.json.JsString.apply org.make.api.technical.crm.crmservicecomponenttest,org.make.api.userhistory.userhistorytest spray.json.JsString.apply(IpAndHash.obfuscateIp(ip))
60 9190 2526 - 2551 Apply org.make.api.technical.IpAndHash.obfuscateIp org.make.api.technical.crm.crmservicecomponenttest,org.make.api.userhistory.userhistorytest IpAndHash.obfuscateIp(ip)
61 11944 2611 - 2648 Apply org.make.api.technical.security.SecurityHelper.generateHash org.make.api.userhistory.userhistorytest,org.make.api.technical.crm.crmservicecomponenttest org.make.api.technical.security.SecurityHelper.generateHash(ip, salt)
61 15640 2583 - 2598 Literal <nosymbol> org.make.api.technical.crm.crmservicecomponenttest,org.make.api.userhistory.userhistorytest "ipAddressHash"
61 18041 2602 - 2649 Apply spray.json.JsString.apply org.make.api.userhistory.userhistorytest,org.make.api.technical.crm.crmservicecomponenttest spray.json.JsString.apply(org.make.api.technical.security.SecurityHelper.generateHash(ip, salt))
61 16380 2583 - 2649 Apply scala.Predef.ArrowAssoc.-> org.make.api.userhistory.userhistorytest,org.make.api.technical.crm.crmservicecomponenttest scala.Predef.ArrowAssoc[String]("ipAddressHash").->[spray.json.JsString](spray.json.JsString.apply(org.make.api.technical.security.SecurityHelper.generateHash(ip, salt)))
61 12668 2565 - 2650 Apply scala.Option.map org.make.api.userhistory.userhistorytest,org.make.api.technical.crm.crmservicecomponenttest maybeIp.map[(String, spray.json.JsString)](((ip: String) => scala.Predef.ArrowAssoc[String]("ipAddressHash").->[spray.json.JsString](spray.json.JsString.apply(org.make.api.technical.security.SecurityHelper.generateHash(ip, salt)))))