I want to create a custom UserStorageProvider that communicates with a servlet to handle user lookup and validation, all against my external database without storing this information in Keycloak. Is this possible?
I have implemented a CustomUserStorageProvider in Keycloak that communicates with a servlet to fetch user details and validate credentials. The servlet interacts with an external database to retrieve user information and validate user credentials. Here is a summary of what I’ve done:
- User Lookup:
- Implemented the
UserLookupProviderinterface to handle user retrieval by username and email. - The
getUserByUsernamemethod sends a GET request to the servlet, which responds with user details in JSON format. This data is then mapped to aUserModelobject.
- Credential Validation:
- Implemented the
CredentialInputValidatorinterface to handle credential validation. - The
isValidmethod sends a POST request to the servlet with the username and password, and the servlet validates the credentials against the external database.
the first step is loggin the correct info in the console, but thows this error:
SERVICES0013: Failed authentication: jakarta.persistence.EntityNotFoundException: Unable to find org.keycloak.models.jpa.entities.UserEntity with id eb05471c-58c6-4fab-85c1-0d71da080942.
it seems that is trying to find the user id in keycloak cache or db