文章作者 100test 发表时间 2007:10:19 12:04:15
来源 100Test.Com百考试题网
import javax.naming.Context.
import javax.naming.NamingEnumeration.
import javax.naming.NamingException.
import javax.naming.directory.Attribute.
import javax.naming.directory.Attributes.
import javax.naming.directory.BasicAttribute.
import javax.naming.directory.DirContext.
import javax.naming.directory.ModificationItem.
import javax.naming.directory.SearchControls.
import javax.naming.directory.SearchResult.
import javax.naming.ldap.InitialLdapContext.
import javax.naming.ldap.LdapContext.
public class OpAD{
private LdapContext ctx = null.
private String adminName = "[email protected]".
private String adminpassword = "password".
private String keystore = "C:/testca.keystore".
private String keyPassword = "changeit".
private String ldapURL = "ldaps://ldap.testad.com:636".
private String searchBase = "DC=testad,DC=com".
private String returnedAtts[] = { "distinguishedName" }.
private boolean initial_Ldap() {
Hashtable env = new Hashtable().
System.setProperty("javax.net.ssl.trustStore", keystore).
System.setProperty("javax.net.ssl.trustStorePassword", keyPassword).
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory").
env.put(Context.SECURITY_AUTHENTICATION, "simple").
env.put(Context.SECURITY_PRINCIPAL, adminName).
env.put(Context.SECURITY_CREDENTIALS, adminpassword).
env.put(Context.SECURITY_PROTOCOL, "ssl").
env.put(Context.PROVIDER_URL, ldapURL).
try {
System.out.println("Start InitialLdapContext").
ctx = new InitialLdapContext(env, null).
System.out.println("InitialLdapContext succeed").
} catch (NamingException e) {
System.out.println("Problem initial_Ldap NamingException: " e).
return false.
}
return true.
}
private boolean close_Ldap() {
System.out.println("Close Ldap").
try {
ctx.close().
相关文章
Entity回调和监听器使用方法
a ert(断言)的使用方法
彻底分清Overload(重载)和Override(重写)
sleep()和wait()有什么不同?
Java添加、修改MSAD用户密码方法
ring Hibernate Struts的优势地位凸显
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛