p2-inc / keycloak-events

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

Can't get the list of webhooks (cors class not found) #53

Closed jangxx closed 5 months ago

jangxx commented 5 months ago

I'm running Keycloak 24.0.1 inside of the default quay.io/keycloak/keycloak docker image with a built version of the plugin mounted into the container as a volume. I also set some environment variables in the docker compose file:

    environment:
      KEYCLOAK_HTTP_PORT: 8080
      PROXY_ADDRESS_FORWARDING: 'true'
      KC_HOSTNAME: "<my hostname>"
      KC_PROXY: "edge"
      JAVA_OPTS: "-Xms64m -Xmx4G -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8"
    volumes:
      - ./extensions/keycloak-events-0.26.jar:/opt/keycloak/providers/keycloak-events-0.26.jar

I'm now trying to list all webhooks by using the respective endpoint, but all I'm getting is a HTTP 500 response and the logs containing the following lines:

2024-03-20 18:08:36,170 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-27) Uncaught server error: java.lang.NoClassDefFoundError: org/keycloak/services/resources/Cors
    at io.phasetwo.keycloak.resources.CorsResource.setupCors(CorsResource.java:37)
    at io.phasetwo.keycloak.resources.AbstractAdminResource.setupCors(AbstractAdminResource.java:61)
    at io.phasetwo.keycloak.resources.AbstractAdminResource.setup(AbstractAdminResource.java:48)
    at io.phasetwo.keycloak.resources.WebhooksResourceProvider.getRealmResource(WebhooksResourceProvider.java:14)
    at io.phasetwo.keycloak.resources.BaseRealmResourceProvider.getResource(BaseRealmResourceProvider.java:30)
    at org.keycloak.services.resources.RealmsResource.resolveRealmExtension(RealmsResource.java:266)
    at org.keycloak.services.resources.RealmsResource$quarkusrestinvoker$resolveRealmExtension_c7e400748748bf35309bc60d82a4789f2a0e2d02.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)
Caused by: java.lang.ClassNotFoundException: org.keycloak.services.resources.Cors
    ... 17 more

Googling for this error leads to no results so I assume it's a bug somewhere in the plugin where it doesn't like some part of my setup.

xgp commented 5 months ago

Thanks. We have not yet ported to 24. If you want to try the branch where we're working on it, please pull the xgp/24-testcontainers branch and build from source.

xgp commented 5 months ago

Fixed in #51

jangxx commented 5 months ago

Okay, I pulled the xgp/24-testcontainers branch, ran mvn clean install and got it to build. I had to add .withEnv("JAVA_OPTS", "-Xms64m -Xmx4G") at line 47 in src\test\java\io\phasetwo\keycloak\resources\AbstractResourceTest.java to get the keycloak container to not throw an out of memory error, but after that all the tests showed success (even though they were all clearly throwing errors about being unable to communicate with the keycloak docker container, but whatever).

The resulting jar file seems to work in letting me create, fetch and delete webhooks and the webhooks also get triggered correctly. Thanks a lot.

jangxx commented 5 months ago

Oh, looks like you were faster than me, alright. I'm going to check out the PR.