title: How to programmatically disable certificate hostname verification in Java LDAP JNDI LDAP API?
body: <p>Java 8u181 introduced a change that enables certificate hostname verification when using the Java JNDI LDAP API connecting to LDAPS (TLS) servers.</p>
  
  <p>See:  <a href="https://www.oracle.com/technetwork/java/javase/8u181-relnotes-4479407.html#JDK-8200666" rel="nofollow noreferrer">https://www.oracle.com/technetwork/java/javase/8u181-relnotes-4479407.html#JDK-8200666</a></p>
  
  <p>How can this hostname verification be disabled, or better yet specify a custom javax.net.ssl.HostnameVerifier class.  Oracle's documentation only specifies a Java environment property to disable the verification, but does not indicate any way to accomplish this problematically which is critical for environments that don't (or don't want) ability to change bits/switches of the JVM they are running on.</p>
  
  <p>This question:  <a href="https://stackoverflow.com/questions/51449801/how-to-disable-endpoint-identification-for-java-1-8-181-version">How to disable endpoint identification for java 1.8.181 version</a>  Asks a similar question but the solution is a java environment change via the command line.  I'm asking how it can be done programmatically without the environment switch.</p>
  
  <p>There are other questions/answers about disabling hostname verification for other types of SSL connections in Java but the answers do not work with the JNDI LDAP API.</p>