繁体   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