I’m developing an application in which login and roles are entirely handled by Keycloak. My Java backend has an application database that also contains additional user business data. I’ve been asked to retrieve all users registered in the application based on their roles. The problem is that only Keycloak knows the roles, while I normally handle pagination on the database side.
What would be the best practice to efficiently achieve this goal?
Currently, I'm loading all user data from the database (filtering by other parameters I have in the DB, though it could be all of them), mapping their roles one by one, removing the roles I'm not interested in, and then paginating the remaining users.
Best practices
2 Replies
Maybe invert that approach:
- find all users with the role
- then query the DB for the additional user details.