Learn Keycloak Admin Rest Api in Spring Boot
I. Introduction Keycloak has provided an admin GUI where a user can manage his profile or an admin user to manage the realm which includ...

I. Introduction
Keycloak has provided an admin GUI where a user can manage his profile or an admin user to manage the realm which includes the roles, permissions, and users.II. Setting Up Keycloak
III. The Spring Boot 2 Project
2.) Make sure to add the following dependencies: keycloak-spring-boot-starter and spring-boot-starter-security.
3.) We need to extend the class KeycloakWebSecurityConfigurerAdapter as specified in the keycloak securing apps documentation below. See the code below.
4.) Due to some Keycloak issues, we need to extend the class KeycloakSpringBootConfigResolver. See the code below.
5.) I created a utility class that will help us initialize a Keycloak class that we can use to communicate and manage a Keycloak instance - KeycloakAdminClientUtils. See the code below.
6.) We then need a service to get or manage information from Keycloak depending on the user's role. For instance, the user I'm using has a manage-realm role, this means that I can call almost all the API provided by Keycloak. In my example, I'm returning the user's role as well as its profile. See class KeycloakAdminClientService.
7.) I create a REST controller class to use the service in #6 for demo. See KeycloakController.
8.) And finally, don't forget to specify the Keycloak configuration in application.properties.
9.) The Keycloak realm configuration and postman project I used for testing are both available in Github under the project's config folder.
Java Classes:
Post a Comment