Forum: Ruby on Rails ActiveLDAP maintain user connection

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Leah C. (Guest)
on 2006-03-05 02:12
Hi, I've just started to do some work using ActiveLDAP and Rails.  I've
managed to get some basic login code that works to authenticate users,
but I would like to be able to maintain that connection for the User
Model so that the ACL's in LDAP for each user will be used correctly as
the various controller queries are made.  I haven't quite sorted out how
to do that.  Does anyone have any examples of code to do this, or a
documentation pointer?

<pre><code>
class User < ActiveLDAP::Base

        ldap_mapping :dnattr => 'uid', :prefix => USER_PREFIX, :classes
=> [
                'top', 'shadowAccount', 'posixAccount', 'person',
'inetOrgPerson',
                'OXUserObject', 'organizationalPerson'
        ]
        belongs_to :groups, :class_name => 'Group', :foreign_key =>
'memberUid'

        def self.login(username, password)
                begin
                        ActiveLDAP::Base.connect(
                                :host => HOST,
                                :port => PORT,
                                :base => BASE,
                                :bind_format =>
"uid=#{username},#{USER_PREFIX},#{BASE}",
                                :password_block => Proc.new { password
},
                                :allow_anonymous => false,
                                :try_sasl => false
                        )
                        #ldap = ActiveLDAP::Base.connection
                        #ActiveLDAP::Base.close
                        return true
                        rescue ActiveLDAP::AuthenticationError
                        return false
                end
        end
end
</pre></code>
Adam B. (Guest)
on 2006-03-05 04:02
(Received via mailing list)
On Saturday 04 March 2006 05:12 pm, Leah C. wrote:
> Hi, I've just started to do some work using ActiveLDAP and Rails.  I've
> managed to get some basic login code that works to authenticate users,
> but I would like to be able to maintain that connection for the User
> Model so that the ACL's in LDAP for each user will be used correctly as
> the various controller queries are made.  I haven't quite sorted out how
> to do that.  Does anyone have any examples of code to do this, or a
> documentation pointer?

You won't be able to have multiple ldap connections under one rails app
using
ActiveLDAP.  It uses a global scope for a connection handler in its
foundation.  If your design doesn't need multiple connections at a
single
time, then this is okay.  I ran into the problem of needing them on a
per
model basis.

You can roll your own system for that or you can try my
plugin(acts_as_ldapable), just a warning quirks haven't been worked
out...
But it allows for a singleton based ldap connection.


--
----------
Sincerely,
Adam B.
Plutonic Networks
Learn about DotGNU =)
http://www.dotgnu.org
Leah C. (Guest)
on 2006-03-05 06:28
Adam B. wrote:

> You can roll your own system for that or you can try my
> plugin(acts_as_ldapable), just a warning quirks haven't been worked
> out...
> But it allows for a singleton based ldap connection.

Thanks.  I'd like to take a look at your plugin.  It looks like the link
on the wiki is broken, however.  Would you posting that?
This topic is locked and can not be replied to.