ClassLoading problem with Wildfly 23 and Keycloak 15.0.2

Hi,

I run Wildfly 23.0.2 in container and keycloak modules are on modules rid

root@9b0e9301f0de /]# ls -la /wildfly/modules/system/add-ons/keycloak/org/keycloak/
total 112
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 .
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 ..
-rw-rw-r-- 1 1001 root 6148 Sep 10 14:30 .DS_Store
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-adapter-core
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-adapter-spi
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-adapter-subsystem
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-authz-client
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-common
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-core
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-jboss-adapter-core
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-undertow-adapter
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-wildfly-adapter
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-wildfly-elytron-oidc-adapter
drwxrwxr-x 1 1001 root 4096 Sep 12 12:22 keycloak-wildfly-subsystem

standalone.xml has keycloak configured, I used jboss-cli to configure that and then used that config xml in the container.

Keycloak adapter seems to work since I get this message to the server log

12:22:58,906 INFO  [org.jboss.keycloak] (MSC service thread 1-7) Keycloak subsystem override for deployment ROOT.war

Next I get WARN

12:22:58,908 WARN  [org.jboss.modules.define] (MSC service thread 1-7) Failed to define class org.keycloak.adapters.elytron.KeycloakConfigurationServletListener in Module "org.keycloak.keycloak-wildfly-elytron-oidc-adapter" version 15.0.2 from local module loader @2654635 (finder: local module finder @737a135b (roots: /wildfly/provided_modules,/wildfly/modules,/wildfly/modules/system/layers/base,/wildfly/modules/system/add-ons/keycloak)): java.lang.NoClassDefFoundError: Failed to link org/keycloak/adapters/elytron/KeycloakConfigurationServletListener (Module "org.keycloak.keycloak-wildfly-elytron-oidc-adapter" version 15.0.2 from local module loader @2654635 (finder: local module finder @737a135b (roots: /wildfly/provided_modules,/wildfly/modules,/wildfly/modules/system/layers/base,/wildfly/modules/system/add-ons/keycloak))): javax/servlet/ServletContextListener
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)

And then ERROR

12:22:58,910 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."ROOT.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."ROOT.war".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment "ROOT.war"
	at org.jboss.as.server@15.0.1.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:189)
...
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.NoClassDefFoundError: Failed to link org/keycloak/adapters/elytron/KeycloakConfigurationServletListener (Module "org.keycloak.keycloak-wildfly-elytron-oidc-adapter" version 15.0.2 from local module loader @2654635 (finder: local module finder @737a135b (roots: /wildfly/provided_modules,/wildfly/modules,/wildfly/modules/system/layers/base,/wildfly/modules/system/add-ons/keycloak))): javax/servlet/ServletContextListener
	... 
	... 8 more

12:22:58,982 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "ROOT.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"ROOT.war\".POST_MODULE" => "WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"ROOT.war\"
    Caused by: java.lang.NoClassDefFoundError: Failed to link org/keycloak/adapters/elytron/KeycloakConfigurationServletListener (Module \"org.keycloak.keycloak-wildfly-elytron-oidc-adapter\" version 15.0.2 from local module loader @2654635 (finder: local module finder @737a135b (roots: /wildfly/provided_modules,/wildfly/modules,/wildfly/modules/system/layers/base,/wildfly/modules/system/add-ons/keycloak))): javax/servlet/ServletContextListener"}}

And finally server starts but ROOT.war doesn’t

Reference to org.keycloak.keycloak-wildfly-elytron-oidc-adapter is under <subsystem xmlns=“urn:wildfly:elytron:13.0” and that should be fine since create by cli script (./bin/jboss-cli.sh --file=bin/adapter-elytron-install-offline.cli)

I dont have any special class loading rules in the app. I have two keycloak deps

   <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-core</artifactId>
      <scope>provided</scope>
      <version>15.0.2</version>
    </dependency>
    <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-adapter-core</artifactId>
      <scope>provided</scope>
      <version>15.0.2</version>
    </dependency>

standalone.conf has following

export JBOSS_MODULEPATH=/wildfly/provided_modules

if [ ! -z $OPENSHIFT_WILDFLY_MODULE_PATH ]; then
   export JBOSS_MODULEPATH=$JBOSS_MODULEPATH:$OPENSHIFT_WILDFLY_MODULE_PATH
fi

export JBOSS_MODULEPATH=$JBOSS_MODULEPATH:/wildfly/modules

But that shouldn’t cause issue since module is loaded fine. If keycloak modules are misplaces, server doesn’t start at all.