Pear
Pear

Reputation: 470

Use third party libraries in Keycloak

I'd like to use kafka-clients for my keycloak module, in order to publish every login event into it.

The problem is in the deployment process : I used the "module way" for my custom keycloak providers packaged in a jar, declaring kafka-clients as a module dependency. As it doesn't exists, I also manually created a kafka-clients module. Still, I have issues on startup because of an unfound class :

java.lang.ClassNotFoundException: javax.net.ssl.KeyManagerFactory from [Module "org.apache.kafka.kafka-clients"

Maybe an other dependency is missing. Anyway, I don't want to handle all dependencies troubles manually.

So my question is : What is the best way to deploy a custom keycloak SPI provider, requiring third party dependencies ?

Should I build an EAR ? A WAR ? Is a JAR enough ?

Upvotes: 4

Views: 1249

Answers (1)

Julien C.
Julien C.

Reputation: 966

A JAR is enough if you add kafka-clients dependency to it.

You can have a look at how keycloak-metrics-spi bundle prometeus dependencies in its own jar (using gradle)

configurations {
    bundleLib
}

dependencies {
    bundleLib group: 'io.prometheus', name: 'simpleclient_common', version: prometheusVersion
    bundleLib group: 'io.prometheus', name: 'simpleclient_hotspot', version: prometheusVersion
    configurations.compile.extendsFrom(configurations.bundleLib)
}

jar {
    from {
        configurations.bundleLib.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

An EAR would work too (and would allow you hot deployment), you only need to add kafka-clients to the lib directory of your archive.

Upvotes: 3

Related Questions