下载的连接:http://www.ilex.fr/openldap/install-openldap-windows.exe
解决方案 »
- getHibernateTemplate().save(ad)奇怪情况,无语了。
- 怎么用URLEncoder编码
- 一个weblogic的jms问题
- 怎么使用Java UI技术实现类似于大智慧证券、港澳证券资讯之类的分析软件?
- ojdbc14.jar驱动
- 字符串'+'字符显示问题
- The absolute uri: http://struts.apache.org/tags-html cannot be resolved in either web.xml or the jar files deployed with this ap
- hibernate配置mapping的概念问题,求解!
- 为什么工作这么难找呀?
- 为什么没有人访问我的网站呢?albert.mycool.net
- 谁能告诉struts的mappings forward与http-url,jsp response redirect连接在原理有什么区别?
- 如何配置jsp环境的虚拟站点而不是目录,tomcat行吗?
我的一个同事用过linux平台下的,好象就是象连接数据库一样的建立连接,然后存取数据就可以了;搜一搜了;如果你也可以用linux下的,我可以问清楚告你。
public boolean connect(){
String account="Manager";
String password="123456";
String root="dc=sweet,dc=com"; //root
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.123.166:389/" + root);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=" + account + "," + root);
env.put(Context.SECURITY_CREDENTIALS, password);
DirContext ctx = null;
try
{
ctx = new InitialDirContext(env);
System.out.println("认证成功");
return true;
}
catch(javax.naming.AuthenticationException e)
{
System.out.println("认证失败");
}
catch(Exception e)
{
System.out.println("认证出错:");
e.printStackTrace();
}
if(ctx != null)
{
try
{
ctx.close();
return false;
}
catch (NamingException e)
{
//ignore
}
} return false;
}
调用该类的connect方法后后台打印出认证失败。请问我该如何访问才行呢,是不是我的配置有问题阿?
你的账户应该是:
String account="cn=Manager";
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;public class LDAPTest {
public LDAPTest() {
} public static void main(String[] args) {
LDAPTest LDAPTest1 = new LDAPTest();
String root = "dc=mywebmail,dc=com"; //root Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.9.1:389/" + root);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=mywebmail,dc=com");//关键是这句
env.put(Context.SECURITY_CREDENTIALS, "s");//我改了密码为s DirContext ctx = null;
try {
ctx = new InitialDirContext(env);
System.out.println("认证成功");
}
catch (javax.naming.AuthenticationException e) {
e.printStackTrace();
System.out.println("认证失败");
}
catch (Exception e) { System.out.println("认证出错:");
e.printStackTrace();
} if (ctx != null) {
try {
ctx.close();
}
catch (NamingException e) {
//ignore
}
}
System.exit(0);
}}