I have Spring MVC REST channel:
@Controller
@RequestMapping("/rest")
public class REST {
and I have my method:
@RequestMapping(value = "/doSomething")
public @ResponseBody DoSomethingResultDTO doSomething(
@RequestBody DoSomethingRequestDTO)
Now I need the name of the user that is logged in. Normally I could do it by the method
HttpServletRequest.getUserPrincipal()
but how to get it here? I have annotations for headers (@RequestHeader
), or even cookies (@CookieValue
). But how can I get the Principal
in my method?
You can inject Principal object to your controller handler method
@RequestMapping(value = "/doSomething")
public @ResponseBody DoSomethingResultDTO doSomething(
@RequestBody DoSomethingRequestDTO, Principal principal)