- Docker and Docker Compose
- JDK 17
- Maven
- jq (for JSON processing)
- Build the application (including executing tests):
./mvnw clean package
- Start the services:
docker compose up --build -d
- Wait for all the services to be healthy (this may take a few minutes):
docker compose ps
- Try accessing the products endpoint without authentication (should return 401 Unauthorized):
curl -v -X GET http://localhost:8080/products
- Get an access token:
access_token=$(curl -X POST http://localhost:8081/realms/product-realm/protocol/openid-connect/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=product-client" \
-d "client_secret=product-secret" \
-d "username=test-user" \
-d "password=password" | jq -r .access_token)
- Access the products endpoint:
curl -X GET http://localhost:8080/products \
-H "Authorization: Bearer $access_token"
- Test the OAuth2 client flow using a spring OAuth2 client (which handles token management automatically):
# Get products through the OAuth2 client (with automatic token management)
curl -X GET http://localhost:8082/retail/products
- Automatically obtain a client credentials token from Keycloak
- Call the resource server with the token
- Apply retail markup to prices
- Return the marked-up product prices
- Keycloak: http://localhost:8081
- Resource Server (Protected Product API): http://localhost:8080
- OAuth2 Client: http://localhost:8082
docker-compose down -v