Spring annotations User Principal
In case anyone was wondering after reading the previous Spring Annotations guide you can also user various parameters to get hold of the current logged in user.
To get hold of the user principal simply add a new parameter to your Request annotated methods called:
org.springframework.web.context.request.WebRequest myWebRequest
Using the previous tutorial as an example your method should look like something similar to this:
@SuppressWarnings("unchecked") @RequestMapping(method = RequestMethod.GET) protected String showNameForm(WebRequest webRequest, ModelMap model) throws Exception { String username = webRequest.getUserPrincipal().getName(); //Do what you need with the username return "form.view"; }