This project is a demonstration of integrating Spring Boot 3.x with Spring Security 6 and Keycloak for secure authentication and authorization.
Spring Boot is a powerful framework for building Java applications with minimal setup, while Spring Security provides robust authentication and authorization mechanisms. Keycloak is an open-source Identity and Access Management solution that adds authentication and authorization to applications.
This project combines these technologies to demonstrate a secure authentication and authorization setup using Spring Boot, Spring Security, and Keycloak.
Before getting started, ensure you have the following prerequisites installed:
- Java Development Kit (JDK) 11 or higher
- Apache Maven
- Docker (for running Keycloak)
To set up this project, follow these steps:
- Clone this repository to your local machine.
- Ensure Docker is installed and running.
- Navigate to the
keycloak
directory within the project. - Run the Keycloak server using Docker Compose:
docker-compose up -d
- Once Keycloak is up and running, proceed to configure it.
Keycloak needs to be configured with the appropriate realm, client, roles, and users. Follow these steps to configure Keycloak:
- Access the Keycloak administration console by navigating to
http://localhost:8080/auth
in your web browser. - Log in with the default administrator credentials (
admin
/admin
). - Create a new realm for your application.
- Create a client within the realm and configure its settings.
- Define roles and permissions within the realm.
- Create users and assign roles to them.
- Once Keycloak is configured, proceed to configure your Spring Boot application to integrate with it.
To use this project:
- Configure Keycloak as described in the Configuration section.
- Configure the Spring Boot application to integrate with Keycloak.
- Run the Spring Boot application.
- Access the application in your web browser.
- You should be redirected to the Keycloak login page to authenticate.
- After successful authentication, you will be redirected back to the application.
Contributions are welcome! If you'd like to contribute to this project, please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License. Feel free to use, modify, and distribute the code for both commercial and non-commercial purposes.