Class: UcbGroups::LdapConn

Inherits:
Object
  • Object
show all
Defined in:
lib/ucb_groups/ldap_conn.rb

Class Method Summary collapse

Class Method Details

.auth_infoObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ucb_groups/ldap_conn.rb', line 23

def self.auth_info
  @auth_info ||= {
      host: "ldap.berkeley.edu",
      auth: {
          method: :simple,
          username: @username,
          password: @password,
      },
      port: 636,
      encryption: { method: :simple_tls }
  }
end

.authenticate(username, password) ⇒ Object



11
12
13
14
# File 'lib/ucb_groups/ldap_conn.rb', line 11

def self.authenticate(username, password)
  @username = username
  @password = password
end

.authenticate_from_config(config_file) ⇒ Object



16
17
18
19
# File 'lib/ucb_groups/ldap_conn.rb', line 16

def self.authenticate_from_config(config_file)
  conf = YAML.load_file(config_file)
  @username, @password = conf['username'], conf['password']
end

.connObject



3
4
5
6
7
8
9
# File 'lib/ucb_groups/ldap_conn.rb', line 3

def self.conn
  net_ldap = ::Net::LDAP.new(auth_info)
  net_ldap.bind || raise(BindFailedException)
  net_ldap
rescue ::Net::LDAP::LdapError
  raise(LdapBindFailedException)
end