Skip to content
Advertisement

Keycloak java.lang.NoClassDefFoundError: java/security/acl/Group using Springboot

So we are building a Springboot back-end with Keycloak integration. But we get the following error when running the back-end on a docker swarm service:

2020-06-29 21:17:51.694 ERROR 1 --- [nio-3304-exec-1] o.a.c.c.C.[Tomcat].[localhost]           : Exception Processing /Suitless/latest/

java.lang.NoClassDefFoundError: java/security/acl/Group

    at org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve.createPrincipalFactory(KeycloakAuthenticatorValve.java:96) ~[spring-boot-container-bundle-10.0.1.jar!/:10.0.1]
    at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.createSessionTokenStore(AbstractKeycloakAuthenticatorValve.java:262) ~[spring-boot-container-bundle-10.0.1.jar!/:10.0.1]
    at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.getTokenStore(AbstractKeycloakAuthenticatorValve.java:251) ~[spring-boot-container-bundle-10.0.1.jar!/:10.0.1]
    at org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve.getTokenStore(KeycloakAuthenticatorValve.java:106) ~[spring-boot-container-bundle-10.0.1.jar!/:10.0.1]
    at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.checkKeycloakSession(AbstractKeycloakAuthenticatorValve.java:228) ~[spring-boot-container-bundle-10.0.1.jar!/:10.0.1]
    at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:180) ~[spring-boot-container-bundle-10.0.1.jar!/:10.0.1]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

Caused by: java.lang.ClassNotFoundException: java.security.acl.Group
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589) ~[na:na]
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) ~[run.jar:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]

    ... 19 common frames omitted

I tried it with JDK 8 and JDK 11 since the following post implies that the wrong JDK can cause a problem: Stackoverflow post. It still gives this error.

The following is our build.gradle setup:

    ext {
        springBootVersion = '2.3.1.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id 'org.springframework.boot' version '2.3.1.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

version = '0.0.1-SNAPSHOT'

bootJar {
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-hateoas'
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    implementation 'org.springframework.boot:spring-boot-starter-validation'

    implementation group: 'joda-time', name: 'joda-time', version: '2.3'
    implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
    implementation 'javax.xml.bind:jaxb-api:2.3.0'

    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation group: 'org.keycloak', name: 'keycloak-spring-boot-starter', version: '10.0.1'

    testImplementation('org.springframework.boot:spring-boot-starter-test')
    annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}

Advertisement

Answer

Thanks for the comments. The problem that causes this error for me was the fact that my Dockerfile always pulled the latest JDK version. This is not version 11 or 8 but 14. So I just added a specific version to it in order for Keycloak not to break.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement