code: public static void validateHostnameOrIpAddress(X509Certificate certificate, String hostname) throws UaException {
          boolean dnsNameMatches =
                  validateSubjectAltNameField(certificate, SUBJECT_ALT_NAME_DNS_NAME, hostname::equals);
  
          boolean ipAddressMatches =
                  validateSubjectAltNameField(certificate, SUBJECT_ALT_NAME_IP_ADDRESS, hostname::equals);
  
          if (!(dnsNameMatches || ipAddressMatches)) {
              throw new UaException(StatusCodes.Bad_CertificateHostNameInvalid);
          }
      }
docs: Validate that the hostname used in the endpoint URL matches either the SubjectAltName DNSName or IPAddress in
  the given certificate.
  
  @param certificate the certificate to validate against.
  @param hostname    the hostname used in the endpoint URL.
  @throws UaException if there is no matching DNSName or IPAddress entry.