Class: SoarLdap::LdapProvider

Inherits:
SoarIdm::DirectoryProvider
  • Object
show all
Defined in:
lib/soar_ldap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ LdapProvider

Returns a new instance of LdapProvider.



23
24
25
# File 'lib/soar_ldap.rb', line 23

def initialize(configuration)      
  bootstrap(configuration)
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



21
22
23
# File 'lib/soar_ldap.rb', line 21

def cache
  @cache
end

#configurationObject (readonly)

Returns the value of attribute configuration.



13
14
15
# File 'lib/soar_ldap.rb', line 13

def configuration
  @configuration
end

#connectionObject (readonly)

Returns the value of attribute connection.



20
21
22
# File 'lib/soar_ldap.rb', line 20

def connection
  @connection
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



17
18
19
# File 'lib/soar_ldap.rb', line 17

def credentials
  @credentials
end

#passwordObject (readonly)

Returns the value of attribute password.



19
20
21
# File 'lib/soar_ldap.rb', line 19

def password
  @password
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/soar_ldap.rb', line 14

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/soar_ldap.rb', line 16

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



15
16
17
# File 'lib/soar_ldap.rb', line 15

def server
  @server
end

#usernameObject (readonly)

Returns the value of attribute username.



18
19
20
# File 'lib/soar_ldap.rb', line 18

def username
  @username
end

Instance Method Details

#authenticate(credentials) ⇒ Object



38
39
40
41
42
# File 'lib/soar_ldap.rb', line 38

def authenticate(credentials)
  @credentials = nil
  validate_credentials(credentials)
  remember_credentials(credentials)
end

#bootstrap(configuration) ⇒ Object



27
28
29
30
31
32
# File 'lib/soar_ldap.rb', line 27

def bootstrap(configuration)
  @configuration = nil
  validate_configuration(configuration)
  remember_configuration(configuration)
  initialize_cache(configuration)
end

#bootstrapped?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/soar_ldap.rb', line 34

def bootstrapped?
  not @configuration.nil?
end

#connectObject



44
45
46
47
48
49
50
51
52
# File 'lib/soar_ldap.rb', line 44

def connect
  @connection = ::LDAP::Conn.new(@server, @port)
  @connection.set_option(::LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
  @connection.bind(@username, @password)
  @connection

rescue => ex
  raise SoarLdapError.new("Connection error + #{ex}")
end

#connected?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/soar_ldap.rb', line 54

def connected?
  not @connection.nil?
end

#get_entity(identifier) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/soar_ldap.rb', line 67

def get_entity(identifier)
  connect if not connected?
  cached = retrieve_from_cache(@connection, identifier)
  return cached if cached
  result = find_entity(@connection, identifier)
  cache_result(@connection, identifier, result)
  result

rescue => ex
  raise SoarLdapError.new("Lookup error, #{ex}")
end

#ready?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/soar_ldap.rb', line 58

def ready?
  bootstrapped? and connected?
end

#uriObject

Raises:



62
63
64
65
# File 'lib/soar_ldap.rb', line 62

def uri
  raise SoarLdapError.new('Not bootstrapped') if not bootstrapped?
  "ldap://#{server}:#{port}/#{@path}"
end