Last active
July 19, 2018 15:42
-
-
Save renanregis/3fa3564196cb44419b33edc800724f8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ldap' | |
class LdapService | |
def con | |
@base = "dc=example, dc=com" | |
@ldap = Net::LDAP.new | |
@ldap.host = host | |
@ldap.port = 389 | |
@ldap.auth "CN= #user_for_bind #{@base}", "password" | |
arr = [] | |
if @ldap.bind | |
filter = "(&(objectClass=user)(sAMAccountName=))" | |
@ldap.search(:base => @base, :filter => filter) do |item| | |
arr << item.cn[0] | |
end | |
@ldap = {:usuarios => arr} | |
else | |
@ldap.get_operation_result | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment