Add Operation

Creates a new LDAP entry in the directory.

AddOperation add = new AddOperation(new DefaultConnectionFactory("ldap://directory.ldaptive.org"));
AddResponse res = add.execute(AddRequest.builder()
  .dn("uid=dfisher,ou=people,dc=ldaptive,dc=org")
  .attributes(new LdapAttribute("uid", "dfisher"), new LdapAttribute("mail", "dfisher@ldaptive.org"))
  .build());
if (res.isSuccess()) {
  // add succeeded
} else {
  // add failed
}

The operation can be configured to throw so the result code doesn’t need to be checked.

AddOperation add = AddOperation.builder()
  .factory(new DefaultConnectionFactory("ldap://directory.ldaptive.org"))
  .throwIf(ResultPredicate.NOT_SUCCESS)
  .build();
add.execute(AddRequest.builder()
  .dn("uid=dfisher,ou=people,dc=ldaptive,dc=org")
  .attributes(new LdapAttribute("uid", "dfisher"), new LdapAttribute("mail", "dfisher@ldaptive.org"))
  .build());