A Spring Boot application with Keycloak integration for authentication and authorization.
- Docker and Docker Compose
- Java 17
- Gradle
- Make
- Google Cloud Console account (for OAuth credentials)
-
Google OAuth Setup
- Go to Google Cloud Console
- Create a new project
- Enable Google OAuth API
- Create OAuth 2.0 credentials
- Add authorized redirect URIs:
http://localhost:8180/realms/ln-foot-01/broker/google/endpointhttp://localhost:8180/realms/ln-foot-01/broker/google/endpoint/login
-
Environment Configuration
- Copy
.env.exampleto.env - Update the following variables:
GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret KEYCLOAK_ADMIN=admin KEYCLOAK_ADMIN_PASSWORD=your-secure-password
- Copy
The project includes a Makefile for common operations:
# Start all services (Keycloak + Spring Boot)
make dev
# Build the application
make build
# Run tests
make test
# Clean everything
make clean-all
# Show all available commands
make help-
Start Keycloak
docker compose up -d
- Wait for Keycloak to start (usually takes 30-60 seconds)
- Access Keycloak admin console at
http://localhost:8180 - Login with admin credentials from
.env
-
Start Spring Boot Application
./gradlew bootRun
- The application will start on port 8080
- Access Swagger UI at
http://localhost:8080/swagger-ui/index.html
- Swagger UI:
http://localhost:8080/swagger-ui/index.html - OpenAPI JSON:
http://localhost:8080/v3/api-docs
- All endpoints are public by default
- Protected endpoints are secured with
@PreAuthorizeannotations - Authentication is handled by Keycloak with Google OAuth
- JWT tokens are used for API authentication
- Two roles are available:
admin: Full access to all endpointsuser: Limited access to specific endpoints
- The application uses Spring Boot 3.4.4
- Keycloak is configured with Google as the String provider
- PostgreSQL is used as the database
- Swagger/OpenAPI for API documentation
.
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── co/hublots/ln_foot/
│ │ │ ├── config/
│ │ │ ├── controllers/
│ │ │ ├── models/
│ │ │ └── services/
│ │ └── resources/
│ └── test/
├── .docker/
│ └── keycloak-config/
├── Dockerfile
├── Makefile
├── compose.yml
└── build.gradle
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request