title: Spring Boot not returning username using CustomAuthenticationProvider
body: <p>I have been following Baeldung's <a href="https://www.baeldung.com/spring-security-two-factor-authentication-with-soft-token" rel="nofollow noreferrer">Spring 2FA tutorial</a> to implement 2FA. I have created a CustomAuthenticationProvider as instructed, however it's not behaving as expected. </p>
  
  <p>The odd thing is that after login, a username format that I'm not familiar with is displayed when using <code>Principal.getName()</code>:</p>
  
  <p><code>com.appname.models.User@69080b62</code></p>
  
  <p>As parts of the application rely on this for fetching details, this isn't appropriate but I'm struggling to understand where I've gone wrong. I have done some research but without the correct nomenclature and the name of the format, I'm struggling to find the appropriate result.</p>
  
  <pre><code>    public Authentication authenticate(Authentication auth) throws AuthenticationException {
  
          User user = userRepository.findByUsername(auth.getName());
  
          if(user == null) {
  
              throw new BadCredentialsException("Invalid username or password");
  
          }
  
          if(user.getTwoFactor()) {
  
              //as per tutorial
  
          }
          //this returns the "correct" username
          System.out.println(user.getUsername());
  
          final Authentication result = super.authenticate(auth);
          //I suspect it's here that the issue is occurring, though any pointers in the right direction would be appreciated
          return new UsernamePasswordAuthenticationToken(user, result.getCredentials(), result.getAuthorities());
  
  }
  </code></pre>
  
  <p>I'm expecting the actual username rather than...however it is currently being returned - i.e. an email address of a user.</p>