How to programmatically disable certificate hostname verification in Java LDAP JNDI LDAP API?

Java 8u181 introduced a change that enables certificate hostname verification when using the Java JNDI LDAP API connecting to LDAPS (TLS) servers.


How can this hostname verification be disabled, or better yet specify a custom 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.

This question: How to disable endpoint identification for java 1.8.181 version 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.

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.