These assets are provided to perform the tasks described in the Java Application Demo guide.
Originally, this app was demonstrated during the Manage secrets, access, and encryption in the public cloud with Vault webinar.
To keep it simple and lightweight, the Java Sample App using Spring Cloud Vault guide used Vagrant to demonstrate the app. This repository also provides example deployments on various platforms:
You can run the sample as a standalone Java application. You will need a Vault instance and a Postgres instance to get started.
- Run the Postgres script at your Postgres instance.
- Run the Vault script at your Vault instance.
- Update the bootstrap.yaml file for your environment.
- Run the Java application.
- Try the API.
- Get Orders
$ curl -s -X GET \
http://localhost:8080/api/orders | jq
[
{
"id": 204,
"customerName": "Lance",
"productName": "Vault-Ent",
"orderDate": 1523656082215
}
]
- Create Order
$ curl -s -X POST \
http://localhost:8080/api/orders \
-H 'content-type: application/json' \
-d '{"customerName": "Lance", "productName": "Vault-Ent"}' | jq
{
"id": 204,
"customerName": "Lance",
"productName": "Vault-Ent",
"orderDate": 1523656082215
}
- Delete Orders
$ curl -s -X DELETE -w "%{http_code}" http://localhost:8080/api/orders | jq
200
Spring has an actuator we can use to facilitate the rotation of static credentials. Example below.
- Export your env vars
export VAULT_ADDR=http://localhost:8200
export VAULT_TOKEN=root
- Create the old secret.
$ curl -s \
--header "X-Vault-Token: ${VAULT_TOKEN}" \
--request POST \
--data '{"secret":"hello-old"}' \
--write-out "%{http_code}" ${VAULT_ADDR}/v1/secret/spring-vault-demo | jq
204
- Read the old secret.
$ curl -s http://localhost:8080/api/secret | jq
{
"key": "secret",
"value": "hello-old"
}
- Create the new secret.
$ curl -s \
--header "X-Vault-Token: ${VAULT_TOKEN}" \
--request POST \
--data '{"secret":"hello-new"}' \
--write-out "%{http_code}" ${VAULT_ADDR}/v1/secret/spring-vault-demo | jq
204
- Rotate the secret.
$ curl -s -X POST http://localhost:8080/actuator/refresh | jq
[
"secret"
]
- Read the new secret.
$ curl -s http://localhost:8080/api/secret | jq
{
"key": "secret",
"value": "hello-new"
}