问题描述
代码如下: public class LdapTest2 { /** * @param args */ public static void main(String[] args) { // ***************** user information to be authenticated ******************************** //*****************Please modify the following three properties accordingly ************ String ldapHost= "ldap://192.168.2.236:389/OU=WorkFlowUser,DC=hotelvm,DC=com"; //ldap host + port number // String ldapHost="ldap://192.168.2.236:389";//改为这样也一样不行 String DN="CN=Administrator,CN=Users,DC=hotelvm,DC=com"; String password = "password.com"; // DN's password String baseDN="OU=WorkFlowUser,DC=hotelvm,DC=com"; String filter="objectClass=User"; //***************** End of user information Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); props.put(Context.SECURITY_AUTHENTICATION, "simple"); //use simple authentication mechanism props.put(Context.SECURITY_CREDENTIALS, password); props.put(Context.SECURITY_PRINCIPAL, DN); props.put(Context.PROVIDER_URL, ldapHost); try { DirContext ctx = new InitialDirContext(props); System.out.println("success"); SearchControls constraints = new SearchControls(); constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration en=ctx.search(baseDN, filter, constraints); if(en==null){ System.out.println("the value is null"); }else{ while(en.hasMore()){ Object obj=en.nextElement(); if(obj instanceof SearchResult){ SearchResult rs=(SearchResult) obj; String cn=rs.getName(); System.out.println(cn); } } } } catch (Exception ex) { System.out.println("Exception is "+ex.toString()); } } } 出现525的错误 Exception is javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 525, vece 请问大家知道是什么地方出错?首先,用户和密码是正确的;LDAP提供的信息如下: <baseDN>OU=WorkFlowUser,DC=hotelvm,DC=com</baseDN> <adminDN>CN=Administrator,CN=Users,DC=hotelvm,DC=com</adminDN> <adminPassword>password.com</adminPassword>
解决方案
http://new.qzone.qq.com/416276265;答案在这里
解决方案二:
看下这个系列http://www.iteye.com/topic/52087
解决方案三:
好象是你的验证错误..你把properties里面的这个属性移除props.put(Context.SECURITY_AUTHENTICATION, "simple"); //use simple authentication mechanism