public void execute(HttpServletRequest request, HttpServletResponse response, MethodExecutor executor)
      throws IOException {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Logging headers in {} request", request.getMethod());
      Enumeration<String> headerNames = request.getHeaderNames();
      while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        LOG.debug("Header: [{}], Value: [{}]", headerName,
            request.getHeader(headerName));
      }
    }
    final UserGroupInformation clientUgi;
    try {
      String userFromHeader = extractUserName(request, response);
      // Temporary, and useless for now. Here only to allow this to work on an otherwise kerberized
      // server.
      if (isSecurityEnabled || jwtAuthEnabled) {
        LOG.info("Creating proxy user for: {}", userFromHeader);
        clientUgi = UserGroupInformation.createProxyUser(userFromHeader, UserGroupInformation.getLoginUser());
      } else {
        LOG.info("Creating remote user for: {}", userFromHeader);
        clientUgi = UserGroupInformation.createRemoteUser(userFromHeader);
      }
    } catch (HttpAuthenticationException e) {
      response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
      response.getWriter().println("Authentication error: " + e.getMessage());
      // Also log the error message on server side
      LOG.error("Authentication error: ", e);
      // no need to go further
      return;
    }
    final PrivilegedExceptionAction<Void> action = () -> {
      executor.execute(request, response);
      return null;
    };
    try {
      clientUgi.doAs(action);
    } catch (InterruptedException e) {
      LOG.info("Interrupted when executing http request as user: {}", clientUgi.getUserName(), e);
      Thread.currentThread().interrupt();
    } catch (RuntimeException e) {
      throw new IOException("Exception when executing http request as user: "+ clientUgi.getUserName(), e);
    }
  }
The method to call to secure the execution of a (http) method.
@param request the request
@param response the response
@param executor the method executor
@throws IOException if the Json in/out fail
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ServletSecurity.java