자바 호출 Domino LDAP
import java.util.Hashtable;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
public class TestLDAP {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_PRINCIPAL, "test1");
env.put(Context.SECURITY_CREDENTIALS, "password");
env.put(Context.PROVIDER_URL, "ldap://107.252.253.239:389");
try {
DirContext ctx = new InitialDirContext(env);
System.out.println("Context Namespace = " + ctx.getNameInNamespace());
String name = "CN=admin,O=ABCSDC";
System.out.println(name);
ctx.lookup(name);
Attributes attrs = ctx.getAttributes(name);
System.out.println("Mailfile: " + attrs.get("mailfile").get());
System.out.println("Mailserver: " + attrs.get("mailserver").get());
NamingEnumeration<NameClassPair> iter = ctx.list(name);
while (iter.hasMore()) {
NameClassPair p = iter.next();
System.out.println(p.getName() + " " + p.getNameInNamespace()
+ " " + p.getClassName());
}
name = "CN= 1,OU= ,OU= ,O=ABCSDC";
System.out.println(name);
Attributes attrs_new = ctx.getAttributes(name);
System.out.println("Mailfile: " + attrs_new.get("mailfile").get());
System.out.println("Mailserver: "
+ attrs_new.get("mailserver").get());
iter = ctx.list(name);
while (iter.hasMore()) {
NameClassPair p = iter.next();
System.out.println(p.getName() + " " + p.getNameInNamespace()
+ " " + p.getClassName());
}
String filter = "(CN=*)";
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration ne = ctx.search("O=ABCSDC", filter, controls);
System.out.println("To list all user in O=ABCSDC ");
while (ne.hasMore()) {
SearchResult result = (SearchResult) ne.next();
System.out.println("Name = " + result.getName()
+ ", Namespace = " + result.getNameInNamespace());
}
System.out.println(" O=ABCSDC ");
env.put(Context.PROVIDER_URL,"ldap://107.252.253.239:389/O=ABCSDC");
ctx = new InitialDirContext(env);
System.out.println(ctx.getNameInNamespace());
name = "CN= 1,OU= ,OU= ";
System.out.println("name = " + name);
ctx.lookup(name);
attrs = ctx.getAttributes(name);
System.out.println("Mailfile: " + attrs.get("mailfile").get());
System.out.println("Mailserver: " + attrs.get("mailserver").get());
System.out.println();
System.out.println(" OU= ,O=ABCSDC ");
env.put(Context.PROVIDER_URL, new String(
"ldap://107.252.253.239:389/OU= ,O=ABCSDC"
.getBytes("UTF-8"), "ISO8859-1"));
ctx = new InitialDirContext(env);
System.out.println(ctx.getNameInNamespace());
name = "CN= 1,OU= ";
System.out.println("name = " + name);
ctx.lookup(name);
attrs = ctx.getAttributes(name);
System.out.println("Mailfile: " + attrs.get("mailfile").get());
System.out.println("Mailserver: " + attrs.get("mailserver").get());
System.out.println();
System.out.println(" OU= , OU= ,O=ABCSDC ");
env.put(Context.PROVIDER_URL, new String(
"ldap://107.252.253.239:389/OU= ,OU= ,O=ABCSDC"
.getBytes("UTF-8"), "ISO8859-1"));
ctx = new InitialDirContext(env);
System.out.println(ctx.getNameInNamespace());
name = "CN= 1";
System.out.println("name = " + name);
ctx.lookup(name);
attrs = ctx.getAttributes(name);
System.out.println("Mailfile: " + attrs.get("mailfile").get());
System.out.println("Mailserver: " + attrs.get("mailserver").get());
System.out.println();
System.out.println(" ");
env.put(Context.PROVIDER_URL, new String(
"ldap://107.252.253.239:389/CN= 1,OU= ,OU= ,O=ABCSDC"
.getBytes("UTF-8"), "ISO8859-1"));
ctx = new InitialDirContext(env);
System.out.println(ctx.getNameInNamespace());
name = "";
System.out.println("name = " + name);
ctx.lookup(name);
attrs = ctx.getAttributes(name);
System.out.println("Mailfile: " + attrs.get("mailfile").get());
System.out.println("Mailserver: " + attrs.get("mailserver").get());
System.out.println();
ctx.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.