keycloak-event-listener-mqtt/src/main/scala/net/dergrimm/keycloak/providers/events/mqtt/PayloadAuthDetails.scala

57 lines
1.7 KiB
Scala

/*
* Copyright 2024 Dominic Grimm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dergrimm.keycloak.providers.events.mqtt
import org.keycloak.events.Event
import org.keycloak.events.admin.{AdminEvent, AuthDetails}
import org.keycloak.models.KeycloakSession
import io.bullet.borer.Codec
import io.bullet.borer.derivation.MapBasedCodecs._
import io.bullet.borer.NullOptions.given
object PayloadAuthDetails extends FromEvent[PayloadAuthDetails]:
def fromEvent(event: Event, session: KeycloakSession): PayloadAuthDetails =
PayloadAuthDetails(
realmId = event.getRealmId(),
clientId = event.getClientId(),
userId = event.getUserId(),
ipAddress = event.getIpAddress()
)
end fromEvent
def fromEvent(
event: AdminEvent,
session: KeycloakSession
): PayloadAuthDetails =
val auth: AuthDetails = event.getAuthDetails()
PayloadAuthDetails(
realmId = auth.getRealmId(),
clientId = auth.getClientId(),
userId = auth.getClientId(),
ipAddress = auth.getIpAddress()
)
end fromEvent
end PayloadAuthDetails
private final case class PayloadAuthDetails(
realmId: String,
clientId: String,
userId: String,
ipAddress: String
) derives Codec