java连接AD的格式如何写
1个回答
展开全部
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
class DomainCon
{
public static void main(String args[])
{
Hashtable env= new Hashtable(11);
env.put(Context.SECURITY_AUTHENTICATION,"none");
env.put(Context.SECURITY_PRINCIPAL,"CN=kiran,OU=LinkedgeOU,DC=LINKEDGEDOMAIN");//User
env.put(Context.SECURITY_CREDENTIALS, "kiran");//Password
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,"ldap://testing2:389/DC=LINKEDGEDOMAIN");
try
{
DirContext ctx = new InitialDirContext(env);
String[] sAttrIDs = new String[2];
Attributes attr = ctx.getAttributes("");
System.out.println("Domain Name:"+ attr.get("name").get());
}
catch(NamingException e)
{
System.err.println("Problem getting attribute: " + e);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询