Class: Identikey::Administration::Session
- Inherits:
-
Object
- Object
- Identikey::Administration::Session
- Defined in:
- lib/identikey/administration/session.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#privileges ⇒ Object
readonly
Returns the value of attribute privileges.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#session_id ⇒ Object
(also: #sid)
readonly
Returns the value of attribute session_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #alive?(log: true) ⇒ Boolean
- #all ⇒ Object
- #endpoint ⇒ Object
- #execute(command, *args) ⇒ Object
- #find_digipass(serial_no) ⇒ Object
- #find_user(username, domain = nil) ⇒ Object
-
#initialize(username:, password: nil, apikey: nil, domain: 'master') ⇒ Session
constructor
A new instance of Session.
- #inspect ⇒ Object
- #logged_on? ⇒ Boolean
- #logoff ⇒ Object
- #logon ⇒ Object
- #parse_privileges(privileges) ⇒ Object
- #require_classic_user! ⇒ Object
- #require_logged_on! ⇒ Object
- #search_digipasses(query) ⇒ Object
- #search_users(query) ⇒ Object
- #service_user? ⇒ Boolean
- #wsdl ⇒ Object
Constructor Details
#initialize(username:, password: nil, apikey: nil, domain: 'master') ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/identikey/administration/session.rb', line 9 def initialize(username:, password: nil, apikey: nil, domain: 'master') if password.nil? && apikey.nil? raise Identikey::UsageError, "Either a password or an API Key is required" end @client = Identikey::Administration.new @username = username @password = password @domain = domain if apikey @service_user = true @session_id = "Apikey #{username}:#{apikey}" end end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
5 6 7 |
# File 'lib/identikey/administration/session.rb', line 5 def domain @domain end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
7 8 9 |
# File 'lib/identikey/administration/session.rb', line 7 def location @location end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
5 6 7 |
# File 'lib/identikey/administration/session.rb', line 5 def password @password end |
#privileges ⇒ Object (readonly)
Returns the value of attribute privileges.
7 8 9 |
# File 'lib/identikey/administration/session.rb', line 7 def privileges @privileges end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
6 7 8 |
# File 'lib/identikey/administration/session.rb', line 6 def product @product end |
#session_id ⇒ Object (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 |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/identikey/administration/session.rb', line 5 def username @username end |
#version ⇒ Object (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?(log: true) ⇒ Boolean
74 75 76 77 78 79 80 81 82 |
# File 'lib/identikey/administration/session.rb', line 74 def alive?(log: true) require_classic_user! return false unless logged_on? stat, _ = @client.ping session_id: @session_id, log: log stat == 'STAT_SUCCESS' end |
#all ⇒ Object
90 91 92 93 94 |
# File 'lib/identikey/administration/session.rb', line 90 def all require_logged_on! SessionQuery.all session: self end |
#endpoint ⇒ Object
26 27 28 |
# File 'lib/identikey/administration/session.rb', line 26 def endpoint @client.endpoint end |
#execute(command, *args) ⇒ Object
84 85 86 87 88 |
# File 'lib/identikey/administration/session.rb', line 84 def execute(command, *args) kwargs = args.first || {} kwargs.update(session_id: @session_id) @client.public_send(command, kwargs) end |
#find_digipass(serial_no) ⇒ Object
96 97 98 99 100 |
# File 'lib/identikey/administration/session.rb', line 96 def find_digipass(serial_no) require_logged_on! Digipass.find session: self, serial_no: serial_no end |
#find_user(username, domain = nil) ⇒ Object
110 111 112 113 114 |
# File 'lib/identikey/administration/session.rb', line 110 def find_user(username, domain = nil) require_logged_on! User.find session: self, username: username, domain: domain || self.domain end |
#inspect ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/identikey/administration/session.rb', line 124 def inspect descr = if service_user? "SERVICE USER" else "domain=#@domain product=#@product" end "#<#{self.class.name} sid=#@session_id username=#@username #{descr}>" end |
#logged_on? ⇒ Boolean
140 141 142 |
# File 'lib/identikey/administration/session.rb', line 140 def logged_on? !@session_id.nil? end |
#logoff ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/identikey/administration/session.rb', line 55 def logoff require_classic_user! 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 |
#logon ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/identikey/administration/session.rb', line 34 def logon require_classic_user! 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
156 157 158 159 160 161 |
# File 'lib/identikey/administration/session.rb', line 156 def parse_privileges(privileges) privileges.split(', ').inject({}) do |h, priv| privilege, status = priv.split(' ') h.update(privilege => status == 'true') end.freeze end |
#require_classic_user! ⇒ Object
150 151 152 153 154 |
# File 'lib/identikey/administration/session.rb', line 150 def require_classic_user! if service_user? raise Identikey::UsageError, "This command is not supported with Service users" end end |
#require_logged_on! ⇒ Object
144 145 146 147 148 |
# File 'lib/identikey/administration/session.rb', line 144 def require_logged_on! unless logged_on? raise Identikey::UsageError, "Session is not logged on at the moment" end end |
#search_digipasses(query) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/identikey/administration/session.rb', line 102 def search_digipasses(query) require_logged_on! = query.delete(:options) || {} Digipass.search session: self, query: query, options: end |
#search_users(query) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/identikey/administration/session.rb', line 116 def search_users(query) require_logged_on! = query.delete(:options) || {} User.search session: self, query: query, options: end |
#service_user? ⇒ Boolean
134 135 136 |
# File 'lib/identikey/administration/session.rb', line 134 def service_user? !!@service_user end |
#wsdl ⇒ Object
30 31 32 |
# File 'lib/identikey/administration/session.rb', line 30 def wsdl @client.wsdl end |