title: How to get a principal with @AuthenticationPrincipal
body: <p>I make a project on Spring Security.
  The teacher wants me to get a principal with @AuthenticationPrincipal</p>
  <p>I have this controller,
  what should I remake to insert @AuthenticationPrincipal?</p>
  <pre><code> @Controller
  public class UserController {
  
      private final UserService userService;
  
      public UserController(UserService userService) {
          this.userService = userService;
      }
  
      @GetMapping(&quot;/user&quot;)
      public String showUser(Model model) {
          User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
          model.addAttribute(&quot;user&quot;, user);
          return &quot;users&quot;;
      }
  } 
  </code></pre>
  <p>My git:  <a href="https://github.com/anatoliy19/3.1.2.git" rel="nofollow noreferrer">https://github.com/anatoliy19/3.1.2.git</a></p>