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



40
41
42
43
44
# File 'lib/soar_ldap.rb', line 40

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

#bootstrap(configuration) ⇒ Object



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

def bootstrap(configuration)
  @configuration = nil
  validate_configuration(configuration)
  remember_configuration(configuration)
  @freshness = configuration['freshness']
  @freshness ||= 0
  @cache = ::Persistent::Cache.new("soar_ldap", @freshness, Persistent::Cache::STORAGE_RAM)
end

#bootstrapped?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/soar_ldap.rb', line 36

def bootstrapped?
  not @configuration.nil?
end

#connectObject



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

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)


56
57
58
# File 'lib/soar_ldap.rb', line 56

def connected?
  not @connection.nil?
end

#get_entity(identifier) ⇒ Object



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

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)


60
61
62
# File 'lib/soar_ldap.rb', line 60

def ready?
  bootstrapped? and connected?
end

#uriObject

Raises:



64
65
66
67
# File 'lib/soar_ldap.rb', line 64

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