`
cyhcheng
  • 浏览: 57947 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ldap入门

 
阅读更多

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 + ".");
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics