Trying to figure out whats wrong with ActiveLDAP

P

Petr Janda

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 = '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?
 
P

Petr Janda

I seem to have my some maybe progress by defining user.sn and commenting
out 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
 
R

Rick DeNatale

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 = '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 = 'Tony' line
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?


--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/

Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top