java - Creating new users with Spring Data LdapRepository fails with LDAP error code 32 -


i attempting use spring data , ldaprepository api read, update , create user data in ldap. have been able read , update successfully, whenever attempt insert new record error:

2017-07-25 17:31:01.966 error 14404 --- [nio-8080-exec-1] o.a.c.c.c.[.[.[/].[dispatcherservlet]    : servlet.service() servlet [dispatcherservlet] in context path [] threw exception [request processing failed;  nested exception org.springframework.ldap.namenotfoundexception:  [ldap: error code 32 - search base entry 'uid=testy1@testy.org,ou=people,ou=myou,dc=bar,dc=foo' not exist];  nested exception javax.naming.namenotfoundexception:  [ldap: error code 32 - search base entry 'uid=testy1@testy.org,ou=people,ou=myou,dc=bar,dc=foo' not exist]; remaining name 'uid=testy1@testy.org']  root cause javax.naming.namenotfoundexception: [ldap: error code 32 - search base entry 'uid=testy1@testy.org,ou=people,ou=myou,dc=bar,dc=foo' not exist] 

my application.properties is:

user-api.ldap.contextsource.url=ldap://server.address.com:1389 user-api.ldap.contextsource.userdn=cn=manager role user-api.ldap.contextsource.password=apasswordwashere user-api.ldap.contextsource.base=ou=people,ou=myou,dc=bar,dc=foo 

my repo interface, ldapuserrepository.java:

public interface ldapuserrepository extends ldaprepository<ldapuser>{     ldapuser findbycn(string cn);     ldapuser findbysn(string sn);     ldapuser save(ldapuser ldapuser); } 

i same response whether or not explicitly expose save method.

my configuration done in ldapconfiguration.java:

@configuration @enableldaprepositories(basepackages = "foo.bar.userapi.dao.ldap", ldaptemplateref="userldaptemplate") public class ldapconfiguration {      @autowired     environment env;      @bean     public ldapcontextsource contextsource () {         ldapcontextsource contextsource= new ldapcontextsource();         contextsource.seturl(env.getrequiredproperty("user-api.ldap.contextsource.url"));         contextsource.setbase(env.getrequiredproperty("user-api.ldap.contextsource.base"));         contextsource.setuserdn(env.getrequiredproperty("user-api.ldap.contextsource.userdn"));         contextsource.setpassword(env.getrequiredproperty("user-api.ldap.contextsource.password"));         return contextsource;     }      @bean(name="userldaptemplate")     public ldaptemplate ldaptemplate() {         return new ldaptemplate(contextsource());            }  } 

and test routine:

public void test() {    ldapuser ldapuser =  new ldapuser();     ldapuser.setcn("198777777");    ldapuser.setcountry("united states");    ldapuser.setgivenname("hepsibah");    ldapuser.setisactive("true");    ldapuser.setsn("testerson91");    ldapuser.setstatus("active");    ldapuser.setuid(ldaputils.newldapname("uid=testy1@testy.org"));    ldapuser.setusermodifytimestamp("20160222145439z");    ldapuser.setuserpassword("password-12345");    ldapuser = ldapuserrepository.save(ldapuser); } 

to stress, configuration works except inserts, since if this, works:

   public void test2() {           ldapuser ldapuser =  ldapuserrepository.findbysn("testerson");           if ( ldapuser != null) {                  system.out.println(ldapuser.getuid().tostring());                  system.out.println("result: " + ldapuser.tostring());                   ldapuser.setsn("testerson2");                  ldapuser.setuserpassword("password-12345!");                  ldapuser = ldapuserrepository.save(ldapuser);                   ldapuser = ldapuserrepository.findbysn("testerson2");                  if ( ldapuser != null) {                        system.out.println("result: " + ldapuser.tostring());                  }           }    } 

i suspect answer may ldap error code 32 while adding user ldap not explictly adding dn during save operation, , update operation works fine.

retrieving record, changing uid value , saving gives same error. retrieving record , inspecting uid shows "uid=testy1@testy.org" part , not "ou=people,ou=myou,dc=bar,dc=foo" part.

assuming default implementation being used (simpleldaprepository - you'll if haven't implemented repository interface yourself) problem occurring when simpleldaprepository tries determine whether should 'save' or 'update' entity. here code in simpleldaprepository looks this:

 @override  public <s extends t> s more ...save(s entity) {      assert.notnull(entity, "entity must not null");      name declaredid = odm.getid(entity);       if (isnew(entity, declaredid)) {          ldapoperations.create(entity);      } else {          ldapoperations.update(entity);      }       return entity;  } 

to the error seeing entity not being determined new, update performed fails when entity found not exist , can't updated.

the isnew() method looks this:

     private <s extends t> boolean more ...isnew(s entity, name id) {      if (entity instanceof persistable) {          persistable<?> persistable = (persistable<?>) entity;          return persistable.isnew();      } else {          return id == null;      }  } 

in example looks required set id. other option implement persistable interface , isnew() method return whether entity new or not. if entity determined new (you can call e.g. ldapuser.setnew(true); before saving), saved rather updated.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -