String ldapHost = "ldap://ldapHostName:389"; // ldap host + port number
String DN = "OU=Software,OU=China,DC=yinghua,DC=com,DC=cn";//OU组织树,DC域名
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_PRINCIPAL, "ldapHostName\\"+userName);
props.put(Context.SECURITY_CREDENTIALS, password);
props.put(Context.PROVIDER_URL, ldapHost);
try {
DirContext ctx = new InitialDirContext(props);
System.out.println("successed login");
} catch (NamingException e) {
log.error("Failed Login, login user name:" + userName + ".");
}