I am trying to implement a custom Keycloak endpoint using the Java SPI.
There is an example, created by @dasniko, that seems a good starting point. Thanks @dasniko !
The code compiles, starting Keycloak with this provider also works. But accessing the new REST HTTP GET endpoint results in an HTTP 405.
curl -X GET http://localhost:8080/realms/master/my-rest-resource/hello
{"error":"HTTP 405 Method Not Allowed"}
Is this URL right? It should definitly be a HTTp GET endpoint: keycloak-extensions-demo/rest-endpoint/src/main/java/dasniko/keycloak/resource/MyResourceProvider.java at main · dasniko/keycloak-extensions-demo · GitHub
Enabling Keycloak Debug logs with env var KC_LOG_LEVEL: DEBUG
reveals more information:
keycloak-extensions-demo | 2023-12-18 14:53:55,786 DEBUG [org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext] (executor-thread-1) Restarting handler chain for exception exception: jakarta.ws.rs.WebApplicationException: HTTP 405 Method Not Allowed
keycloak-extensions-demo | at org.jboss.resteasy.reactive.server.handlers.ResourceLocatorHandler.handle(ResourceLocatorHandler.java:71)
keycloak-extensions-demo | at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:150)
keycloak-extensions-demo | at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:145)
keycloak-extensions-demo | at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
keycloak-extensions-demo | at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
keycloak-extensions-demo | at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
keycloak-extensions-demo | at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
keycloak-extensions-demo | at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
keycloak-extensions-demo | at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
keycloak-extensions-demo | at java.base/java.lang.Thread.run(Thread.java:840)
keycloak-extensions-demo |
keycloak-extensions-demo | 2023-12-18 14:53:55,786 DEBUG [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-1) Error response 405: jakarta.ws.rs.WebApplicationException: HTTP 405 Method Not Allowed
keycloak-extensions-demo | at org.jboss.resteasy.reactive.server.handlers.ResourceLocatorHandler.handle(ResourceLocatorHandler.java:71)
keycloak-extensions-demo | at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:150)
keycloak-extensions-demo | at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:145)
keycloak-extensions-demo | at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
keycloak-extensions-demo | at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
keycloak-extensions-demo | at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
keycloak-extensions-demo | at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
keycloak-extensions-demo | at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
keycloak-extensions-demo | at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
keycloak-extensions-demo | at java.base/java.lang.Thread.run(Thread.java:840)
I am using Keycloak 23 as defined in keycloak-extensions-demo/docker-compose.yml at main · dasniko/keycloak-extensions-demo · GitHub
This can be reproduced with:
git clone git@github.com:dasniko/keycloak-extensions-demo.git
cd keycloak-extensions-demo
- Enabling Keycloak logs in docker compose with
KC_LOG_LEVEL: DEBUG
./mvnw clean package -DskipTests && docker compose up
Does anyone know what’s going wrong here?
Is anyone here able to successfully run this example rest endpoint code?