Jruby-ldap - undefined method `to_java_attributes'

Hi folks,

I’m working on some ruby code to populate and modify one of our OpenLDAP
servers - it’s using JRuby 1.1.4 and jruby-ldap-0.0.1 for this purpose.
I’ve been following the guide at
Ruby - LDAP Tutorial | Tutorialspoint and the docs at
RDoc Documentation. Searching the directory is a
breeze and works really well :slight_smile:

I’m now trying to add entries to the directory:

newLdapEntry[0] = “LDAP.mod(LDAP::LDAP_MOD_ADD, ‘objectclass’,
[‘top’,‘fmscAccount’])”
newstaffaccount.each do |var,val|
n += 1
newLdapEntry[n] = “LDAP.mod(LDAP::LDAP_MOD_ADD, ‘#{var}’,
[‘#{val}’]),”
end
conn.add(“#{newstaffaccount[“dn”]}”, newLdapEntry)

When I run the code I appear to get an error from jruby-ldap:

lib/ruby/gems/1.8/gems/jruby-ldap-0.0.1/lib/ldap/mod.rb:22:in
to_java_attributes': undefined method to_java_attributes’ for
#String:0x7c9ed5d6 (NoMethodError)

If I display the newLdapEntry structure:

newLdapEntry.each do |row|
puts row
end

I get something similar to this:
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘objectclass’, [‘top’,‘fmscAccount’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘uid’, [‘ntestacc’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘login’, [‘ntestacc’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘fmscstage’, [‘1’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘uniqode’, [‘11111111’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘displayname’, [‘Mr Miscellaneous (Test
Guy)’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘password’, [‘asdkjnvdk’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘fmscdept’, [DEPT])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘fmscpersongroup’, [‘Staff’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘givenname’, [‘Test Guy’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘mail’, [‘[email protected]’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘surname’, [‘Miscellaneous’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘title’, [‘Mr’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘fmsccoursecode’, [‘ZZ99’])
LDAP.mod(LDAP::LDAP_MOD_ADD, ‘dn’,
[‘uid=ntestacc,ou=misc,ou=people,ou=newcastle,dc=ncl,dc=ac,dc=uk’]),

Is there something wrong with this array of LDAP.mod attributes I am
passing to the conn.add method? Or is there something more fundamental
going on with jruby-ldap?

John

Unix & Web Infrastructure Management
Faculty of Medical Sciences Computing
University of Newcastle

Email : [email protected]
Web: http://www.ncl.ac.uk/medev


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

John S. wrote:

end
conn.add("#{newstaffaccount[“dn”]}", newLdapEntry)

When I run the code I appear to get an error from jruby-ldap:

lib/ruby/gems/1.8/gems/jruby-ldap-0.0.1/lib/ldap/mod.rb:22:in to_java_attributes': undefined methodto_java_attributes’ for #String:0x7c9ed5d6 (NoMethodError)

It looks like it’s either depending on a method we eliminated
(unlikely…never seen that before) or something’s wrong with the code
in that it’s not defining that method. Mostly seems like a
jruby-ldap-0.0.1 bug. Have you tried contacting anyone involved in that
project? (and yeah, I know they probably have moved on, but it’s worth a
try)

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. wrote:

I’m now trying to add entries to the directory:
When I run the code I appear to get an error from jruby-ldap:
worth a try)

That would be me.

Not sure why this fails actually. Or rather, when I look at the back
trace and the line number, it’s obvious that something is strange. the
to_java_attributes method is defined at that point. It’s a class method
on LDAP::Mod, and the only usage I can see of it is using it correctly,
so this is not about the to_java_attributes method itself. Something
else is going wrong.

Actually, now I see it. You have a bug in your code.
The LDAP.mod statements are in quotes. That’s totally wrong. It should
look like this:

newLdapEntry[0] = LDAP.mod(LDAP::LDAP_MOD_ADD, ‘objectclass’,
[‘top’,‘fmscAccount’])
newstaffaccount.each do |var,val|
n += 1
newLdapEntry[n] = LDAP.mod(LDAP::LDAP_MOD_ADD, ‘#{var}’, [‘#{val}’])
end
conn.add(“#{newstaffaccount[“dn”]}”, newLdapEntry)

The error message is wrong though. The method it should complain about
is to_java_attribute - while it is IN to_java_attributes.

Cheers


Ola B. (http://olabini.com)
JRuby Core Developer
Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
Practical JRuby on Rails (http://apress.com/book/view/9781590598818)

“Yields falsehood when quined” yields falsehood when quined.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks guys, I came to the same conclusion yesterday afternoon after
reading the tutorials a bit more thoroughly :slight_smile: