我有以下java代码,但我收到错误 提供详情
密码="一些&#34 ;;域名= ABF.ADDAS.com用户 name = SADFA.com \ username或SADFA \ username
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://ip:389");
//
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "");
env.put(Context.SECURITY_CREDENTIALS, "password");
答案 0 :(得分:0)
只需使用您的参数调用InitialLdapContext:
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, domainName + "\\" + username);
env.put(Context.SECURITY_CREDENTIALS, password);
try{
return new InitialLdapContext(env, null);
}
catch(javax.naming.CommunicationException e){
throw new NamingException("Failed to connect to " + domainName + ((serverName==null)? "" : " through " + serverName));
}
catch(NamingException e){
throw new NamingException("Failed to authenticate " + username + "@" + domainName + ((serverName==null)? "" : " through " + serverName));
}