I need to connect to an LDAP directory over SSL.
In non-production environments, we use self-signed certificates which, of course, fails to validate with:
No code required. Just add the certificate to the test client truststores.
Don't write extra code for this. It is insecure, and you run a major risk of the code leaking into production. You really don't want that.