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.



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

def initialize(configuration)      
  bootstrap(configuration)
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



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

def cache
  @cache
end

#configurationObject (readonly)

Returns the value of attribute configuration.



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

def configuration
  @configuration
end

#connectionObject (readonly)

Returns the value of attribute connection.



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

def connection
  @connection
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



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

def credentials
  @credentials
end

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



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

def server
  @server
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#authenticate(credentials) ⇒ Object



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

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

#bootstrap(configuration) ⇒ Object



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

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

#bootstrapped?Boolean

Returns:

  • (Boolean)


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

def bootstrapped?
  not @configuration.nil?
end

#connectObject



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

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)


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

def connected?
  not @connection.nil?
end

#get_entity(identifier) ⇒ Object



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

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)


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

def ready?
  bootstrapped? and connected?
end

#uriObject

Raises:



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

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