Lee
Lee

Reputation: 661

ActiveLdap - Move user from one container to another

I have a user with the following:

'cn=example_user, ou=Person, dc=example, dc=com'

Using ActiveLdap, I'd like to change the container to:

'cn=example_user, ou=Inactive, dc=example, dc=com'

I'm missing something... I've searched and looked at the source code, and the possibility seems to be there but I'm not seeing how it's done. Thanks!

Upvotes: 1

Views: 433

Answers (2)

Lee
Lee

Reputation: 661

Finally figured this out. Here's what I did:

  1. After running setup_connection

    ActiveLdap::Base.setup_connection(host: host, port: port, etc.) 
    
  2. Call the modify_rdn method on connection

    ActiveLdap::Base.connection.modify_rdn(dn, new_rdn, remove_old_rdn, new_superior, options={})
    

I created a change_ou(new_ou) instance method on the model with ldap_mapping, so I pass:

  • dn for dn
  • "cn=#{cn}" for new_rdn
  • true for remove_old_rdn
  • "ou=#{new_ou},dc=example,dc=com" for new_superior

The variable new_ou is, of course, the name of the new container(which would be "Inactive" in my example above). I don't pass anything for options since it defaults to any empty hash.

Below is the link to the source code for the modify_rdn method. I was having a hard time figuring out that it needed to be called from ActiveLdap::Base.connection:

https://github.com/activeldap/activeldap/blob/master/lib/active_ldap/adapter/base.rb#L236

Upvotes: 0

Terry Gardner
Terry Gardner

Reputation: 11132

Use the MODIFY DN operation for this purpose. See also:

Upvotes: 1

Related Questions