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?
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