我想使用.p12證書連接到LDAP服務器,而不是使用用戶名和密碼。 Java的解決方案看起來像如何使用p12證書連接到LDAP服務器
String ldapURL = "ldaps://"+host+":"+port;
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.setProperty("javax.net.ssl.keyStore",keystore);
System.setProperty("javax.net.ssl.keyStorePassword", keystorePassword);
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapURL);
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.REFERRAL, "follow");
try
{
// Create initial context
LdapContext ctx = new InitialLdapContext(env, null);
// Perform client authentication using TLS credentials
ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, "EXTERNAL");
SearchControls ctls = new SearchControls();
// Specify the search filter to match
String filter = "(objectClass=*)";
// Search for objects using the filter
NamingEnumeration answer = ctx.search("ou="+elemType[i]+","+siteSpecificBaseDN, filter, ctls);
...
我可以使用python做同樣的事嗎?我只能找到示例顯示如何使用用戶名和密碼與python-ldap連接到LDAP服務器,但這不是我所需要的。如果使用.p12證書是不可能的,如果有使用x509證書(.pem格式)的解決方案,它也可以幫助我。