NoClassDefFoundError from Maven deploy when attempting to create a custom authenticator provider for Keycloak

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>
...

java maven wildfly

replied in the mailing list: Google Groups

tl;dr you need to have a manifest in your jar that says which keycloak modules you depend on

1 Like

Thanks heaps.

In case it helps someone else, I ended up with the following, which worked for my situation:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>lib/</Class-Path>
                        <Dependencies>org.keycloak.keycloak-services</Dependencies>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>