RFC2254CertificateFilter extends CertificateFilter { @Override public String[] matches(final String[] aliases, final KeyStoreManager ksm) { if (!this.recurseIssuers) { return super.matches(aliases, ksm); } final List<String> filteredAliases = new ArrayList<String>(); for (final String alias : aliases) { if (filterSubjectByRFC2254(this.rfc2254SubjectFilter, ksm.getCertificate(alias)) && matchesIssuersRecursivelly(ksm.getCertificateChain(alias))) { filteredAliases.add(alias); } } return filteredAliases.toArray(new String[filteredAliases.size()]); } RFC2254CertificateFilter(final String subjectFilter, final String issuerFilter, final boolean recurse);  RFC2254CertificateFilter(final String subjectFilter, final String issuerFilter); @Override String[] matches(final String[] aliases, final KeyStoreManager ksm); @Override boolean matches(final X509Certificate cert);  }
@Test @SuppressWarnings("static-method") public void TestRFC2254CertificateSimpleFilter() throws Exception { final X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate( ClassLoader.getSystemResourceAsStream("Tomas_DNI_FIRMA.cer") ); RFC2254CertificateFilter filter = new RFC2254CertificateFilter( "SERIALNUMBER=11830960J", "O=*POLIC*" ); Assert.assertTrue(filter.matches(cert)); filter = new RFC2254CertificateFilter( "", "cn=*QNIE*" ); Assert.assertFalse(filter.matches(cert)); }
@Test @SuppressWarnings("static-method") public void TestRFC2254CertificateRecursiveFilter() throws Exception { final RFC2254CertificateFilter filter = new RFC2254CertificateFilter(null, "cn=ANF Global Root CA", true); final AOKeyStoreManager ksm = AOKeyStoreManagerFactory.getAOKeyStoreManager(AOKeyStore.WINDOWS, null, "CAPI", null, null); final String[] aceptados = filter.matches(ksm.getAliases(), ksm); System.out.println("Aceptados:"); for (final String a : aceptados) { System.out.println(a); } }