@Override
  public HttpURLConnection doAs(HttpURLConnection conn, String type, String username, String doAsParamName) {
    String url = conn.getURL().toString();
    if (url.toLowerCase().contains(doAsParamName.toLowerCase())) {
      throw new IllegalArgumentException("URL cannot contain \"" + doAsParamName + "\" parameter");
    }

    try {
      conn.setRequestMethod(type);
    } catch (IOException e) {
      return null;
    }

    conn.setRequestProperty(doAsParamName, username);
    return conn;
  }
@param conn HTTP connection that will be modified and returned
@param type HTTP Request type: GET, PUT, POST, DELETE, etc.
@param username Username to impersonate
@param doAsParamName Query param, typically "doAs"
@return HTTP Connection object with the doAs query param set to the provider username.
ambari-server/src/main/java/org/apache/ambari/server/view/HttpImpersonatorImpl.java