Class: Identikey::Administration::User

Inherits:
Object
  • Object
show all
Defined in:
lib/identikey/administration/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, user = nil, persisted: false) ⇒ User

Returns a new instance of User.



71
72
73
74
75
# File 'lib/identikey/administration/user.rb', line 71

def initialize(session, user = nil, persisted: false)
  @session = session

  replace(user, persisted: persisted) if user
end

Instance Attribute Details

#backend_authObject

Returns the value of attribute backend_auth.



55
56
57
# File 'lib/identikey/administration/user.rb', line 55

def backend_auth
  @backend_auth
end

#created_atObject

Returns the value of attribute created_at.



48
49
50
# File 'lib/identikey/administration/user.rb', line 48

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



63
64
65
# File 'lib/identikey/administration/user.rb', line 63

def description
  @description
end

#digipassObject

Returns the value of attribute digipass.



53
54
55
# File 'lib/identikey/administration/user.rb', line 53

def digipass
  @digipass
end

#disabledObject

Returns the value of attribute disabled.



56
57
58
# File 'lib/identikey/administration/user.rb', line 56

def disabled
  @disabled
end

#domainObject

Returns the value of attribute domain.



51
52
53
# File 'lib/identikey/administration/user.rb', line 51

def domain
  @domain
end

#emailObject

Returns the value of attribute email.



45
46
47
# File 'lib/identikey/administration/user.rb', line 45

def email
  @email
end

#expiredObject

Returns the value of attribute expired.



61
62
63
# File 'lib/identikey/administration/user.rb', line 61

def expired
  @expired
end

#expires_atObject

Returns the value of attribute expires_at.



60
61
62
# File 'lib/identikey/administration/user.rb', line 60

def expires_at
  @expires_at
end

#has_digipassObject Also known as: digipass?

Returns the value of attribute has_digipass.



50
51
52
# File 'lib/identikey/administration/user.rb', line 50

def has_digipass
  @has_digipass
end

#has_passwordObject Also known as: password?

Returns the value of attribute has_password.



65
66
67
# File 'lib/identikey/administration/user.rb', line 65

def has_password
  @has_password
end

#last_auth_attempt_atObject

Returns the value of attribute last_auth_attempt_at.



62
63
64
# File 'lib/identikey/administration/user.rb', line 62

def last_auth_attempt_at
  @last_auth_attempt_at
end

#last_auth_success_atObject

Returns the value of attribute last_auth_success_at.



59
60
61
# File 'lib/identikey/administration/user.rb', line 59

def last_auth_success_at
  @last_auth_success_at
end

#local_authObject

Returns the value of attribute local_auth.



54
55
56
# File 'lib/identikey/administration/user.rb', line 54

def local_auth
  @local_auth
end

#lock_countObject

Returns the value of attribute lock_count.



57
58
59
# File 'lib/identikey/administration/user.rb', line 57

def lock_count
  @lock_count
end

#lockedObject Also known as: locked?

Returns the value of attribute locked.



58
59
60
# File 'lib/identikey/administration/user.rb', line 58

def locked
  @locked
end

#mobileObject

Returns the value of attribute mobile.



46
47
48
# File 'lib/identikey/administration/user.rb', line 46

def mobile
  @mobile
end

#ouObject

Returns the value of attribute ou.



52
53
54
# File 'lib/identikey/administration/user.rb', line 52

def ou
  @ou
end

#passwd_last_set_atObject

Returns the value of attribute passwd_last_set_at.



64
65
66
# File 'lib/identikey/administration/user.rb', line 64

def passwd_last_set_at
  @passwd_last_set_at
end

#phoneObject

Returns the value of attribute phone.



47
48
49
# File 'lib/identikey/administration/user.rb', line 47

def phone
  @phone
end

#updated_atObject

Returns the value of attribute updated_at.



49
50
51
# File 'lib/identikey/administration/user.rb', line 49

def updated_at
  @updated_at
end

#usernameObject

Returns the value of attribute username.



44
45
46
# File 'lib/identikey/administration/user.rb', line 44

def username
  @username
end

Class Method Details

.find(session:, username:, domain:) ⇒ Object



5
6
7
# File 'lib/identikey/administration/user.rb', line 5

def self.find(session:, username:, domain:)
  new(session).find(username, domain)
end

.search(session:, query:, options: {}, log: false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/identikey/administration/user.rb', line 9

def self.search(session:, query:, options: {}, log: false)
  [:has_digipass, :not_has_digipass].each do |funky_boolean|
    if query.key?(funky_boolean) && [true, false].include?(query[funky_boolean])
      query[funky_boolean] = query[funky_boolean] ? 'Assigned' : 'Unassigned'
    end
  end

  query_keys = {
    'has_digipass' => 'USERFLD_HAS_DP',
    'description'  => 'USERFLD_DESCRIPTION',
    'disabled'     => 'USERFLD_DISABLED',
    'domain'       => 'USERFLD_DOMAIN',
    'email'        => 'USERFLD_EMAIL',
    'expired'      => 'USERFLD_EXPIRED',
    'locked'       => 'USERFLD_LOCKED',
    'mobile'       => 'USERFLD_MOBILE',
    'org_unit'     => 'USERFLD_ORGANIZATIONAL_UNIT',
    'phone'        => 'USERFLD_PHONE',
    'username'     => 'USERFLD_USERID',
  }

  stat, users, error = session.execute(:user_query,
    attributes:    Base.search_attributes_from(query, attribute_map: query_keys),
    query_options: Base.search_options_from(options),
    log:           log
  )

  case stat
  when 'STAT_SUCCESS'   then (users||[]).map {|user| new(session, user, persisted: true) }
  when 'STAT_NOT_FOUND' then []
  else
    raise Identikey::Error, "Search user failed: #{stat} - #{error}"
  end
end

Instance Method Details

#clear_password!Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/identikey/administration/user.rb', line 134

def clear_password!
  ensure_persisted!

  stat, _, error = @session.execute(
    :user_execute_RESET_PASSWORD, username: username, domain: domain)

  if stat != 'STAT_SUCCESS'
    raise Identikey::OperationFailed, "Clear user #{self.username} password failed: #{stat} - #{error}"
  end

  self.has_password = false

  true
end

#destroy!Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/identikey/administration/user.rb', line 119

def destroy!
  ensure_persisted!

  stat, _, error = @session.execute(
    :user_execute_DELETE, username: username, domain: domain)

  if stat != 'STAT_SUCCESS'
    raise Identikey::OperationFailed, "Delete user #{self.username} failed: #{stat} - #{error}"
  end

  @persisted = false

  self
end

#find(username, domain) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/identikey/administration/user.rb', line 77

def find(username, domain)
  stat, user, error = @session.execute(
    :user_execute_VIEW, username: username, domain: domain)

  if stat != 'STAT_SUCCESS'
    raise Identikey::NotFound, "Find user failed: #{stat} - #{error}"
  end

  replace(user, persisted: true)
end

#persisted?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/identikey/administration/user.rb', line 88

def persisted?
  @persisted || false
end

#reloadObject



92
93
94
# File 'lib/identikey/administration/user.rb', line 92

def reload
  find(self.username, self.domain)
end

#save!Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/identikey/administration/user.rb', line 96

def save!
  method = persisted? ? :user_execute_UPDATE : :user_execute_CREATE

  stat, user, error = @session.execute(method, attributes: {
    USERFLD_BACKEND_AUTH:        self.backend_auth,
    USERFLD_DISABLED:            self.disabled,
    USERFLD_DOMAIN:              self.domain,
    USERFLD_EMAIL:               self.email,
    USERFLD_LOCAL_AUTH:          self.local_auth,
    USERFLD_LOCKED:              self.locked,
    USERFLD_MOBILE:              self.mobile,
    USERFLD_ORGANIZATIONAL_UNIT: self.ou,
    USERFLD_PHONE:               self.phone,
    USERFLD_USERID:              self.username
  })

  if stat != 'STAT_SUCCESS'
    raise Identikey::OperationFailed, "Save user #{self.username} failed: #{stat} - #{error}"
  end

  replace(user, persisted: true)
end

#set_local_auth!(value) ⇒ Object



164
165
166
167
168
169
170
171
172
# File 'lib/identikey/administration/user.rb', line 164

def set_local_auth!(value)
  ensure_persisted!

  self.local_auth = value

  self.save!

  self
end

#set_password!(password) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/identikey/administration/user.rb', line 149

def set_password!(password)
  ensure_persisted!

  stat, _, error = @session.execute(
    :user_execute_SET_PASSWORD, username: username, domain: domain, password: password)

  if stat != 'STAT_SUCCESS'
    raise Identikey::OperationFailed, "Set user #{self.username} password failed: #{stat} - #{error}"
  end

  self.has_password = true

  true
end

#unlock!Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/identikey/administration/user.rb', line 174

def unlock!
  ensure_persisted!

  stat, _, error = @session.execute(
    :user_execute_UNLOCK, username: username, domain: domain)

  if stat != 'STAT_SUCCESS'
    raise Identikey::OperationFailed, "Unlock user #{self.username} failed: #{stat} - #{error}"
  end

  self.locked = false

  true
end