Class: Identikey::Administration::Session

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:, domain: 'master') ⇒ Session

Returns a new instance of Session.



9
10
11
12
13
14
15
# File 'lib/identikey/administration/session.rb', line 9

def initialize(username:, password:, domain: 'master')
  @client = Identikey::Administration.new

  @username = username
  @password = password
  @domain   = domain
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#locationObject (readonly)

Returns the value of attribute location.



7
8
9
# File 'lib/identikey/administration/session.rb', line 7

def location
  @location
end

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#privilegesObject (readonly)

Returns the value of attribute privileges.



7
8
9
# File 'lib/identikey/administration/session.rb', line 7

def privileges
  @privileges
end

#productObject (readonly)

Returns the value of attribute product.



6
7
8
# File 'lib/identikey/administration/session.rb', line 6

def product
  @product
end

#session_idObject (readonly) Also known as: sid

Returns the value of attribute session_id.



6
7
8
# File 'lib/identikey/administration/session.rb', line 6

def session_id
  @session_id
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/identikey/administration/session.rb', line 6

def version
  @version
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'lib/identikey/administration/session.rb', line 62

def alive?
  return false unless logged_on?

  stat, _ = @client.sessionalive session_id: @session_id

  stat == 'STAT_SUCCESS'
end

#allObject



76
77
78
79
80
# File 'lib/identikey/administration/session.rb', line 76

def all
  require_logged_on!

  SessionQuery.all session: self
end

#endpointObject



17
18
19
# File 'lib/identikey/administration/session.rb', line 17

def endpoint
  @client.endpoint
end

#execute(command, *args) ⇒ Object



70
71
72
73
74
# File 'lib/identikey/administration/session.rb', line 70

def execute(command, *args)
  kwargs = args.first || {}
  kwargs.update(session_id: @session_id)
  @client.public_send(command, kwargs)
end

#find_digipass(serial_no) ⇒ Object



82
83
84
85
86
# File 'lib/identikey/administration/session.rb', line 82

def find_digipass(serial_no)
  require_logged_on!

  Digipass.find session: self, serial_no: serial_no
end

#find_user(username, domain = nil) ⇒ Object



88
89
90
91
92
# File 'lib/identikey/administration/session.rb', line 88

def find_user(username, domain = nil)
  require_logged_on!

  User.find session: self, username: username, domain: domain || self.domain
end

#inspectObject



94
95
96
# File 'lib/identikey/administration/session.rb', line 94

def inspect
  "#<#{self.class.name} sid=#@session_id username=#@username domain=#@domain product=#@product>"
end

#logged_on?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/identikey/administration/session.rb', line 100

def logged_on?
  !@session_id.nil?
end

#logoffObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/identikey/administration/session.rb', line 44

def logoff
  require_logged_on!

  stat, _, error = @client.logoff session_id: @session_id

  unless stat == 'STAT_ADMIN_SESSION_STOPPED' || stat == 'STAT_SUCCESS'
    raise Identikey::LogonFailed, "logoff failed: #{stat} - #{error}"
  end

  @privileges = nil
  @session_id = nil
  @product    = nil
  @version    = nil
  @last_logon = nil

  stat == 'STAT_SUCCESS'
end

#logonObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/identikey/administration/session.rb', line 25

def logon
  stat, sess, error = @client.logon(username: @username, password: @password, domain: @domain)

  if stat != 'STAT_SUCCESS'
    raise Identikey::LogonFailed, "logon failed: #{stat} - #{error}"
  end

  @privileges = parse_privileges sess['CREDFLD_LOGICAL_ADMIN_PRIVILEGES']

  @session_id = sess['CREDFLD_SESSION_ID'].freeze
  @location   = sess['CREDFLD_USER_LOCATION'].freeze
  @last_logon = sess['CREDFLD_LAST_LOGON_TIME'].freeze

  @product    = sess['CREDFLD_PRODUCT_NAME'].freeze
  @version    = sess['CREDFLD_PRODUCT_VERSION'].freeze

  self
end

#parse_privileges(privileges) ⇒ Object



110
111
112
113
114
115
# File 'lib/identikey/administration/session.rb', line 110

def parse_privileges(privileges)
  privileges.split(', ').inject({}) do |h, priv|
    privilege, status = priv.split(' ')
    h.update(privilege => status == 'true')
  end.freeze
end

#require_logged_on!Object



104
105
106
107
108
# File 'lib/identikey/administration/session.rb', line 104

def require_logged_on!
  unless logged_on?
    raise Identikey::UsageError, "Session is not logged on at the moment"
  end
end

#wsdlObject



21
22
23
# File 'lib/identikey/administration/session.rb', line 21

def wsdl
  @client.wsdl
end