问题
I'm currently trying to get Keycloak bearer only to work with a spring boot application. I've followed the docs but I continue to get a NoSuchMethodError when I try to hit any of my endpoints. It seems similar to this keycloak issue. Based on that it looks like it should be working in all of the latest builds. I've followed this tutorial for the most part.
I have the project here for reference. (POM, KeycloakConfiguration)
Starting the app using mvn spring-boot:run
When hitting any route (in this example http://localhost:5767/health
) I get 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"
}
Which prints the following in the app's console:
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$2.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$2.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]
Using Keycloak-3.4.2.Final (Ran with ./Keycloak-3.4.2.Final/bin/standalone
)
Here is my current maven dependency tree.
And current environment (Refer to POM in repo for dependency versions)
Right now you can see I have the 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).
Am I missing some weird depdency conflict with Jetty versions? All the Jetty versions in the depdency tree are the same. So I am a bit lost on what is casuing this issue.
My desired behavior is to get 403's on all routes unless I pass a valid bearer token through the headers from whatever client I am using.
回答1:
It appears to be a dependency conflict. The Request
class in org.eclipse.jetty.server
of version 9.4.7 doesn't have a method getSessionManager()
. See here. Whereas, in the earlier version 9.3.2, this method was present.
So,Can you try by using 9.3.2 version of Jetty?
回答2:
Spring boot keycloak starter doesn't work with Jetty 9.4 There is an open bug: https://issues.jboss.org/browse/KEYCLOAK-9080
来源:https://stackoverflow.com/questions/48070223/keycloak-with-spring-boot-nosuchmethoderror-org-eclipse-jetty-server-request-get