这是连接方法: private void LDAP_connect() {
Hashtable env = new Hashtable();
LdapContext ctx ;
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://127.0.0.1:333/" + "dc=ccc, dc=com");// LDAP server
env.put(Context.SECURITY_AUTHENTICATION, "simple");
try {
ctx = new InitialLdapContext(env, connCtls);
} catch (javax.naming.AuthenticationException e) {
System.out.println("Authentication faild: " + e.toString());
} catch (Exception e) {
System.out.println("Something wrong while authenticating: "
+ e.toString());
}
}
用这个方法连接没有报错,而且能打印连接对象:
ctx=javax.naming.ldap.InitialLdapContext@47364736这样是不是就连接成功了?那要怎样做才能获取到里面的全部用户信息?高分求高手,谢谢啦
Hashtable env = new Hashtable();
LdapContext ctx ;
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://127.0.0.1:333/" + "dc=ccc, dc=com");// LDAP server
env.put(Context.SECURITY_AUTHENTICATION, "simple");
try {
ctx = new InitialLdapContext(env, connCtls);
} catch (javax.naming.AuthenticationException e) {
System.out.println("Authentication faild: " + e.toString());
} catch (Exception e) {
System.out.println("Something wrong while authenticating: "
+ e.toString());
}
}
用这个方法连接没有报错,而且能打印连接对象:
ctx=javax.naming.ldap.InitialLdapContext@47364736这样是不是就连接成功了?那要怎样做才能获取到里面的全部用户信息?高分求高手,谢谢啦
解决方案 »
- 子线程调用run方法为什么是主线程调用的
- 求教:怎么使用JMF(java播放视频)?
- 能过来帮忙解决一下.就是我写的一个聊天程序,然后用客户端发给服务器信息,服务器在把信息发给我想要指定的客户端,怎么解决,我用swt写的,代码如下!
- 求各位大侠帮助!!!急急!!!
- java代码无法运行出结果。
- 跪求!关于jsp迭代的问题?
- 怎样才能做出象javaDoc那样的文档?
- & 、&& 有啥区别,具体讲讲???
- 为什么安装了 JBuilder 后,JDK 不能用了?
- 请指教:weblogic+jb6整和后,project-->default project properties-->run-->application 的 main class 是什么?
- java Swing实现类似UML工具拖动一个控件然后生成并可以添加监听事件
- 求救:windows环境下无法运行JAR包下的class文件
private LdapContext getNewLdapContext() throws Exception {
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put("com.sun.jndi.ldap.connect.pool", "true");
env.put("java.naming.referral", "follow");
env.put(Context.PROVIDER_URL, "ldap://xxx.xxx.xxx.xxx:xxxx/");
env.put(Context.SECURITY_PRINCIPAL, "/*account*/");
env.put(Context.SECURITY_CREDENTIALS, "/*password*/");
try {
LdapContext ldapContext = new InitialLdapContext(env, null);
return ldapContext;
} catch (Exception e) {
throw new Exception("LdapContext initialize error", e);
}
} public NamingEnumeration<SearchResult> getAllUsersInfo() throws Exception {
try {
return ctxSearch("DC=ccc,DC=com", "objectClass=User", null, SearchControls.SUBTREE_SCOPE);
} catch (Exception e) {
throw new Exception("get all users info error", e);
}
}
public void printAllUsersInfo() throws Exception {
NamingEnumeration<SearchResult> infos = getAllUsersInfo();
while (infos.hasMoreElements()) {
NamingEnumeration<? extends Attribute> attrs = infos.next().getAttributes().getAll();
while (attrs.hasMore()) {
Attribute attr = attrs.next();
System.out.println(attr.getID() + ":" + attr.get());
}
}
}