当前位置: 技术问答>java相关
JNDI和LDAP问题,言者有其分
来源: 互联网 发布时间:2015-06-30
本文导语: 我现在是要访问LDAP,我在WINDOWS2000 SERVER下配置了ACTIVE DIRECTORY 可我不知道,我是否还需要继续培植LDAP,是不是ADS中就直接有LDAP,还是我要另外下载呀?? 小弟实在不知道该怎么办了,我是新人,请多指教 import com...
我现在是要访问LDAP,我在WINDOWS2000 SERVER下配置了ACTIVE DIRECTORY
可我不知道,我是否还需要继续培植LDAP,是不是ADS中就直接有LDAP,还是我要另外下载呀??
小弟实在不知道该怎么办了,我是新人,请多指教
import com.sun.jndi.ldap.LdapCtxFactory;
import java.lang.String;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.directory.InitialDirContext;
import java.util.Vector;
public class ldap
{
public static String INITCTX="com.sun.jndi.ldap.LdapCtxFactory";
public static String MY_HOST="ldap://localhost:389";
public static String MY_SEARCHBASE="o=lifeis.lifeis.net.cn";
public static String MY_FILTER="(sn=life)";
public static void main(String[] args)
{
try
{
Hashtable env=new Hashtable();
//specify which class to use for our JNDI provider
env.put(Context.INITIAL_CONTEXT_FACTORY,INITCTX);
//security information
//authenticates us to the server
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"lifeis");
env.put(Context.SECURITY_CREDENTIALS,"lifeis");
//specify host and port to use for directory service
env.put(Context.PROVIDER_URL,MY_HOST);
//get a reference to a directory context
Context context = new InitialContext(env);
DirContext ctx=new InitialDirContext(env);
//specify the scope to the search
SearchControls constraints=new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
//perform the actual search
//we give it a searchbase,a filter and the constraints
//containing the scope of the search
NamingEnumeration results=ctx.search(MY_SEARCHBASE,MY_FILTER,constraints);
while(results!=null &&results.hasMore()
{
.............................
}
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}
现在是进入WHILE循环就抛异常
可我不知道,我是否还需要继续培植LDAP,是不是ADS中就直接有LDAP,还是我要另外下载呀??
小弟实在不知道该怎么办了,我是新人,请多指教
import com.sun.jndi.ldap.LdapCtxFactory;
import java.lang.String;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.directory.InitialDirContext;
import java.util.Vector;
public class ldap
{
public static String INITCTX="com.sun.jndi.ldap.LdapCtxFactory";
public static String MY_HOST="ldap://localhost:389";
public static String MY_SEARCHBASE="o=lifeis.lifeis.net.cn";
public static String MY_FILTER="(sn=life)";
public static void main(String[] args)
{
try
{
Hashtable env=new Hashtable();
//specify which class to use for our JNDI provider
env.put(Context.INITIAL_CONTEXT_FACTORY,INITCTX);
//security information
//authenticates us to the server
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"lifeis");
env.put(Context.SECURITY_CREDENTIALS,"lifeis");
//specify host and port to use for directory service
env.put(Context.PROVIDER_URL,MY_HOST);
//get a reference to a directory context
Context context = new InitialContext(env);
DirContext ctx=new InitialDirContext(env);
//specify the scope to the search
SearchControls constraints=new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
//perform the actual search
//we give it a searchbase,a filter and the constraints
//containing the scope of the search
NamingEnumeration results=ctx.search(MY_SEARCHBASE,MY_FILTER,constraints);
while(results!=null &&results.hasMore()
{
.............................
}
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}
现在是进入WHILE循环就抛异常
|
我没用过win的ADS,所以不太清楚。
我只有iPlant的LDAP服务器,帮你调试一下吧。稍后……
另,我有一个java的LDAP Borwser工具,可以访问LDAP,好象也可以访问ADS的,试试,(给我你的mail,通过消息给吧)。我发过去。
|
用domino server 作ldap server