See config file at /config folder
# Start keycloak container
docker compose up -d keycloak-rest-authz-resource-server# Start spring boot
./mvnw spring-boot:run -pl rest-authz-resource-serverThere are two users:
| Username | Password | Role |
|---|---|---|
| alice | alice | user |
| jdoe | jdoe | user, user_premium |
| endpoint | Permission |
|---|---|
| / | user |
| /protected/premium | user_premium |
GET http://localhost:8080
Authorization: Bearer ${alice_token}The result should be : Hello alice!
GET http://localhost:8080/protected/premium
Authorization: Bearer ${alice_token}The result should be : 403
GET http://localhost:8080/protected/premium
Authorization: Bearer ${jdoe_token}The result should be : Hello jdoe!
# Start keycloak container
docker compose up -d keycloak-bank-rest-authz-resource-server# Start spring boot
./mvnw spring-boot:run -pl bank-rest-authz-resource-serverPlease visit Keycloak admin console http://localhost:8180 with username|password admin|admin
and then create two users with following info.
| Username | Password | Role |
|---|---|---|
| bob | bob | bank_teller |
| alice | alice | account_owner |
This application is configured by policy-enforcer.json find more details
in keycloak policy-enforcer
| Endpoint | Methods | Users | Result |
|---|---|---|---|
/accounts/* |
GET |
bob/alice | permit |
/accounts/* |
POST,PUT |
bob | deny |
/accounts/* |
POST,PUT |
alice | permit |
This example using:
reactwithvitekeycloak-jslibrary
You can find more details in keycloak javascript-adapter
# Start keycloak container
docker compose up -d keycloak-javascript-adapterrun these commands
cd keycloak-javascript-adapternpm i npm run dev