-3

I want to check an organizational unit (OU) is available in LDAP using Java code.

My requirement is from this base dn ou=people,dc=agroup,dc=com i have fetch a user based on some attribute eg: email attribute is not null and i have to move those users to new base dn "dc=com to dc=1a_archive,dc=com" using java and in the destination basedn if the ou is not available,(eg :ou=nce,o=hotel,ou=company) is it possible to create these ou of a user in the destination base dn with java code? if yes please provide the solution

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216

1 Answers1

1

There's not a simple one-liner to accomplish this. The outline of a multi-step process would be as follows:

  1. Determine the OU into which you want to move the user -- e.g. ou=something,ou=somethingelse,dc=example,dc=com

  2. Perform a one-level search for "(&(objectClass=organizationalUnit)(ou=Something))" at the base ou=somethingelse,dc=example,dc=com

  3. If the number of records returned from the search is 0, create the OU. See something like https://self-learning-java-tutorial.blogspot.com/2016/05/add-new-entry-to-ldap-using-java.html for an example of creating an LDAP object using Java. Use an existing OU to mirror the attributes (OUs are fairly simple objects, you need the objectClass of organziationalUnit and the ou value which is the OU name. You may want a description value

  4. MODRDN to move the user into the new location

LisaJ
  • 1,666
  • 1
  • 12
  • 18