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

941 views
Skip to first unread message

Kenn Baker

unread,
Jan 14, 2021, 2:24:16 AM1/14/21
to Keycloak User

I'm implementing a Keycloak authentication provider (for Keycloak 6.0.1) which returns a message when a user is temporarily locked

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

Garth

unread,
Jan 14, 2021, 5:05:07 AM1/14/21
to keyclo...@googlegroups.com
Hi Ken,

Are you building a jar that will be put in the jboss `deployments/` directory? If so, you need to have a manifest in your jar that says which keycloak modules you depend on. You can do that with the `maven-jar-plugin` in your pom like this:

```
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<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-common,org.keycloak.keycloak-core,org.keycloak.keycloak-server-spi,org.keycloak.keycloak-server-spi-private,org.apache.httpcomponents,org.keycloak.keycloak-services,org.jboss.logging,javax.api,javax.jms.api,javax.transaction.api,com.fasterxml.jackson.core.jackson-core,com.fasterxml.jackson.core.jackson-annotations,com.fasterxml.jackson.core.jackson-databind,com.google.guava]]></Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
...
</plugins>
</build>
...
```

Note, the content of your dependency list may differ based on which keycloak module dependencies you have.

There is a different approach if you are using an ear file, so let us know your setup, and we can help further.

Best wishes,
Garth
> --
> You received this message because you are subscribed to the Google
> Groups "Keycloak User" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to keycloak-use...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/keycloak-user/09dc69ce-dcae-4191-a404-b0fb32db2f62n%40googlegroups.com <https://groups.google.com/d/msgid/keycloak-user/09dc69ce-dcae-4191-a404-b0fb32db2f62n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Kenn Baker

unread,
Jan 17, 2021, 7:14:41 PM1/17/21
to Keycloak User
Thanks heaps Garth. This worked for me.

If people are having issue with this, you might find some of the information at https://stackoverflow.com/questions/57778240/noclassdeffounderror-in-a-provider-jar-when-using-a-class-from-org-keycloak-auth#answer-57791073 to be helpful.

And, in case it helps anyone, I'm including the plugin entry that worked for me (for my situation, it seems like I needed to add org.keycloak.keycloak-services to Dependencies.

            <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>
Reply all
Reply to author
Forward
0 new messages