net::LDAP and can't dump singleton method

What does this mean and how do I fix it? It makes my server hang with a
500 error.

On 10/2/06, bluengreen [email protected] wrote:

What does this mean and how do I fix it? It makes my server hang with a
500 error.

A full backtrace would be useful.

Chances are, you’re trying to do something that tries to Marshal a
Net::LDAP object, and that can’t be marshaled because it’s got a
singleton method on it (that is, the object’s singleton class has a
method, and if you don’t understand that – I suggest you look up
singleton class, metaclass, and eigenclass in the context of Ruby).

Have you got your Net::LDAP operation modified and/or in a transaction?

-austin

Austin Z. * [email protected] * http://www.halostatue.ca/
* [email protected] * You are in a maze of twisty little passages, all alike. // halo • statue
* [email protected]

You are correct about all those things. That is exactly what I’m
doing. I have my Net::LDAP stuff inside of my ActiveRecord model for
users. It’s within a login method. Here is what I’m trying to do,

def self.login(username, password)
begin
ldap = Net::LDAP.new
ldap.host = “gonzo”
ldap.port = 389

  result = ldap.bind_as(
    :base => "dc=net",
    :filter => "(cn=#{username})",
    :password => password
  )

rescue  => e
      false
end
   result.first

end

And then use it like:

session[:user] = AuthUser.login(params[:user][“username”],
params[:user][“password”])

I’ve tried a million differnt ways. I can get it to work if all I
return from the method is true or false. If I try return any attributes
from the LDAP object it dumps errors on me.

It errors out when I try it outside of AR as well.

I just don’t know how would you go about saving the attribute values
into the session? Are they always tied to the object? Is there any way
to copy the values only?

Thanks in advance,
Phill

On 10/3/06, bluengreen [email protected] wrote:

You are correct about all those things. That is exactly what I’m
doing. I have my Net::LDAP stuff inside of my ActiveRecord model for
users. It’s within a login method. Here is what I’m trying to do,

…Unfortunately, I don’t really do much with Rails or Net::LDAP.
Hopefully others can help with that, but the dump message is a pure
Ruby issue related to trying to Marshal a singleton value.

This means you can’t put the actual auth result in the session (I’m
assuming it’s a Marshaled object); you will have to somehow get the
data out of the auth result and use those in the session. You may want
to try to write a little Ruby program that tries your auth without
Rails and get help about that from the Net::LDAP homepage.

-austin

Austin Z. * [email protected] * http://www.halostatue.ca/
* [email protected] * You are in a maze of twisty little passages, all alike. // halo • statue
* [email protected]

Austin Z. wrote:

On 10/2/06, bluengreen [email protected] wrote:

What does this mean and how do I fix it? It makes my server hang with a
500 error.

A full backtrace would be useful.

Chances are, you’re trying to do something that tries to Marshal a
Net::LDAP object, and that can’t be marshaled because it’s got a
singleton method on it (that is, the object’s singleton class has a
method, and if you don’t understand that – I suggest you look up
singleton class, metaclass, and eigenclass in the context of Ruby).

Have you got your Net::LDAP operation modified and/or in a transaction?

-austin

Austin Z. * [email protected] * http://www.halostatue.ca/
* [email protected] * You are in a maze of twisty little passages, all alike. // halo • statue
* [email protected]

Austin, you’re right. The Net::LDAP::Entry class has some stuff that
can’t be marshalled. (For one thing, there was a hash that took a
closure.) However, I changed this stuff recently so there should be no
problem marshalling entries. Look in entry.rb in the Net::LDAP distro
for commentary.

Bluengreen, if you’d be so kind as to sync to the latest Net::LDAP
source code and try again, I’d appreciate it. I think your problem is
fixed but it would be very helpful if you can confirm or deny.

There’s enough new stuff in Net::LDAP (performance improvements, LDIF
support) that it’s time for a new release anyway.

bluengreen wrote:

How do I sync with the source code? I have version 0.0.4 now. Is there
a svn repository?

Thanks,
Phill

Yes, the source is on Rubyforge. There are instructions there on how to
work with SVN anonymously. If you can’t figure it out, send me a private
email and I’ll send you a gem.

How do I sync with the source code? I have version 0.0.4 now. Is there
a svn repository?

Thanks,
Phill

Francis Thanks. I got the newest code. I got it to work. But I had to
convert it to an array to get it to my session variable:

result.first.to_a

Other wise I still get the dump error.

I dunno. Is this how it should work? Or should I just be able to pass
the entry to my session?

I get to the vars like this in my views and code…

session[:user][0][:dn]
session[:user][0][:cn]

etc…

It seems a little obtuse. But I’m still pretty green at Ruby.

Thanks,
Phill

bluengreen wrote:

Francis Thanks. I got the newest code. I got it to work. But I had to
convert it to an array to get it to my session variable:

result.first.to_a

Other wise I still get the dump error.

I dunno. Is this how it should work? Or should I just be able to pass
the entry to my session?

I get to the vars like this in my views and code…

session[:user][0][:dn]
session[:user][0][:cn]

etc…

It seems a little obtuse. But I’m still pretty green at Ruby.

Thanks,
Phill

I have to guess at this because I can’t see your code, but I think
you’re taking the return value from a call to Net::LDAP#search, which is
an array of Net::LDAP::Entry objects, and trying to stuff the result
into a Rails session. And of course the session barks because it can’t
persist the object. If you’re sure you’ve installed the latest code and
Rails is seeing the latest, then you should look at the error backtrace
to see if Rails is trying to call Net::LDAP::Entry’s custom _load and
_dump methods. (If you installed Net::LDAP 0.0.4 as a gem, then try
uninstalling the gem, because otherwise Rails might not be loading the
version of Net::LDAP you think it is.)

If you really can’t get past this, then there are alternative
approaches, but I really think this should work without any weird hacks.