簡體   English   中英

使用ldap通過rails上的devise ruby​​連接到廣告

[英]Using ldap to connect to ad with devise ruby on rails

問題我在使用devise_ldap_authentication連接到我的Microsoft Active Directory時遇到問題。 出於某種原因,我一直在使用設計時將LDAP搜索產生0匹配並且我100%確定我使用了正確的憑據,因此我使用'net / ldap'編寫了一個測試類,看看我是否能夠提供正確的匹配並且它可以與我的測試類一起使用但是,我仍然無法使用devise_ldap_auth進行身份驗證。 任何幫助將非常感謝或幫助設置我的config / ldap.yml以匹配我的測試類。

這是我的config / ldap.yml

#Environment
development:
  host: myldap.mydomain.com
  port: 389
  attribute: sAMAccountname
  base: dc=mydomain, dc=com
  admin_user: cn=admin,dc=mydomain,dc=com
  admin_password: password
  #ssl: false

這是我的設計.rb

Devise.setup do |config|
  # ==> LDAP Configuration
  config.ldap_logger = true
  # config.ldap_create_user = false
  # config.ldap_update_password = true
  config.ldap_config = "#{Rails.root}/config/ldap.yml"
  # config.ldap_check_group_membership = false
  # config.ldap_check_group_membership_without_admin = false
  config.ldap_check_attributes = true
  #config.ldap_use_admin_to_bind = true
  # config.ldap_ad_group_check = false

這是我在使用帶有設計的ldap時得到的。

D, [2016-06-24T07:01:30.558440 #42760] DEBUG -- :   LDAP: LDAP dn lookup: sAMAccountName=snow
D, [2016-06-24T07:01:30.558507 #42760] DEBUG -- :   LDAP: LDAP dn lookup: sAMAccountName=snow
D, [2016-06-24T07:01:30.558549 #42760] DEBUG -- :   LDAP: LDAP search for login: sAMAccountName=snow
D, [2016-06-24T07:01:30.558579 #42760] DEBUG -- :   LDAP: LDAP search for login: sAMAccountName=snow
D, [2016-06-24T07:01:30.594029 #42760] DEBUG -- :   LDAP: LDAP search yielded 0 matches
D, [2016-06-24T07:01:30.594099 #42760] DEBUG -- :   LDAP: LDAP search yielded 0 matches
D, [2016-06-24T07:01:30.594146 #42760] DEBUG -- :   LDAP: Authorizing user sAMAccountName=snow,dc=mydomain, dc=com
D, [2016-06-24T07:01:30.594180 #42760] DEBUG -- :   LDAP: Authorizing user sAMAccountName=snow,dc=mydomain, dc=com
D, [2016-06-24T07:01:30.611308 #42760] DEBUG -- :   LDAP: Not authorized because not authenticated.
D, [2016-06-24T07:01:30.611377 #42760] DEBUG -- :   LDAP: Not authorized because not authenticated.

這是我的測試類,可以在我的Microsoft AD上使用ldap進行身份驗證

require 'net/ldap' # gem install ruby-net-ldap
module Test
  class PutAd
    SERVER = 'myldap.mydomain.com'
    PORT = 389
    BASE = 'DC=mydomain,DC=com'
    DOMAIN = 'mydomain.com'

    ATTR_SV = {
                :login => :samaccountname,
                :first_name => :givenname,
                :last_name => :sn,
                :email => :mail
              }


    def self.authenticate(login, pass)
      return nil if login.empty? or pass.empty?

      conn = Net::LDAP.new :host => SERVER,
                           :port => PORT,
                           :base => BASE,
                           :auth => { :username => "#{login}@#{DOMAIN}",
                                      :password => pass,
                                      :method => :simple }
      if conn.bind and user = conn.search(:filter => "sAMAccountName=#{login}").first
        return self.new(user)
      else
        return nil
      end
    rescue Net::LDAP::LdapError => e
      return nil
    end
  end 
end 

^如果匹配則返回我的帳戶信息,否則返回nil。

事實證明我的公司有一種不同的授權用戶的方式。 我將高級標志添加到我的設計ldap安裝中,並相應地設置它並使其正常工作。

==>高級LDAP配置

config.ldap_auth_username_builder = Proc.new() {|attribute, login, ldap| "#{login}@mydomain.com"}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM