title: How get jwt 'user_name' inside @ExceptionHandler class ResponseEntity using WebRequest (Spring)?
body: <p><a href="https://i.stack.imgur.com/Ve6eH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ve6eH.png" alt="enter image description here" /></a>
  <strong>I try:</strong>
  <a href="https://stackoverflow.com/questions/32052076/how-to-get-the-current-logged-in-user-object-from-spring-security">How to get the current logged in user object from spring security?</a></p>
  <p><strong>but doesn't work.</strong></p>
  <p>How convert <code>org.springframework.security.oauth2.jwt.Jwt@9f4f7d6e</code> to username jwt ?</p>
  <p>My Class Starts With:</p>
  <pre><code>@Slf4j
  @RestControllerAdvice
  public class RestControllerExceptionHandler {
  
      @ExceptionHandler(Throwable.class)
      public final ResponseEntity&lt;ErrorResponse&gt; handleException(Throwable ex, WebRequest request) {
          // ex.printStackTrace();
          // Authentication authenticantion = SecurityContextHolder.getContext().getAuthentication();
          String username = new String();
          Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  
          AbstractAuthenticationToken auth = (AbstractAuthenticationToken)
                  SecurityContextHolder.getContext().getAuthentication();
  
          UserDetails details = (UserDetails) auth.getDetails();
  
          log.error(ex.getMessage().toUpperCase() + &quot; User:  &quot;+ username  + &quot; Source: &quot; + request.getDescription(false));
  ....
  </code></pre>