This Java backend application uses the token-client module to requests access tokens from XSUAA
service via the ClientCredentialsTokenFlow.
There is no authentication done, i.e. the resulting tokens are not related to a user accessing the application.
Instead, the access token is issued for the bound service instance on behalf of the application itself.
mvn clean package
Deployment on Cloud Foundry
Use the cf CLI to create an XSUAA service instance based on the authentication settings in xs-security.json.
cf create-service xsuaa application xsuaa-token-client -c xs-security.json
The vars contain hosts and paths that need to be adapted.
Deploy the application using the cf CLI.
cf push --vars-file ../vars.yml
Deployment on Kubernetes
Execute the following docker commands to build and push the docker image to a repository.
Replace <repository>/<image>
with your repository and image name.
docker build -t <repository>/<image> .
docker push <repository>/<image>
In deployment.yml replace the placeholder <YOUR IMAGE TAG>
with the image tag created in the previous step.
Deploy the application using kubectl.
kubectl apply -f k8s/deployment.yml
The sample application provides a single HTTP endpoint:
/hello-token-client
- accessible without authentication
access Cloud Foundry deployment
You can access the application at:
https://java-tokenclient-usage-<<ID>>.<<LANDSCAPE_APPS_DOMAIN>>/hello-token-client
access Kubernetes deployment
You can access the application at:
https://java-tokenclient-api.<<K8S DOMAIN>>/java-tokenclient-usage/hello-token-client \
You should see something like this:
Access-Token: eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8v...
Access-Token-Payload: {"jti":"abcdefghijklmnopqrstuvwxyz123456","ext_attr":{"enhancer":"XSUAA","subaccountid":"...
Expired-At: 2024-10-17T04:31:46.397Z
If you no longer need the sample application, you can free up resources using the cf CLI or the Kubernetes CLI.
Cleanup commands for Cloud Foundry
cf delete -f java-tokenclient-usage
cf delete-service -f xsuaa-token-client
Cleanup command for Kubernetes
kubectl delete -f k8s/deployment.yml