private String addDoAs(String spec, String userName) throws IOException {
    if (spec.toLowerCase().contains(DO_AS_PARAM)) {
      throw new IllegalArgumentException("URL cannot contain \"" + DO_AS_PARAM + "\" parameter.");
    }

    try {
      URIBuilder builder = new URIBuilder(spec);
      builder.addParameter(DO_AS_PARAM, userName);
      return builder.build().toString();
    } catch (URISyntaxException e) {
      throw new IOException(e);
    }
  }
Get an instance of HostPortRestrictionHandler

@return
ambari-server/src/main/java/org/apache/ambari/server/view/ViewURLStreamProvider.java