KeyCloak custom REST Endpoint - Admin client classes not found

I have implemented a custom REST endpoint in KeyCloak 9.0.3. This endpoint will be invoked by an external UI layer to complete the entire registration flow including creating the user and sending the verification flow. In the SPI code, I am invoking the Admin REST client to create the user and send the verification email. I get an error when I invoke this service.

ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-42) Uncaught server error: java.lang.NoClassDefFoundError: org/keycloak/admin/client/KeycloakBuilder

My POM file has the dependency included -

<dependency>
  <groupId>org.keycloak</groupId>
  <artifactId>keycloak-admin-client</artifactId>
 </dependency>

I have tried adding a provided depenency as well but no luck.
Any ideas on what I am missing here? Or is there a problem with accessing the Admin REST API from within a custom SPI?

1 Like

It’s possible you need to add this to your jboss-deployment-structure.xml file.
An example can be found here for such a file, take note of the location of the file also.

In your case you’ll probably need to add

<module name="org.keycloak.keycloak-admin-client" />

Not tried it though but I expect this will solve your problem, let us know how it went

Thanks but now I get a …

Caused by: org.jboss.modules.ModuleNotFoundException: org.keycloak.keycloak-admin-client
at org.jboss.modules.Module.addPaths(Module.java:1266)
at org.jboss.modules.Module.link(Module.java:1622)
at org.jboss.modules.Module.relinkIfNecessary(Module.java:1650)
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:299)
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:283)
at org.jboss.as.server.moduleservice.ModuleLoadService.start(ModuleLoadService.java:93)

2 Likes

@sab.surendran I am getting the same error. Did you solved the issue?

I may be incorrect, but I don’t think the keycloak-admin-client is available as a module in the standard Keycloak server. You’d have to put the keycloak-admin-client jar file into your ear file at the top level, and put it in your META-INF/application.xml as a java module.

Let me know if there’s anything I can do to help with this!

Hi… That is correct. I was able to resolve it using the admin client as a module.
Add the admin client to the modules directory inside KeyCloak.
And I added a META-INF\services\jboss-deployment-structure.xml to my custom provider jar.

 <?xml version="1.0" encoding="UTF-8"?>
 <jboss-deployment-structure>
     <deployment>
         <dependencies>
             <module name="org.keycloak.keycloak-admin-client" />
         </dependencies>
     </deployment>
 </jboss-deployment-structure>

Hello,
I am stuck at the same place! Can you suggest how you added keycloak-admin-client as a module? Also for adding the said module is any jar downloaded?

Thanks,
Romil Shah