Compare commits
2 commits
410a6adea2
...
0225ef383b
Author | SHA1 | Date | |
---|---|---|---|
Dominic Grimm | 0225ef383b | ||
Dominic Grimm | 8e10632ffd |
|
@ -34,7 +34,7 @@ lazy val root = project
|
||||||
.in(file("."))
|
.in(file("."))
|
||||||
.settings(
|
.settings(
|
||||||
name := "keycloak-event-listener-mqtt",
|
name := "keycloak-event-listener-mqtt",
|
||||||
version := "0.1.0",
|
version := "0.2.0",
|
||||||
scalaVersion := scala3Version,
|
scalaVersion := scala3Version,
|
||||||
resolvers += "Akka library repository".at("https://repo.akka.io/maven"),
|
resolvers += "Akka library repository".at("https://repo.akka.io/maven"),
|
||||||
libraryDependencies ++= keycloakDeps,
|
libraryDependencies ++= keycloakDeps,
|
||||||
|
|
|
@ -70,11 +70,10 @@ class MqttEventListenerProvider(
|
||||||
import concurrent.ExecutionContext.Implicits.global
|
import concurrent.ExecutionContext.Implicits.global
|
||||||
import MqttEventListenerProviderFactory.system
|
import MqttEventListenerProviderFactory.system
|
||||||
|
|
||||||
val topic: String = s"${mqttOptions.topic}/${payload.topic}"
|
|
||||||
val payloadBytes: Array[Byte] = Json.encode(payload).toByteArray
|
val payloadBytes: Array[Byte] = Json.encode(payload).toByteArray
|
||||||
|
|
||||||
val msg: MqttMessage =
|
val msg: MqttMessage =
|
||||||
MqttMessage(topic, ByteString.fromArray(payloadBytes))
|
MqttMessage(mqttOptions.topic, ByteString.fromArray(payloadBytes))
|
||||||
.withRetained(mqttOptions.retained)
|
.withRetained(mqttOptions.retained)
|
||||||
val future: Future[Done] = Source.single(msg).runWith(mqttSink)
|
val future: Future[Done] = Source.single(msg).runWith(mqttSink)
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ object MqttOptions:
|
||||||
end fromConfig
|
end fromConfig
|
||||||
end MqttOptions
|
end MqttOptions
|
||||||
|
|
||||||
private final case class MqttOptions(
|
final case class MqttOptions(
|
||||||
topic: String,
|
topic: String,
|
||||||
retained: Boolean,
|
retained: Boolean,
|
||||||
qos: MqttQoS
|
qos: MqttQoS
|
||||||
|
|
|
@ -65,7 +65,7 @@ object Payload extends FromEvent[Payload]:
|
||||||
end fromEvent
|
end fromEvent
|
||||||
end Payload
|
end Payload
|
||||||
|
|
||||||
private final case class Payload(
|
final case class Payload(
|
||||||
admin: Boolean,
|
admin: Boolean,
|
||||||
time: Long,
|
time: Long,
|
||||||
realm: String,
|
realm: String,
|
||||||
|
@ -76,17 +76,4 @@ private final case class Payload(
|
||||||
resourcePath: Option[String],
|
resourcePath: Option[String],
|
||||||
representation: Option[String],
|
representation: Option[String],
|
||||||
error: Option[String]
|
error: Option[String]
|
||||||
) derives Codec:
|
) derives Codec
|
||||||
private def result: String = if error.isDefined then "error" else "success"
|
|
||||||
|
|
||||||
def topic: String =
|
|
||||||
if admin
|
|
||||||
then
|
|
||||||
resourceType match
|
|
||||||
case Some(rType) =>
|
|
||||||
s"admin/${realm}/${result}/${rType.toLowerCase()}/${operationType.toLowerCase()}"
|
|
||||||
case None => throw new IllegalStateException
|
|
||||||
else
|
|
||||||
s"client/${realm}/${result}/${authDetails.clientId}/${operationType.toLowerCase()}"
|
|
||||||
end topic
|
|
||||||
end Payload
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ object PayloadAuthDetails extends FromEvent[PayloadAuthDetails]:
|
||||||
end fromEvent
|
end fromEvent
|
||||||
end PayloadAuthDetails
|
end PayloadAuthDetails
|
||||||
|
|
||||||
private final case class PayloadAuthDetails(
|
final case class PayloadAuthDetails(
|
||||||
realmId: String,
|
realmId: String,
|
||||||
clientId: String,
|
clientId: String,
|
||||||
userId: String,
|
userId: String,
|
||||||
|
|
Loading…
Reference in a new issue