How to get the user which is calling a microservice API endpoint

What product/components do you use and which version/fix level are you on?

Cumulocity 1011.0.28

Is your question related to the free trial, or to a production (customer) instance?


What are you trying to achieve? Please describe it in detail.

Within the microservice SDK, how could we get the username of the user which is calling a Microservice API endpoint?


Hi Kai,

not sure if this is outdated but this is how I did this some years ago in my REST Controller:

Authentication auth = SecurityContextHolder.getContext().getAuthentication();
SecurityUserDetails securityUserDetails = ((SecurityUserDetails)auth.getPrincipal());

This is the generic Spring based way to access calling user details. If you prefer using our SDK, or if you want an easy way to use these credentials for API calls you can inject a bean of type ContextService<UserCredentials> and get the details from there.


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.