title: How to amend LDAP connection properties in LDAPCertStore for X509 cert chain validation
body: <p>I'm trying to validate X509 certificate chain using sun.security.validator.PKIXValidator according to <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/certpath/CertPathProgGuide.html" rel="nofollow noreferrer">Oracle official guide</a>. One of the steps in validation is to check CRLs. I'm providing LDAPCertStore to get the CRL from LDAP. But LDAPCertStore cannot handle server closing connection becuase <code>java.security.cert.LDAPCertStoreParameters</code> lacks settings for LDAPConnection.</p>
  <p>Is it possible to amend LDAP connection properties e.g. using <a href="http://docs.oracle.com/javase/jndi/tutorial/ldap/connect/config.html" rel="nofollow noreferrer">LDAP Connection Pooling</a> (system properties doesn't help, bouncy castle has the same implementation regarding connections)?
  Please see code to reproduce below:</p>
  <pre><code>@Test
  public void testRevocationListValidation() throws Exception {
      String trustStoreFile = &quot;trustStoreFilePath&quot;;
      KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
      InputStream is = getClass().getResourceAsStream(trustStoreFile);
      if (is == null) {
          throw new FileNotFoundException(String.format(&quot;KeyStore file '%s' is not found on classpath&quot;, trustStoreFile));
      }
      trustStore.load(is, &quot;password&quot;.toCharArray());
      Set&lt;TrustAnchor&gt; trustedAnchors = new HashSet&lt;TrustAnchor&gt;();
      for (String caCertificateAlias : new String[]{&quot;ca&quot;}) {
          X509Certificate certificate = (X509Certificate) trustStore.getCertificate(caCertificateAlias);
          trustedAnchors.add(new TrustAnchor(certificate, null));
      }
      PKIXParameters parameters = new PKIXParameters(trustedAnchors);
      CertStore certStore = CertStore.getInstance(&quot;LDAP&quot;, new LDAPCertStoreParameters(&quot;ldapHost&quot;, 389));
      parameters.setCertStores(Collections.singletonList(certStore));
  
      KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
      keyStore.load(getClass().getResourceAsStream(&quot;keystore.jks&quot;), &quot;password&quot;.toCharArray());
  
      String keyStoreAlias = &quot;dev-test&quot;;
      Certificate[] userCertificateChain = keyStore.getCertificateChain(keyStoreAlias);
  
      for (int i = 0; i &lt; 3; i++) {
          System.out.println(&quot;Starting validation &quot; + i);
          CertPath userCertificatePath = CertificateFactory.getInstance(&quot;X.509&quot;).generateCertPath(Arrays.asList(userCertificateChain));
          CertPathValidator.getInstance(&quot;PKIX&quot;).validate(userCertificatePath, parameters);
          System.out.println(&quot;Validation &quot; + i + &quot; succeeded&quot;);
          if (i == 1) {
              System.out.println(&quot;Sleeping after second validation&quot;);
              TimeUnit.SECONDS.sleep(90); // Server connection timeout ~ 60 sec
          }
      }
  
  }
  </code></pre>
  <p>Sample output:</p>
  <blockquote>
  <p>Starting validation 0</p>
  <p>Validation 0 succeeded</p>
  <p>Starting validation 1</p>
  <p>Validation 1 succeeded</p>
  <p>Sleeping after second validation</p>
  <p>Starting validation 2</p>
  <p>java.security.cert.CertPathValidatorException:
  java.security.cert.CertStoreException:
  javax.naming.CommunicationException: connection closed [Root exception
  is java.io.IOException: <strong>connection closed</strong>]; remaining name</p>
  </blockquote>