为什么这有效?
env.put(Context.PROVIDER_URL, "ldap://localhost:10389/o=csRepository");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
//env.put(Context.SECURITY_PRINCIPAL, "cn=John Eipe, ou=employees, o=csRepository");
//env.put(Context.SECURITY_CREDENTIALS, "qwer1234");
DirContext ctx = new InitialDirContext(env);
//operations on ctx
我的理解是,当 SECURITY_AUTHENTICATION 指定为简单且未指定用户名或密码时,它应该抛出 javax.naming.AuthenticationException。
最佳答案
已解决。可悲的是它就是这样运作的。 Oracle 文档中对此进行了如下说明。
If you supply an empty string, an empty byte/char array, or null to the Context.SECURITY_CREDENTIALS environment property, then the authentication mechanism will be "none". This is because the LDAP requires the password to be nonempty for simple authentication. The protocol automatically converts the authentication to "none" if a password is not supplied.
这会导致严重的安全漏洞。但是,我想这是留给应用程序来验证的。
关于java - 无需用户名/密码的简单安全身份验证即可产生结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22881112/