Debugging Custom SPI

3,238 views
Skip to first unread message

Adam van den Hoven

unread,
Dec 18, 2019, 2:06:32 PM12/18/19
to keyclo...@googlegroups.com
Hey all, 

I need to work on a Custom SPI and need some help figuring how to debug it. 

The dev machine I'm using is a VM created by the guy before me and it has Keycloak running as a standalone. 

I'd like to do live debugging but I don't know if that'll work with IntelliJ. I'm not a Java developer normally (mostly I work in Visual Studio) so I'm not quite up to speed on IntelliJ, so it's possible I'm missing something obvious.  

Does anyone know how to do what I want or of a resource that will help me?

Adam

Thomas Darimont

unread,
Dec 18, 2019, 4:14:38 PM12/18/19
to Adam van den Hoven, Keycloak User
Hello Adam,

one way to debug Keycloak extensions is by starting Keycloak with the deployed extension and remote debugging enabled, e.g.:
bin/standalone.sh -c standalone-ha.xml --debug

This starts Keycloak with remote debugging enabled, where the JVM accepts debug connections on a local network port like 8787, indicated by the 
"Listening for transport dt_socket at address: 8787" log entry that gets printed during server start.

We now need to setup a remote debugging configuration in IntelliJ to attach the Debugger to our Keycloak instance.
To do that, open the project with the module that contains your extension in IntelliJ. 
Then create a new debug run configuration by selecting the menu entry Run -> Debug... -> Edit Configurations.
Click on the "+" icon in the upper left corner and select "Remote". This creates a new remote debug configuration.
I usually set the name of this debug config to something like "Keycloak Remote Debug (local)".
Change the hostname to localhost and the port to 8787.
Change "Use module classpath" to the intellij project / module with your extension code.

Then click "apply" to save the configuration. Now you can start Keycloak with the --debug parameter, if it is not already running.
Now you can click on Debug in the dialog to attach the debugger to the Keycloak process or select your newly created debug configuration 
from the toolbar and click the green debug icon.

That's it. You should now be able the set breakpoints and IntelliJ should stop the execution once a breakpoint is hit.

HTH.

Cheers,
Thomas

--
You received this message because you are subscribed to the Google Groups "Keycloak User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keycloak-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-user/CAAkH_kMhygp2YvX%2BBGd7gL9pqQQhQFic5M80t8zAtyqxPG-t-Q%40mail.gmail.com.

Adam van den Hoven

unread,
Dec 19, 2019, 3:48:29 PM12/19/19
to Thomas Darimont, Keycloak User
Thanks Thomas, 

This worked perfectly.

Adam
Reply all
Reply to author
Forward
0 new messages