class Ddr::Auth::LdapGateway

Constants

SCOPE

Attributes

ldap[R]

Public Class Methods

find(user_key) click to toggle source
# File lib/ddr/auth/ldap_gateway.rb, line 13
def self.find(user_key)
  new.find(user_key)
end
new() click to toggle source
# File lib/ddr/auth/ldap_gateway.rb, line 17
def initialize
  @ldap = Net::LDAP.new(config)
end

Public Instance Methods

find(user_key) click to toggle source
# File lib/ddr/auth/ldap_gateway.rb, line 21
def find(user_key)
  result_set = ldap.search find_params(user_key)
  if result_set
    Result.new result_set.first
  else
    raise ldap.get_operation_result.message
  end
end

Private Instance Methods

config() click to toggle source
# File lib/ddr/auth/ldap_gateway.rb, line 60
def config
  { host: ENV["LDAP_HOST"],
    port: ENV["LDAP_PORT"],
    base: ENV["LDAP_BASE"],
    auth:
      { method: :simple,
        username: ENV["LDAP_USER"],
        password: ENV["LDAP_PASSWORD"]
      },
    encryption: { method: :simple_tls }
  }
end
filter(user_key) click to toggle source
# File lib/ddr/auth/ldap_gateway.rb, line 56
def filter(user_key)
  Net::LDAP::Filter.eq("eduPersonPrincipalName", user_key)
end
find_params(user_key) click to toggle source
# File lib/ddr/auth/ldap_gateway.rb, line 48
def find_params(user_key)
  { scope: SCOPE,
    filter: filter(user_key),
    size: 1,
    attributes: attributes
  }
end