code: @Deprecated
      public static @Nonnull SecurityContext impersonate(@Nonnull Authentication auth) {
          SecurityContext old = SecurityContextHolder.getContext();
          SecurityContextHolder.setContext(new NonSerializableSecurityContext(auth));
          return old;
      }
docs: Changes the {@link Authentication} associated with the current thread
  to the specified one, and returns  the previous security context.
  
  <p>
  When the impersonation is over, be sure to restore the previous authentication
  via {@code SecurityContextHolder.setContext(returnValueFromThisMethod)};
  or just use {@link #impersonate(Authentication,Runnable)}.
  
  <p>
  We need to create a new {@link SecurityContext} instead of {@link SecurityContext#setAuthentication(Authentication)}
  because the same {@link SecurityContext} object is reused for all the concurrent requests from the same session.
  @since 1.462
  @deprecated use try with resources and {@link #as(Authentication)}