title: How can I get the currently logged in user's data in Spring Boot Thymeleaf?
body: <p>I want my logged in user to be able to see their own user profile and even modify that if they want to.</p>
  <p>My two entities that store my user's data:</p>
  <pre><code>@Entity
  @Table(name = &quot;users&quot;)
  public class User {
  
      @Id
      @GeneratedValue
      private Long id;
  
      @Column(unique = true, nullable = false)
      private String email;
  
      @Column(nullable = false)
      private String password;
  
      private String fullName;
  
      private String activation;
  
      private Boolean enabled;
  
      @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      @JoinTable(name = &quot;users_roles&quot;, joinColumns = { @JoinColumn(name = &quot;user_id&quot;) }, inverseJoinColumns = {
              @JoinColumn(name = &quot;role_id&quot;) })
      private Set&lt;Role&gt; roles = new HashSet&lt;Role&gt;();
  
      @OneToOne(mappedBy = &quot;user&quot;, cascade = CascadeType.ALL)
      private UserProfile userProfile;
  //constructors, getters and setters
  </code></pre>
  <p>and:</p>
  <pre><code>@Entity
  @Table(name=&quot;profiles&quot;)
  public class UserProfile {
  
      
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Id
      private Long id;
  
      @Column(length = 20)
      private String activation;
  
      @Column(length = 64)
      private String address;
  
      @Column(length = 32)
      private String phoneNumber;
  
      @Column(length = 60)
      private String resetToken;
  
      @OneToOne
      private User user;
      
  //constructors, getters and setters
  </code></pre>
  <p>I wrote this in my UserController:</p>
  <pre><code>    @GetMapping(&quot;/profile&quot;)
      public String showUserProfile (Model model){
          //Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
          //String currentPrincipalName = authentication.getName();
          //User user = userRepository.findByEmail(authentication.getPrincipal());
          //model.addAttribute(&quot;currentUser&quot;, user);
          return &quot;profile&quot;;
      }
  </code></pre>
  <p>My findByEmail method in UserRepository and UserService:</p>
  <pre><code>User findByEmail(String email);
  </code></pre>
  <p>STS wants to modify this method into a (object principal) or something like that, but I can't change it since that method is already used.</p>
  <pre><code>java.lang.Error: Unresolved compilation problem: 
      The method findByEmail(String) in the type UserRepository is not applicable for the arguments (Object)
  </code></pre>
  <p>I'm sorry, I'm still new to Spring Boot. <strong>How do I get the current user's data? I've already made a users CRUD, I want to do the same just with the current user and without DELETE and CREATE.</strong></p>