连接 LDAP

JLDAP   

LDAPConnection ldapConn = new LDAPConnection();
ldapConn.setConstraints(new LDAPConstraints());
ldapConn.connect("127.0.0.1", 10389);
ldapConn.bind(LDAPConnection.LDAP_V3, "uid=admin,ou=system", "secret"); 

  

 


JNDI

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://127.0.0.1:10389/o=JNDITutorial,dc=example,dc=com"); 
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"); 
env.put(Context.SECURITY_CREDENTIALS, "secret"); 
DirContext ctx = new InitialDirContext(env);

 

 

你可能感兴趣的:(Security,sun)