Reputation: 143
I'm implementing a Keycloak authentication provider (for Keycloak 6.0.1) which returns a message when a user is temporarily locked (like specified at Keycloak Custom message on user temporary lock)
When I do mvn clean install wildfly:deploy
I get :
[ERROR] Caused by: java.util.ServiceConfigurationError: org.keycloak.authentication.AuthenticatorFactory: Provider com.mumba.cloud.authenticator.LockedUserAuthenticatorFactory could not be instantiated
[ERROR] Caused by: java.lang.NoClassDefFoundError: Failed to link com/mumba/cloud/authenticator/LockedUserAuthenticator (Module \"deployment.lockeduser-authenticator-1.0-SNAPSHOT.jar\" from Service Module Loader): org/keycloak/authentication/authenticators/browser/UsernamePasswordForm"}}}}
I'm looking for some help on how to track down why I'm getting the java.lang.NoClassDefFoundError and why Maven (or maybe it's wildfly) can't seem to find org/keycloak/authentication/authenticators/browser/UsernamePasswordForm
It isn't a compile-time error, and I believe my import statement below is correct for UsernamePasswordForm (see code below).
I also think I have correctly added the dependency (keycloak-services) to my pom.xml (see below).
I'm very new to Maven (and Java/Keycloak development), so I'm not sure where to dig to track this down.
Anyone have any pointers?
package com.mumba.cloud.authenticator;
import org.keycloak.authentication.authenticators.browser.UsernamePasswordForm;
public class LockedUserAuthenticator extends UsernamePasswordForm {
@Override
protected String tempDisabledError() {
return "ACCOUNT IS temporarily disabled.";
}
}
My pom.xml includes :
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<keycloak-version>6.0.1</keycloak-version>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>${keycloak-version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-services</artifactId>
<version>${keycloak-version}</version>
</dependency>
...
Upvotes: 3
Views: 2123
Reputation: 309
You need to add explicit dependencies to avoid class-loading issues at runtime.
Here is what you need to add to your pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<!-- This is required since we need to add the jboss module references
to the resulting jar -->
<manifestEntries>
<!-- Adding explicit dependencies to avoid class-loading issues at runtime -->
<Dependencies>
<![CDATA[org.keycloak.keycloak-core,org.keycloak.keycloak-services]]></Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Also, add scope provided
to you dependencies as follows:
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-services</artifactId>
<version>${keycloak.version}</version>
<scope>provided</scope>
</dependency>
Upvotes: 5