[api] Fix the LDAP issues

Fix the LDAP issues, also clean up the configuration, make it configured in one file. I'd appreciate that if these fixes can be merged into 2.4. Thank you.