# Trying to figure out whats wrong with ActiveLDAP

**URL:** <https://www.ruby-forum.com/t/trying-to-figure-out-whats-wrong-with-activeldap/65179>\
**Category:** Ruby\
**Created:** [August 16, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/trying-to-figure-out-whats-wrong-with-activeldap/65179 "2006-08-16T17:32:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [August 16, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/trying-to-figure-out-whats-wrong-with-activeldap/65179/1 "2006-08-16T17:32:10Z")

</div>

Hi,  
Can I get help at this?

The code:

require ‘rubygems’  
require ‘activeldap’

ActiveLDAP::Base.connect(  
:host =\> ‘127.0.0.1’,  
:base =\> ‘dc=test,dc=com’,  
:bind\_format =\> ‘cn=Manager,dc=test,dc=com’,  
:password\_block =\> Proc.new { ‘xxxxx’ },  
:allow\_anonymous =\> false  
)

class User \< ActiveLDAP::Base  
ldap\_mapping :dnattr =\> ‘cn’, :prefix =\> ‘ou=users’, :classes =\>  
[‘inetOrgPerson’]  
end

user = User.new(‘tony’)  
user.objectClass = user.objectClass \<\< ‘inetOrgPerson’  
[user.cn](http://user.cn) = ‘Tony’  
user.userPassword = ‘yeahbaby’  
user.write

puts “User created”

and the error is:

/usr/pkg/lib/ruby/gems/1.8/gems/ruby-activeldap-0.7.4/lib/activeldap/base.rb:1377:in  
`attribute_method=': cannot modify the DN attribute value (ActiveLDAP::AttributeAssignmentError) from /usr/pkg/lib/ruby/gems/1.8/gems/ruby-activeldap-0.7.4/lib/activeldap/base.rb:957:in `method\_missing’  
from ldapadd.rb:19

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [August 16, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/trying-to-figure-out-whats-wrong-with-activeldap/65179/2 "2006-08-16T19:19:22Z")

</div>

I seem to have my some maybe progress by defining user.sn and commenting  
out [user.cn](http://user.cn) but still get an error:

/usr/pkg/lib/ruby/gems/1.8/gems/ruby-activeldap-0.7.4/lib/activeldap/base.rb:312:in  
`connection': Failed to add: '#<LDAP::Mod:0x285804cc>#<LDAP::Mod:0x285804a4>#<LDAP::Mod:0x28580378>#<LDAP::Mod:0x285802b0>' (ActiveLDAP::WriteError) from /usr/pkg/lib/ruby/gems/1.8/gems/ruby-activeldap-0.7.4/lib/activeldap/base.rb:913:in `write’  
from ldapadd.rb:22

Can anyone help me out? Thanks

---

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [August 20, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/trying-to-figure-out-whats-wrong-with-activeldap/65179/3 "2006-08-20T20:25:17Z")

</div>

On 8/16/06, Petr J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> class User \< ActiveLDAP::Base  
> ldap\_mapping :dnattr =\> ‘cn’, :prefix =\> ‘ou=users’, :classes =\>  
> [‘inetOrgPerson’]  
> end
> 
> user = User.new(‘tony’)

I think that ActiveLDAP::Base wants a string argument to new to be of  
the form:  
“attr=val”

where attr is the dnattr, so in this case, since you set the dnattr to  
‘cn’ in the ldap mapping, it should be  
‘cn=tony’

instead of just ‘tony’. If it’s not in that form, then it looks like  
it sets the distinquished name attribute (or cn in this case) to an  
empty string.

> user.objectClass = user.objectClass \<\< ‘inetOrgPerson’  
> [user.cn](http://user.cn) = ‘Tony’

I suspect that this is line 19 in your source file. It’s trying to  
change the cn attribute to ‘tony’ but since cn is the dnattr, it won’t  
do it. The dn is effectively the “identity” of the ldap object.

Try changing the parameter to new to “Tony” and get rid of the  
[user.cn](http://user.cn) = ‘Tony’ line

> ```
> from ldapadd.rb:19
> 
> ```
> 
> What am I doing wrong?
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

IPMS/USA Region 12 Coordinator  
[http://ipmsr12.denhaven2.com/](http://ipmsr12.denhaven2.com/)

Visit the Project Mercury Wiki Site  
[http://www.mercuryspacecraft.com/](http://www.mercuryspacecraft.com/)
