0

I'm writing a custom authentication SPI for Keycloak. To authenticate cookie, I want to use AuthenticationManager of keycloak-services. I've added keycloak-services as maven dependency in the project. It doesn't give any compilation error but after deploying the SPI on Keycloak, it's throwing me below exception.

Here is the Exception :

ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-68) Uncaught server error: java.lang.NoClassDefFoundError: org/keycloak/services/managers/AuthenticationManager at org.keycloak.examples.authenticator.SecretQuestionAuthenticator.authenticate(SecretQuestionAuthenticator.java:102) at org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:200) at org.keycloak.authentication.AuthenticationProcessor.authenticateOnly(AuthenticationProcessor.java:853) at org.keycloak.authentication.AuthenticationProcessor.authenticate(AuthenticationProcessor.java:722) at org.keycloak.protocol.AuthorizationEndpointBase.handleBrowserAuthenticationRequest(AuthorizationEndpointBase.java:145) at org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.buildAuthorizationCodeAuthorizationResponse(AuthorizationEndpoint.java:395) at org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.build(AuthorizationEndpoint.java:139)

Maven Dependency

<dependencies>
<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-core</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-server-spi</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-server-spi-private</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.jboss.logging</groupId>
    <artifactId>jboss-logging</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-services</artifactId>
    <scope>provided</scope>
</dependency>
</dependencies>
Utsav Shah
  • 177
  • 5

2 Answers2

0

It turns out that the way I was deploying the code was causing the issue. I was deploying the code on Keycloak using

mvn clean install wildfly:deploy

When we deploy the code using the above command, it's not able to load jar file in the keycloak context. To make it work, we have to deploy the code using module structure as mentioned in the Keycloak SPI. When we deploy the code using module method, we can add the dependencies in the module.xml file of the newly created module, which can then be used in the code.

Utsav Shah
  • 177
  • 5
0

I was also facing similiar issues in keycloak 15.0.2. Solved by following this link :

https://keycloak.discourse.group/t/how-to-get-authenticated-user-inside-realmresourceprovider/13260/2

In case the link isn't accessible, this is the solution:

you must add the jboss-deployment-structure.xml in META-INF of the jar with the required modules.

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.keycloak.keycloak-core" export="true"/>
            <module name="org.keycloak.keycloak-server-spi" export="true"/>
            <module name="org.keycloak.keycloak-server-spi-private" export="true"/>
            <module name="org.keycloak.keycloak-services" export="true"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>
Anwar Reefat
  • 79
  • 1
  • 8