I am writing an Authenticator provider for keycloak, that I package as a .jar
.
As soon as it uses a class from keycloak-services, I get a NoClassDefFoundError
.
I get the same error when the provider is deployed via "mvn wildfly:deploy
".
I must be missing something, but I rarely do java code and I am clueless at this point.
I defined the dependencies in pom.xml, and tried both 'provided' and 'compile' as scope:
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<scope>provided</scope>
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi</artifactId>
<scope>provided</scope>
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi-private</artifactId>
<scope>provided</scope>
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
<version>3.1.4.GA</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-services</artifactId>
<scope>provided</scope>
<version>${keycloak.version}</version>
</dependency>
</dependencies>
I get the error as soon as I add the following code to the authenticate function:
AuthenticationSessionModel authSession = context.getAuthenticationSession();
SerializedBrokeredIdentityContext serializedCtx =
SerializedBrokeredIdentityContext.readFromAuthenticationSession(
authSession, "BROKERED_CONTEXT");
The error I get:
20:05:03,844 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-6) Uncaught server error: java.lang.NoClassDefFoundError: org/keycloak/authentication/authenticators/broker/util/SerializedBrokeredIdentityContext
Because wildfly isolates the classloaders, I had to declare the dependencies in the META-INF/MANIFEST.MF file.
To do that, I added the following code to my pom.xml file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.keycloak.keycloak-services</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
(The solution was given to me on the keycloak user list: https://lists.jboss.org/pipermail/keycloak-user/2019-September/019108.html)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With