Class: Identikey::Administration::Digipass
- Inherits:
-
Object
- Object
- Identikey::Administration::Digipass
- Defined in:
- lib/identikey/administration/digipass.rb
Class Method Summary collapse
Instance Method Summary collapse
- #applications ⇒ Object
- #assign!(username, domain) ⇒ Object
- #assigned? ⇒ Boolean
- #default_application! ⇒ Object
- #find(serial_no) ⇒ Object
-
#initialize(session, digipass = nil) ⇒ Digipass
constructor
A new instance of Digipass.
- #method_missing(name, *args, &block) ⇒ Object
- #reload ⇒ Object
- #replace(digipass) ⇒ Object
- #set_pin(pin, application: nil) ⇒ Object
- #test_otp(otp, application: nil) ⇒ Object
- #unassign! ⇒ Object
Constructor Details
#initialize(session, digipass = nil) ⇒ Digipass
Returns a new instance of Digipass.
39 40 41 42 43 |
# File 'lib/identikey/administration/digipass.rb', line 39 def initialize(session, digipass = nil) @session = session replace(digipass) if digipass end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/identikey/administration/digipass.rb', line 152 def method_missing(name, *args, &block) if @attributes.key?(name) @attributes.fetch(name) else super(name, *args, &block) end end |
Class Method Details
.find(session:, serial_no:) ⇒ Object
5 6 7 |
# File 'lib/identikey/administration/digipass.rb', line 5 def self.find(session:, serial_no:) new(session).find(serial_no) end |
.search(session:, query:, options: {}) ⇒ 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 |
# File 'lib/identikey/administration/digipass.rb', line 9 def self.search(session:, query:, options: {}) query_keys = { 'applications' => 'DIGIPASSFLD_ACTIVE_APPL_NAMES', 'app_types' => 'DIGIPASSFLD_ACTIVE_APPL_TYPES', 'status' => 'DIGIPASSFLD_ASSIGN_STATUS', 'user_org_unit' => 'DIGIPASSFLD_ASSIGNED_USER_ORG_UNIT', 'username' => 'DIGIPASSFLD_ASSIGNED_USERID', 'device_id' => 'DIGIPASSFLD_DEVICE_ID', 'direct' => 'DIGIPASSFLD_DIRECT_ASSIGN_ONLY', 'domain' => 'DIGIPASSFLD_DOMAIN', 'type' => 'DIGIPASSFLD_DPTYPE', 'expired' => 'DIGIPASSFLD_EXPIRED', 'grace_expired' => 'DIGIPASSFLD_GRACE_PERIOD_EXPIRED', 'license_serial' => 'DIGIPASSFLD_LICENSE_SERNO', 'org_unit' => 'DIGIPASSFLD_ORGANIZATIONAL_UNIT', 'serial' => 'DIGIPASSFLD_SERNO' } stat, digipasses, error = session.execute(:digipass_query, attributes: Base.search_attributes_from(query, attribute_map: query_keys), query_options: Base.()) case stat when 'STAT_SUCCESS' then (digipasses||[]).map {|user| new(session, user) } when 'STAT_NOT_FOUND' then [] else raise Identikey::Error, "Search digipass failed: #{stat} - #{error}" end end |
Instance Method Details
#applications ⇒ Object
148 149 150 |
# File 'lib/identikey/administration/digipass.rb', line 148 def applications @_applications ||= @attributes.fetch(:application).split(',') end |
#assign!(username, domain) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/identikey/administration/digipass.rb', line 99 def assign!(username, domain) stat, digipass, error = @session.execute( :digipass_execute_ASSIGN, serial_no: self.serial, username: username, domain: domain) if stat != 'STAT_SUCCESS' raise Identikey::OperationFailed, "Unassign digipass failed: #{stat} - #{error}" end replace(digipass) end |
#assigned? ⇒ Boolean
69 70 71 |
# File 'lib/identikey/administration/digipass.rb', line 69 def assigned? self.status == 'Assigned' end |
#default_application! ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/identikey/administration/digipass.rb', line 138 def default_application! if self.applications.size == 1 self.applications.first else raise Identikey::UsageError, "Digipass #{self.serial} has more than one application. " \ "Please specify which one to use out of #{applications.join(', ')}" end end |
#find(serial_no) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/identikey/administration/digipass.rb', line 73 def find(serial_no) stat, digipass, error = @session.execute( :digipass_execute_VIEW, serial_no: serial_no) if stat != 'STAT_SUCCESS' raise Identikey::NotFound, "Find digipass failed: #{stat} - #{error}" end replace(digipass) end |
#reload ⇒ Object
84 85 86 |
# File 'lib/identikey/administration/digipass.rb', line 84 def reload find(self.serial) end |
#replace(digipass) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/identikey/administration/digipass.rb', line 45 def replace(digipass) @attributes = { serial: digipass['DIGIPASSFLD_SERNO'], domain: digipass['DIGIPASSFLD_DOMAIN'], ou: digipass['DIGIPASSFLD_ORGANIZATIONAL_UNIT'], type: digipass['DIGIPASSFLD_DPTYPE'], application: digipass['DIGIPASSFLD_ACTIVE_APPL_NAMES'], status: digipass['DIGIPASSFLD_ASSIGN_STATUS'], userid: digipass['DIGIPASSFLD_ASSIGNED_USERID'], assigned_at: digipass['DIGIPASSFLD_ASSIGNED_DATE'], grace_expires_at: digipass['DIGIPASSFLD_GRACE_PERIOD_EXPIRES'], created_at: digipass['DIGIPASSFLD_CREATE_TIME'], updated_at: digipass['DIGIPASSFLD_MODIFY_TIME'], activation_count: digipass['DIGIPASSFLD_ACTIV_COUNT'], last_activation_at: digipass['DIGIPASSFLD_LAST_ACTIV_TIME'], bind_status: digipass['DIGIPASSFLD_BIND_STATUS'], max_activations: digipass['DIGIPASSFLD_MAX_ACTIVATIONS'], expired: digipass['DIGIPASSFLD_EXPIRED'], grace_expired: digipass['DIGIPASSFLD_GRACE_PERIOD_EXPIRED'] }.freeze self end |
#set_pin(pin, application: nil) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/identikey/administration/digipass.rb', line 125 def set_pin(pin, application: nil) application ||= self.default_application! stat, _, error = @session.execute( :digipassappl_execute_SET_PIN, serial_no: self.serial, appl: application, pin: pin) if stat != 'STAT_SUCCESS' raise Identikey::OperationFailed, "Set PIN failed: #{stat} - #{error}" end true end |
#test_otp(otp, application: nil) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/identikey/administration/digipass.rb', line 110 def test_otp(otp, application: nil) application ||= self.default_application! stat, appl, error = @session.execute( :digipassappl_execute_TEST_OTP, serial_no: self.serial, appl: application, otp: otp) # Stat is useless here - it reports whether the call or not has # succeeded, not whether the OTP is valid if stat != 'STAT_SUCCESS' raise Identikey::OperationFailed, "Test OTP failed: #{stat} - #{error}" end appl['DIGIPASSAPPLFLD_RESULT_CODE'] == '0' end |
#unassign! ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/identikey/administration/digipass.rb', line 88 def unassign! stat, digipass, error = @session.execute( :digipass_execute_UNASSIGN, serial_no: self.serial) if stat != 'STAT_SUCCESS' raise Identikey::OperationFailed, "Assign digipass failed: #{stat} - #{error}" end replace(digipass) end |