[英]What gems should I use to have a Ruby app talk to an LDAP server?
我的總體目標是讓我的Rails應用程序的用戶通過LDAP針對我們組織的ActiveDirectory服務器進行身份驗證。 (我說對了嗎?)
我想嘗試Ruby ActiveLDAP gem。
文檔說這取決於...
要么...
我使用哪一個無關緊要?
通過調查Ruby ActiveLDAP,我是否朝着正確的總體方向發展? 還有別的更好嗎?
我有一台openldap服務器,用於通過我的Rails應用程序進行身份驗證。
我基本上使用authlogic和hack通過使用ruby-net-ldap gem與ldap服務器進行通信來支持ldap。
我使用了本教程中詳細介紹的相當基本的authlogic設置,但做了一些更改:
class UserSession < Authlogic::Session::Base
verify_password_method :valid_ldap_credentials?
end
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.validate_password_field = false
c.logged_in_timeout = 30.minutes
end
def valid_ldap_credentials?(password_plaintext)
ldap = ldap_connect
ldap.auth self.dn, password_plaintext
ldap.bind # will return false if authentication is NOT successful
end
def ldap_connect(params = {})
ldap_config = YAML.load_file("#{RAILS_ROOT}/config/ldap.yml")[RAILS_ENV]
ldap_options = params.merge({:encryption => :simple_tls})
ldap = Net::LDAP.new(ldap_options)
ldap.host = ldap_config["host"]
ldap.port = ldap_config["port"]
ldap.base = ldap_config["base"]
ldap.auth ldap_config["admin_user"], ldap_config["admin_password"] if params[:admin]
return ldap
end
end
目前正在努力為ldap制作用於authlogic的插件,但是一段時間以來我還沒有看到任何進展。
我發現(並詢問 )的困難之處在於測試。 我基本上必須設置LDAP服務器的生產,開發和測試實例以進行測試。
如果您只想使用LDAP並發布自己的授權內容,則建議使用ruby-net-ldap。
但是請注意,如果由於某種原因(我只有登錄名)而沒有用戶名,則需要一個單獨的用戶來查詢LDAP。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.