在LDAP中增加记录的问题

GFox 2003-07-01 05:21:40
我的代码如下:
...
...
try {
Hashtable env = new Hashtable();
env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put( Context.PROVIDER_URL, "ldap://1.2.3.4:389");
env.put( Context.SECURITY_AUTHENTICATION, "simple" );
env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=myou,dc=my,dc=cn" );
env.put( Context.SECURITY_CREDENTIALS, "12345678");
// Connect to the directory as admin
DirContext ctx = new InitialDirContext(env);
// Create the sub context
String userP = "uid=test,ou=myou,dc=my,dc=cn";
// describe the new user
Attributes attrs = new BasicAttributes();
attrs.put("objectclass","inetOrgPerson");
// define objectclass of new enry
attrs.put("uid","dbm");
attrs.put("mail","dbm@whatever.com");
attrs.put("telephonenumber","555-555-5555");
DirContext subCtx = ctx.createSubcontext( userP, attrs );
Attributes atts = subCtx.getAttributes( userP );
Attribute att = atts.get( "uid" );
String value = (String) att.get();
System.out.println( "UserID = " + value );
}
catch(Exception e) {
e.printStackTrace();
}
...
...

可是运行时报:
javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - Object Class Violation]; remaining name 'uid=test,ou=myou,dc=my,dc=cn'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:2767)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2682)

可有兄弟教教小弟如何做呢?
...全文
881 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
shannon977 2003-08-09
  • 打赏
  • 举报
回复
mark
feiyuegaoshan 2003-07-02
  • 打赏
  • 举报
回复
你的程序试图要往ldap里加入'uid=test,ou=myou,dc=my,dc=cn',
可是它已经在ldap内存在了。

你在程序内把他们的属性值换一下,就ok乐。
GFox 2003-07-02
  • 打赏
  • 举报
回复
这年头,连sun上的东西都不能信呀,我就因为太信sun,结果都没怎么检查,结果...
GFox 2003-07-02
  • 打赏
  • 举报
回复
呀,真的是少了,我昨天是怎么检查的啊...

现在行了,谢谢 amandapan(amandapan)

:)
amandapan 2003-07-02
  • 打赏
  • 举报
回复
是上两行少了
amandapan 2003-07-02
  • 打赏
  • 举报
回复
attrs.put("cn","youcn");
attrs.put("sn","yousn");
amandapan 2003-07-02
  • 打赏
  • 举报
回复
没可能啊,检查一下是不是真的有什么东西没写?我以前也是这样的
GFox 2003-07-02
  • 打赏
  • 举报
回复
不,我用console看,并没有这个'uid=test,ou=myou,dc=my,dc=cn'

改了后也是不行

改成这样
...
String userP = "uid=test1,ou=myou,dc=my,dc=cn";

Attributes attrs = new BasicAttributes();
attrs.put("objectclass","inetOrgPerson");

// define objectclass of new enry
attrs.put("uid","test1");
attrs.put("mail","dbm1@whatever.com");
attrs.put("telephonenumber","555-555-5555");

DirContext subCtx = ctx.createSubcontext( userP, attrs );
...

也是不行啊
GFox 2003-07-01
  • 打赏
  • 举报
回复
按Exception的信息,应该是我生成的记录信息不配置,可是我查过了ldap的Schema,觉得上面写的应该是够的了呀,难道我还是看错了?再说,这个例子是从sun网站下抄下来的,应该它本身是能运行的才对呀,我用的也是他们本身的iPlanet 5.1,应该说不会不兼容吧?

有没有高手可以告诉我?

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧