p2-inc / keycloak-events

Useful Keycloak event listener implementations and utilities.
https://phasetwo.io
Other
168 stars 35 forks source link

java.lang.NoClassDefFoundError: com/github/xgp/util/BackOff (original keycloak 24.0.2) #56

Closed svyatoslavratov closed 4 months ago

svyatoslavratov commented 4 months ago

Hello!

I'm getting an error when try add ext-event-webhook to realm event listener in admin UI. But ext-event-http and ext-event-script add is good.

What is the reason? Do I need to manually install the dependency or is the problem on the keycloak-events side or am I misconfiguring docker-compose?

 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-7) Uncaught server error: java.lang.NoClassDefFoundError: com/github/xgp/util/BackOff
        at io.phasetwo.keycloak.events.WebhookSenderEventListenerProviderFactory.create(WebhookSenderEventListenerProviderFactory.java:28)
        at io.phasetwo.keycloak.events.WebhookSenderEventListenerProviderFactory.create(WebhookSenderEventListenerProviderFactory.java:12)
        at org.keycloak.services.DefaultKeycloakSession.getProvider(DefaultKeycloakSession.java:195)
        at org.keycloak.models.KeycloakBeanProducer_ProducerMethod_getKeycloakSession_XoSEUTXOsE3bpqXlGMAykCiECUM_ClientProxy.getProvider(Unknown Source)
        at org.keycloak.services.resources.admin.AdminEventBuilder.lambda$addListeners$0(AdminEventBuilder.java:136)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
        at org.keycloak.services.resources.admin.AdminEventBuilder.addListeners(AdminEventBuilder.java:135)
        at org.keycloak.services.resources.admin.AdminEventBuilder.refreshRealmEventsConfig(AdminEventBuilder.java:119)
        at org.keycloak.services.resources.admin.RealmAdminResource.updateRealmEventsConfig(RealmAdminResource.java:746)
        at org.keycloak.services.resources.admin.RealmAdminResource$quarkusrestinvoker$updateRealmEventsConfig_819a7611841478b25afbae197af50b540fbebc6f.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:582)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:840)

Part of my docker-compose.yml:

version: "3.9"

services:
  keycloak-postgres:
    image: postgres
    container_name: keycloack-postgres
    restart: on-failure
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: postgres
    healthcheck:
      test: pg_isready -d postgres
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 5s
    ports:
      - 5444:5432
    deploy:
      resources:
        limits:
          memory: 256M

  keycloak:
    image: quay.io/keycloak/keycloak:24.0.2
    container_name: keycloak
    command: ["start-dev", "--import-realm"]
    environment:
      KC_DB: postgres
      KC_DB_URL: jdbc:postgresql://keycloak-postgres:5432/postgres
      KC_DB_USERNAME: postgres
      KC_DB_PASSWORD: postgres
      KC_DB_SCHEMA: public
      KC_LOG_LEVEL: ALL
      KC_FEATURES: preview
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin
      KEYCLOAK_LOGLEVEL: DEBUG
    volumes:
      - ./keycloak-events/target/original-keycloak-events-0.28-SNAPSHOT.jar:/opt/keycloak/providers/original-keycloak-events-0.28-SNAPSHOT.jar
    ports:
      - 8282:8080
    depends_on:
      keycloak-postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://0.0.0.0:8080/realms/master"]
      start_period: 10s
      interval: 30s
      retries: 3
      timeout: 5s
image
xgp commented 4 months ago

don't use the original-keycloak-events jar. use the keycloak-events jar which bundles the dependencies into a fat jar (see https://github.com/p2-inc/keycloak-events/blob/main/pom.xml#L48-L70)

svyatoslavratov commented 4 months ago

@xgp thanks for the quick reply! Could you please tell me why when I send a GET http://localhost:8282/auth/realms/test-realme/webhooks I get: { "error": "Unable to find a matching method for the target resource", { "error_description": "Please refer to the debug level server log for more information about this error." } My keycloak client with manage-events, view-events privileges.

xgp commented 4 months ago

That's telling you something is wrong with the path. From your docker-compose, it doesn't look like you have a relative path variable set. So your URI would be something like http://localhost:8282/realms/test-realme/webhooks (no /auth)

svyatoslavratov commented 4 months ago

@xgp Wow, thank you! Spent a lot of time to solve this problem, digging into sources and tests. Thank you!