public static @Nullable @CheckForNull String getCurrentUsername() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null) {
      return null;
    }
    return getUsername(authentication);
  }
public static @ Nullable @ CheckForNull String getCurrentUsername ( ) { Authentication authentication = SecurityContextHolder . getContext ( ) . getAuthentication ( ) ; if ( authentication == null ) { return null ; } return getUsername ( authentication ) ; }
Returns the username of the current authentication.

@return username or <tt>null</tt> if 1) the current authentication is null or 2) the currently
authenticated principal is the system.