I'm in trouble with this error when I change a password or update user's info. I've tried so many codes that are similar each others, but I still got the error. The problem can be a bad CN definition, but should be correct in my case and I'm really sad about this because I cannot face the problem.
- Connection to the server via LDAP: OK.
- SSL and cacerts: OK.
- Add user via code: OK.
- Fetching all users info: OK.
- Update user's info: BAD.
Here is a simple code where I try, without success, to update the user's info (description). The user "batman" obviously, exists in AD.
public class ADConnection {
DirContext ctx = null;
String baseName = ",OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL";
String serverIP = "192.168.10.45";
boolean ssl = true;
public ADConnection() {
try {
Hashtable ldapEnv = new Hashtable();
ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
if(ssl==true)
{
ldapEnv.put(Context.PROVIDER_URL, "ldaps://192.168.10.45:636/dc=softwaredev,dc=local");
ldapEnv.put(Context.SECURITY_PROTOCOL, "ssl");
}
else
{
ldapEnv.put(Context.PROVIDER_URL, "ldap://192.168.10.45:389/dc=softwaredev,dc=local");
}
ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
ldapEnv.put(Context.SECURITY_PRINCIPAL, new String("softwaredev" + "\\" + "superadmin"));
ldapEnv.put(Context.SECURITY_CREDENTIALS, "passw0rd");
ctx = new InitialDirContext(ldapEnv);
}
catch (Exception e) {
System.out.println(" bind error: " + e);
e.printStackTrace();
System.exit(-1);
}
}
public void updateDescription(String username) {
try {
System.out.println("updating...\n");
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute("description", "batman_description"));
ctx.modifyAttributes("CN=" + username + baseName, mods);
System.out.println("update successful!!!");
}
catch (Exception e) {
System.out.println(" update error: " + e);
System.exit(-1);
}
}
public static void main(String[] args) {
ADConnection adc = new ADConnection();
adc.updateDescription("batman");
}
}
ERROR: update error: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-0310020A, problem 2001 (NO_OBJECT), data 0, best match of:
The crash is on the 6th line of code in the function updateDescription. Any suggestions?
CNattribtue value of the user.