2010-05-19 63 views

回答

3

ActiveDirectory是LDAP的实现。您可以使用RubyLDAP宝石与AD集成。我目前使用这个gem从RHEL服务器连接到Windows域控制器。

gem install ruby-ldap 
+0

您好jamin,我正在使用ruby-ldap并在rails3应用程序中遇到问题,请问您可以看看这个问题吗? http://stackoverflow.com/questions/11979920/ruby-ldap-gem-not-work-in-rails3-app-but-work-in-rails-console – 2012-08-16 02:36:41

1

对于Ruby的LDAP绑定是相当不错的 - 不完全美丽,但他们工作得很好。当然,您可以访问ActiveDirectory 作为的LDAP服务器。我从来没有尝试任何Ruby的ActiveDirectory绑定。

4

我用net-ldap宝石认证和工作查询ActiveDirectory的服务器。它运作良好。以下是一些示例代码,用于验证用户的登录凭据并获取其全名。

def name_for_login(email, password) 
    email = email[/\A\w+/].downcase # Throw out the domain, if it was there 
    email << "@mycompany.com"  # I only check people in my company 
    ldap = Net::LDAP.new(
    host: 'ldap.mycompany.com', # Thankfully this is a standard name 
    auth: { method: :simple, email: email, password:password } 
) 
    if ldap.bind 
    # Yay, the login credentials were valid! 
    # Get the user's full name and return it 
    ldap.search(
     base:   "OU=Users,OU=Accounts,DC=mycompany,DC=com", 
     filter:  Net::LDAP::Filter.eq("mail", email), 
     attributes: %w[ displayName ], 
     return_result:true 
    ).first.displayName.first 
    end 
end