Skip to content

Instantly share code, notes, and snippets.

@renanregis
Last active July 19, 2018 15:42
Show Gist options
  • Save renanregis/3fa3564196cb44419b33edc800724f8d to your computer and use it in GitHub Desktop.
Save renanregis/3fa3564196cb44419b33edc800724f8d to your computer and use it in GitHub Desktop.
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