spring 启动 NoSuchMethodError org.eclipse.jetty.server.Request.getSessionManager()Lorg/eclipse/jetty/server/SessionManager 的 Keycloak

Keycloak with spring boot NoSuchMethodError org.eclipse.jetty.server.Request.getSessionManager()Lorg/eclipse/jetty/server/SessionManager

我目前正在尝试让 Keycloak 承载仅与 spring 启动应用程序一起使用。我已经按照文档进行操作,但是当我尝试访问我的任何端点时,我仍然会收到 NoSuchMethodError。好像和这个类似keycloak issue。基于此,它看起来应该适用于所有最新版本。 我大部分时间都在关注 this tutorial

我有项目here for reference. (POM, KeycloakConfiguration)

使用 mvn spring-boot:run

启动应用程序

当到达任何路线时(在这个例子中 http://localhost:5767/health)我得到 this error:

{
    "timestamp": 1514942790219,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "java.lang.NoSuchMethodError",
    "message": "java.lang.NoSuchMethodError: org.eclipse.jetty.server.Request.getSessionManager()Lorg/eclipse/jetty/server/SessionManager;",
    "path": "/health"
}

在应用程序的控制台中打印 the following

2018-01-02 19:22:35.926  INFO 6201 --- [           main] com.ringofstorms.jservice.Application    : Started Application in 9.381 seconds (JVM running for 13.906)
2018-01-02 19:26:30.176  WARN 6201 --- [tp1664999292-17] org.eclipse.jetty.server.HttpChannel     : /health

java.lang.NoSuchMethodError: org.eclipse.jetty.server.Request.getSessionManager()Lorg/eclipse/jetty/server/SessionManager;
    at org.keycloak.adapters.jetty.KeycloakJettyAuthenticator.createSessionManagement(KeycloakJettyAuthenticator.java:66) ~[spring-boot-container-bundle-3.4.1.Final.jar:3.4.1.Final]
    at org.keycloak.adapters.jetty.core.AbstractKeycloakJettyAuthenticator.validateRequest(AbstractKeycloakJettyAuthenticator.java:292) ~[spring-boot-container-bundle-3.4.1.Final.jar:3.4.1.Final]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:483) ~[jetty-security-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) ~[jetty-servlet-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.Server.handle(Server.java:561) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:334) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) [jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) [jetty-io-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104) [jetty-io-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.io.ChannelEndPoint.run(ChannelEndPoint.java:124) [jetty-io-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679) [jetty-util-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:597) [jetty-util-9.4.7.v20170914.jar:9.4.7.v20170914]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]

使用 Keycloak-3.4.2.Final(运行 和 ./Keycloak-3.4.2.Final/bin/standaloneHere is my current maven dependency tree. And current environment(依赖版本请参考 repo 中的 POM)

现在你可以看到我有 keycloak-spring-security-adapter depdenency commented out, and am attempting to just do the security through the application.yaml like the tutorial does BEFORE it introduces the adapter and java configuration (which is also commented out).

我是否遗漏了一些与 Jetty 版本的奇怪的依赖冲突?依赖树中的所有 Jetty 版本都是相同的。所以我对导致这个问题的原因有点迷茫。

我想要的行为是 在所有路由上获得 403,除非我从我使用的任何客户端通过 headers 传递有效的承载令牌。

这似乎是一个依赖冲突。 9.4.7版本org.eclipse.jetty.server中的Requestclass没有方法getSessionManager()。参见 here. Whereas, in the earlier version 9.3.2,此方法已存在。

那么,你能用9.3.2版本的Jetty试试吗?

Spring boot keycloak starter 不适用于 Jetty 9.4 有一个未解决的错误: https://issues.jboss.org/browse/KEYCLOAK-9080