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> -- Posted via http://www.ruby-forum.com/.
On Saturday 04 March 2006 05:12 pm, Leah Cunningham 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 Ballai Plutonic Networks Learn about DotGNU =) http://www.dotgnu.org
Adam Ballai 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? -- Posted via http://www.ruby-forum.com/.