ldap笔记
参考http://wiki.ubuntu.org.cn/index.php?title=OpenLDAPServer&variant=zh-cn#Installation.EF.BC.88.E5.AE.89.E8.A3.85.EF.BC.89
先安装slapd 和 ldap-utils
vim /etc/ldap/slapd.conf
# Make sure you edit or add these directives after the first 'database' directive.suffix "dc=example,dc=com"directory "/var/lib/ldap"rootdn "cn=admin,dc=example,dc=com"rootpw {SSHA}d2BamRTgBuhC6SxC0vFGWol31ki8iq5m127.0.0.1 localhost209.85.225.101sites.google.com192.168.1.116example.com
suffix "dc=example,dc=com"rootdn "cn=Manager,dc=example,dc=com"
import java.util.*;import javax.naming.Context;import javax.naming.NamingException;import javax.naming.directory.DirContext;import javax.naming.directory.InitialDirContext; public class Demo {public static void main(String[] args) { Demo LDAPTest1 = new Demo(); String root = "dc=example,dc=com"; //root Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://192.168.1.116/" + root); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=example,dc=com"); env.put(Context.SECURITY_CREDENTIALS, "haoning"); DirContext ctx = null; try { ctx = new InitialDirContext(env); System.out.println("认证成功"); } catch (javax.naming.AuthenticationException e) { e.printStackTrace(); System.out.println("认证失败"); } catch (Exception e) { System.out.println("认证出错:"); e.printStackTrace(); } if (ctx != null) { try { ctx.close(); } catch (NamingException e) { //ignore } } System.exit(0); }}