I have a situation with a clean domain project (i....
# ktor
r
I have a situation with a clean domain project (i.e. no ktor, exposed or anything) and an api project, depending on the domain, ktor etc. In my domain I have a
data class DomainPrincipal
that of course does not (and should not) know of ktor
Principal
. However, when doing JWT mapping in ktor, I want to map to my domain model 🙂 but as far as I know, I cannot really do that because the data class is (as it should be) final. So, if not much mistaken, I need to work around this, am I correct in this? If so am I also correct in that there's basically two ways to work around it: • Having some kind of composition by
data class KtorDomainPrincipal(val domainPrincipal: DomainPrincipal): Principal
• Using the
by
keyword to make a subclass of principal that basically wraps the methods and fields of my
DomainPrincipal
is there any pros or cons that I should know of with the two? I think the first is easier to maintain whereas the second will have a cleaner and nicer interface
b
Generally just using composition is the way to go, then you can add additional session details in the principal. For accessing the domain object you can always add an extension method like
ApplicationCall.principal<KtorDomainPrincipal>.domainObject
. I'm not entirely sure why the empty placeholder
Principal
interface exists, it might be useful for us to remove it from Ktor authentication.