Spring annotations User Principal | PermGen error
Home > Spring Framework > Spring annotations User Principal

Spring annotations User Principal

November 10th, 2009 admin Leave a comment Go to comments

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";
}
  1. No comments yet.
  1. No trackbacks yet.