Sha256: 5b93500f5d54fb712d7870cc953c8b071b1b96b70610640ae40079f0a39ca2a5
Contents?: true
Size: 1.64 KB
Versions: 3
Compression:
Stored size: 1.64 KB
Contents
require 'net/ldap' require 'telemetry/snmp/auth/defaults' module Telemetry module Snmp class Auth include Telemetry::Snmp::AuthDefaults def initialize(username:, **opts) @username = username @details = {} @opts = opts end def process_result(result) unless result.is_a? Net::LDAP::Entry @success = false return end @details[:username] = result.sAMAccountName.first @details[:email] = result.mail.first @details[:first] = result.givenName.first @details[:last] = result.sn.first @success = true end def search_user(ldap, username) user_filter = Net::LDAP::Filter.eq('sAMAccountName', username) ldap.search(base: treebase, filter: user_filter, attrs: attrs, return_result: false) do |entry| @details[:group_access] = entry.memberof.include?("CN=#{admin_group}, #{treebase}") return entry end end def auth_with_service(password) options = defaults options[:auth] = defaults_auth result = provider.new(options).bind_as(base: defaults[:base], attributes: attrs, filter: filter, password: password) # rubocop:disable Layout/LineLength process_result(result.first) end def auth_without_service(password) options = { host: defaults[:host], port: defaults[:port] } options[:auth] = { password: password, username: @username, method: :simple } ldap = provider.new(options) @success = ldap.bind return unless @success process_result(search_user(ldap, @username)) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
telemetry-snmp-0.3.0 | lib/telemetry/snmp/auth.rb |
telemetry-snmp-0.2.0 | lib/telemetry/snmp/auth.rb |
telemetry-snmp-0.1.0 | lib/telemetry/snmp/auth.rb |