有没有一种方法可以通过事实来决定和确认,哪个更好并且更容易与Ruby集成。LDAP还是ActiveDirectory?
我使用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
ActiveDirectory是LDAP的一种实现。您可以使用RubyLDAP gem与AD集成。我目前正在使用这个gem从RHEL服务器连接到Windows域控制器。
gem install ruby-ldap
Ruby的LDAP绑定相当不错--虽然不是非常美观,但它们工作得很好。当然,你也可以将ActiveDirectory作为LDAP服务器访问。我从未尝试过任何Ruby的ActiveDirectory绑定。