title: Get Spring Security Principal in JSP EL expression
body: <p>I am using Spring MVC and Spring Security version 3.0.6.RELEASE. What is the easiest way to get the user name in my JSP? Or even just whether or not the user is logged in? I can think of a couple ways:</p>
  
  <h1>1. Using a scriptlet</h1>
  
  <p>Using a scriptlet like this to determine if the user is logged in: </p>
  
  <pre><code>&lt;%=org.springframework.security.core.context.SecurityContextHolder.getContext()
      .getAuthentication().getPrincipal().equals("anonymousUser")
      ? "false":"true"%&gt;
  </code></pre>
  
  <p>I'm not a fan of using scriptlets, though, and I want to use this in some <code>&lt;c:if&gt;</code> tags, which requires putting it back as a page attribute.</p>
  
  <h1>2. Using SecurityContextHolder</h1>
  
  <p>I could again use SecurityContextHolder from my <code>@Controller</code> and put it on the model. I need this on every page, though, so I'd rather not have to add this logic in every one of my Controllers.</p>
  
  <p>I suspect there's a cleaner way to do this...</p>