PermGen error

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";
}

Categorised as: Spring Framework


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">