在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)
可有兄弟教教小弟如何做呢?