code: @SuppressWarnings("unchecked")
      public static final Map<?, ?> hidePasswords(Map<?, ?> map, int depth) 
      {
          if (map != null && depth > 0) {
              map = new HashMap<Object, Object>(map);
  
              for (@SuppressWarnings("rawtypes")
              Map.Entry entry : map.entrySet())
                  if (entry.getKey() instanceof String && ((String) entry.getKey()).toUpperCase().contains("PASSWORD"))
                      entry.setValue("******");
                  else if (entry.getValue() instanceof Map)
                      entry.setValue(hidePasswords((Map<?, ?>) entry.getValue(), depth - 1));
          }
  
          return map;
      }
docs: Utility method to hide passwords from a map structure.
  Make a copy of the map and
  <li> replace password values with ******
  <li> replace map values by recursively invoking this method
  
  @param map collection of name/value pairs. Values might be passwords or submaps of
  name/value pairs that might contain more submaps or passwords.
  @param depth depth of the map. A map without any submaps is depth 1.
  
  @return copy of the map with passwords hidden.