I try:
How to get the current logged in user object from spring security?
but doesn't work.
How convert org.springframework.security.oauth2.jwt.Jwt@9f4f7d6e
to username jwt ?
My Class Starts With:
@Slf4j
@RestControllerAdvice
public class RestControllerExceptionHandler {
@ExceptionHandler(Throwable.class)
public final ResponseEntity<ErrorResponse> 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() + " User: "+ username + " Source: " + request.getDescription(false));
....