Class: Soar::Registry::Staff::Identity

Inherits:
SoarIdm::IdmApi
  • Object
show all
Defined in:
lib/soar/registry/staff/identity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Identity

Returns a new instance of Identity.

Parameters:

  • configuration (Hash)

    for example see config/config.yml

Raises:



19
20
21
22
23
24
25
26
27
28
# File 'lib/soar/registry/staff/identity.rb', line 19

def initialize(configuration)
  @translator = Object.const_get(configuration['rule_set']['adaptor']).new
  @directory = Object::const_get(configuration['provider']['adaptor']).new
  @directory.bootstrap(configuration['provider']['config'])
  @directory.authenticate(configuration['provider']['credentials'])
  @client = @directory.connect
  raise Soar::Registry::Staff::Directory::Error::BootstrapError if not @directory.bootstrapped? 
  raise Soar::Registry::Staff::Directory::Error::ConnectionError if not @directory.connected?
  raise Soar::Registry::Staff::Directory::Error::NotReadyError if not @directory.ready?
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



13
14
15
# File 'lib/soar/registry/staff/identity.rb', line 13

def client
  @client
end

#directoryObject (readonly)

Returns the value of attribute directory.



11
12
13
# File 'lib/soar/registry/staff/identity.rb', line 11

def directory
  @directory
end

#translatorObject (readonly)

Returns the value of attribute translator.



12
13
14
# File 'lib/soar/registry/staff/identity.rb', line 12

def translator
  @translator
end

Instance Method Details

#calculate_all_attributes(identity) ⇒ Hash

Returns Hash of attributes keyed by role.

Parameters:

  • identity_id (String)

Returns:

  • (Hash)

    Hash of attributes keyed by role



73
74
75
76
# File 'lib/soar/registry/staff/identity.rb', line 73

def calculate_all_attributes(identity)
  entry = @directory.fetch_identity(identity['identity_id'])
  @translator.get_identity(entry)
end

#calculate_attributes(identity, role) ⇒ Hash

Returns A hash of attributes.

Parameters:

  • identity_id (String)
  • role (String)

Returns:

  • (Hash)

    A hash of attributes



63
64
65
66
67
68
# File 'lib/soar/registry/staff/identity.rb', line 63

def calculate_attributes(identity, role)
  entry = @directory.fetch_identity(identity['identity_id'])
  return nil if not entry
  identity = @translator.get_identity(entry)
  { role => identity['roles'][role] }
end

#calculate_identifiers(identity) ⇒ Array

Returns list of identifiers.

Parameters:

  • identity_id (String)

Returns:

  • (Array)

    list of identifiers



48
49
50
51
52
53
54
55
56
57
# File 'lib/soar/registry/staff/identity.rb', line 48

def calculate_identifiers(identity)
  indexes = @directory.indexed_attributes
  entry = @directory.fetch_identity(identity['identity_id'])
  identity = @translator.get_identity(entry)
  identifiers = []
  indexes.each { |index| 
    identifiers << identity[index]
  }
  identifiers
end

#calculate_identities(identifier) ⇒ Array

Parameters:

  • identity_id (String|Hash)

    or identifier (a hash containing attribute name and attribute value)

Returns:

  • (Array)


81
82
83
84
85
86
87
88
# File 'lib/soar/registry/staff/identity.rb', line 81

def calculate_identities(identifier)
  if @translator.is_json?(identifier)
    identifier = @translator.get_identifier(identifier)
    entries = @directory.search_identities(identifier.keys[0], identifier[identifier.keys[0]] )
    return [@translator.get_identity(entries)[0]]
  end
  return [@translator.get_identity(@directory.fetch_identity(identifier))]
end

#calculate_roles(identity) ⇒ Array

Returns list of roles.

Parameters:

  • identity_id (String)

Returns:

  • (Array)

    list of roles



33
34
35
36
37
38
39
40
41
42
# File 'lib/soar/registry/staff/identity.rb', line 33

def calculate_roles(identity)
  entry = @directory.fetch_identity(identity['identity_id'])
  return nil if not entry
  identity = @translator.get_identity(entry)
  roles = []
  identity['roles'].each do |role, attributes|
    roles << role
  end
  roles
end