我写了一个小程序来对ldap进行身份验证。java程序无法对ldap进行身份验证
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
class SAuth {
public static void main(String[] args) {
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://xx.xx.xx.xx:yyyy/");
// Authenticate as S. User and password "mysecret"
env.put(Context.SECURITY_AUTHENTICATION, "username");
env.put(Context.SECURITY_PRINCIPAL, "cn=orcladmin");
env.put(Context.SECURITY_CREDENTIALS, "password");
try {
DirContext ctx = new InitialDirContext(env);
System.out.println(" i guess the connection is sucessfull :)");
// Do something useful with ctx
// Close the context when we're done
ctx.close();
} catch (NamingException e) {
e.printStackTrace();
}
}}
我得到以下错误:
javax.naming.AuthenticationNotSupportedException: orcladmin
at com.sun.jndi.ldap.sasl.LdapSasl.saslBind(LdapSasl.java:100)
at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:214)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2658)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:287)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193
)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.ja
va:136)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.jav
a:66)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
67)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288
)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.jav
a:82)
at Simple.main(Simple.java:28)
但是,如果我尝试使用LDAP CMD线和相同的用户凭据访问LDAP目录,它工作的顺利进行。 例如:
ldapsearch -p <port> -h <ip> -D "cn=orcladmin" -w "password" objectClass=*
回报有关的数据。 我猜java程序有问题,但不知道笏。
可能复制http://stackoverflow.com/questions/4209710/authenticationnotsupportedexception-digest-md5-on-websphere –
的同时,检查HTTP ://www-01.ibm.com/support/docview.wss?uid = swg1PQ72729 –
Artem:我试图连接到Oracle Internet Directory的ldap。我怀疑设置是否与webspheres相同。 – Rahul