CertificateUtil { public static List<String> getSanDnsNames(X509Certificate certificate) { List<Object> values = getSubjectAltNameField(certificate, SUBJECT_ALT_NAME_DNS_NAME); return values.stream() .filter(v -> v instanceof String) .map(String.class::cast) .collect(Collectors.toList()); }  static X509Certificate decodeCertificate(byte[] certificateBytes); static X509Certificate decodeCertificate(InputStream inputStream); static List<X509Certificate> decodeCertificates(byte[] certificateBytes); static List<X509Certificate> decodeCertificates(InputStream inputStream); static PKCS10CertificationRequest generateCsr(
        KeyPair keyPair,
        X509Certificate certificate
    ); static PKCS10CertificationRequest generateCsr(
        KeyPair keyPair,
        String subjectName,
        String sanUri,
        List<String> sanDnsNames,
        List<String> sanIpAddresses,
        String signatureAlgorithm
    ); static PKCS10CertificationRequest generateCsr(
        KeyPair keyPair,
        X500Name subject,
        String sanUri,
        List<String> sanDnsNames,
        List<String> sanIpAddresses,
        String signatureAlgorithm
    ); static String getCsrPem(PKCS10CertificationRequest csr); static List<Object> getSubjectAltNameField(X509Certificate certificate, int field); static Optional<String> getSanUri(X509Certificate certificate); static List<String> getSanDnsNames(X509Certificate certificate); static List<String> getSanIpAddresses(X509Certificate certificate); static ByteString thumbprint(X509Certificate certificate); static ByteString getCertificateChainBytes(List<X509Certificate> certificateChain); static final int SUBJECT_ALT_NAME_DNS_NAME; static final int SUBJECT_ALT_NAME_IP_ADDRESS; static final int SUBJECT_ALT_NAME_URI; }
@Test public void testGetSanDnsNames() { List<String> sanDnsNames = CertificateUtil.getSanDnsNames(certificate); assertEquals(sanDnsNames, newArrayList("localhost", "hostname")); }