LDAP Look up
来源:互联网 发布:免费日语自学软件 编辑:程序博客网 时间:2024/04/30 02:38
import java.util.Properties;
import java.util.Hashtable;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.NamingException;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.Context;
import javax.naming.directory.*;
import javax.naming.*;
//import org.apache.ldap.common.message.Control;
public class TEST1 {
private void putAttribute(Attributes attrs,
String attrName, String attrValue) {
if (attrValue != null && attrValue.length() != 0) {
Attribute attr =
new BasicAttribute(attrName, attrValue);
attrs.put(attr);
}
}
public static void main(String[] args) throws NamingException {
TEST1 s = new TEST1();
s.doProcess();
}
public void doProcess() throws NamingException{
Properties p = new Properties();
p.setProperty("java.naming.factory.initial","com.sun.jndi.ldap.LdapCtxFactory");
p.setProperty("java.naming.provider.url","ldap://localhost:389");
p.setProperty("java.naming.security.authentication","simple");
p.setProperty(Context.SECURITY_PRINCIPAL, "CN=administrator,cn=users,dc=lisa,dc=beijing,dc=indigo");
p.put(Context.SECURITY_CREDENTIALS, "LISA429");
InitialLdapContext ctx = new InitialLdapContext(p,null);
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration e = ctx.search("cn=lisa ni,ou=newOU,dc=lisa,dc=beijing,dc=indigo", "(&(objectClass=user))", constraints);
while (e.hasMore()) {
SearchResult entry = (SearchResult) e.next();
Attributes attrs = entry.getAttributes();
if (attrs == null) {
System.out.println("Pas d'attributs");
} else {
System.out.println(attrs.get("Department"));
}
}
}
}
- LDAP Look up
- FOJ 1845 Look Up
- dns look up command
- DTC look up 例子
- 低头族,Look Up!
- 什么是LUT(LOOK UP TABLE)
- 每日一句:Look Up
- P2947 [USACO09MAR]仰望Look Up
- USACO 2009 Mar Look Up 向右看齐
- bzoj3401[Usaco2009 Mar]Look Up 仰望
- [G+smo]Interpolation and look up
- FZU 1845 Look Up(单调栈)
- [BZOJ3401] [Usaco2009 Mar]Look Up 仰望
- Spring look-up获取器注入
- 洛谷 2947 仰望Look Up(单调栈)
- BZOJ 3401: [Usaco2009 Mar]Look Up 仰望
- bzoj3401 Look up(单调栈)
- bzoj 3401: [Usaco2009 Mar]Look Up 仰望
- 定制Plone2之联合发布(Syndication)
- 从 ASPX 页面进行 Web 服务调用时的性能考虑
- 为什么是GeoRSS而不是GML
- 常用函数使用:
- bash教程1
- LDAP Look up
- bash 教程2
- JSF常见错误总结
- 写在前面的话
- 访问 IIS 元数据库失败
- 那一年的北风--序言1
- 9X、2000、XP、2003所有注册表设置
- 程序员成功之路
- Winform短信猫程序开发总结(一)