public static String hideCredentials(String urlString) {
    if (StringUtils.isEmpty(urlString)) {
      return urlString;
    }
    URL url;
    try {
      url = new URL(urlString);
    } catch (MalformedURLException e) {
      // it is better to miss url instead of spreading it out
      return INVALID_URL;
    }
    String userInfo = url.getUserInfo();
    if (StringUtils.isNotEmpty(userInfo)) {
      if (userInfo.contains(":")) {
        return StringUtils.replaceOnce(urlString, userInfo, HIDDEN_CREDENTIALS);
      } else {
        return StringUtils.replaceOnce(urlString, userInfo, HIDDEN_USER);
      }
    }
    return urlString;
  }
Provides functionality for hiding credentials in URLs.
ambari-server/src/main/java/org/apache/ambari/server/utils/URLCredentialsHider.java