code: private static boolean areSame(Credentials c1, Credentials c2) {
          if (c1 == null) {
              return c2 == null;
          } else {
              return StringUtils.equals(c1.getUserPrincipal().getName(), c1.getUserPrincipal().getName()) &&
                      StringUtils.equals(c1.getPassword(), c1.getPassword());
          }
      }
docs: Compare two instances of Credentials.
  @param c1 instance of Credentials
  @param c2 another instance of Credentials
  @return comparison result. {@code true} if both are null or contain same user/password pairs, false otherwise.