ldap怎么查找一个人所在部门,用Java访问的
答案:1 悬赏:0 手机版
解决时间 2021-11-21 00:54
- 提问者网友:风月客
- 2021-11-20 00:48
ldap怎么查找一个人所在部门,用Java访问的
最佳答案
- 五星知识达人网友:持酒劝斜阳
- 2021-11-20 01:56
* 获得LDAP连接(不通过连接池,直接获得连接)
* @return
* @throws Exception
*/
private javax.naming.directory.DirContext getDirContext() throws Exception
{
DirContext ctx = null;
java.util.Hashtable env = new java.util.Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, pwd);
ctx = new InitialDirContext(env);
return ctx;
}
public javax.naming.NamingEnumeration getFilter(String DN,String filter,int myserach) throws Exception
{
DirContext ctx = getDirContext();
try
{
NamingEnumeration em;
SearchControls con = new SearchControls();
con.setSearchScope(myserach);
em = ctx.search(DN, filter, con);
return em;
}
finally
{
//
}
}
public java.util.Vector getfilterNodes(String dn,String filter,int level) throws Exception
{
java.util.Vector ve=new java.util.Vector();
NamingEnumeration em=getFilter(dn,filter,level);
while(em!=null && em.hasMoreElements())
{
SearchResult rs=(SearchResult)em.nextElement();
String db=rs.getName();
if (db.trim().equals(""))
ve.add(dn);
else
ve.add(db+","+dn);
}
return ve;
}
* @return
* @throws Exception
*/
private javax.naming.directory.DirContext getDirContext() throws Exception
{
DirContext ctx = null;
java.util.Hashtable env = new java.util.Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, pwd);
ctx = new InitialDirContext(env);
return ctx;
}
public javax.naming.NamingEnumeration getFilter(String DN,String filter,int myserach) throws Exception
{
DirContext ctx = getDirContext();
try
{
NamingEnumeration em;
SearchControls con = new SearchControls();
con.setSearchScope(myserach);
em = ctx.search(DN, filter, con);
return em;
}
finally
{
//
}
}
public java.util.Vector getfilterNodes(String dn,String filter,int level) throws Exception
{
java.util.Vector ve=new java.util.Vector();
NamingEnumeration em=getFilter(dn,filter,level);
while(em!=null && em.hasMoreElements())
{
SearchResult rs=(SearchResult)em.nextElement();
String db=rs.getName();
if (db.trim().equals(""))
ve.add(dn);
else
ve.add(db+","+dn);
}
return ve;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯