Class: VacmanController::Token
- Inherits:
-
Object
- Object
- VacmanController::Token
- Defined in:
- lib/vacman_controller/token.rb,
lib/vacman_controller/token/properties.rb
Defined Under Namespace
Classes: Properties
Class Method Summary collapse
-
.import(dpx_filename, transport_key) ⇒ Object
Opens the given dpx_filename with the given transport key and, if successful, returns Token instances for all tokens in the DPX file.
Instance Method Summary collapse
-
#app_name ⇒ Object
Returns the token Application Name.
-
#disable! ⇒ Object
Sets the “disabled” token status.
-
#disable_pin! ⇒ Object
Disables the PIN on this token.
-
#enable! ⇒ Object
Set both primary and backup application enabled status.
-
#enable_backup_only! ⇒ Object
Set the backup application enabled status.
-
#enable_pin! ⇒ Object
Enables the PIN on this token.
-
#enable_primary_only! ⇒ Object
Set the primary application enabled status.
-
#force_pin_change! ⇒ Object
Forces PIN change on this token.
-
#generate ⇒ Object
Generate an OTPfrom this token.
-
#initialize(token_hash) ⇒ Token
constructor
Initialises a Token instance with the given token hash.
-
#inspect ⇒ Object
Renders this token in your development console and in your logs (possibly).
-
#properties ⇒ Object
Returns a
Token::Propertiesobject giving low-level access to the token properties. -
#reset_error_count! ⇒ Object
Resets the token error count.
-
#serial ⇒ Object
Return the token serial number.
-
#set_pin(pin) ⇒ Object
Set this token’s PIN.
-
#to_h ⇒ Object
Returns the token as an hash, that is suitable for passing to the low-level functions, or for persistance purposes.
-
#verify(otp) ⇒ Object
Verify a password.
-
#verify!(otp) ⇒ Object
Same as verify, but raises a VacmanController::Error if OTP verification fails.
Constructor Details
#initialize(token_hash) ⇒ Token
Initialises a Token instance with the given token hash.
19 20 21 |
# File 'lib/vacman_controller/token.rb', line 19 def initialize(token_hash) @token_hash = token_hash end |
Class Method Details
.import(dpx_filename, transport_key) ⇒ Object
Opens the given dpx_filename with the given transport key and, if successful, returns Token instances for all tokens in the DPX file.
10 11 12 13 14 |
# File 'lib/vacman_controller/token.rb', line 10 def self.import(dpx_filename, transport_key) VacmanController.import(dpx_filename, transport_key).map do |hash| Token.new(hash) end end |
Instance Method Details
#app_name ⇒ Object
Returns the token Application Name
33 34 35 |
# File 'lib/vacman_controller/token.rb', line 33 def app_name @token_hash.fetch('app_name').dup end |
#disable! ⇒ Object
Sets the “disabled” token status
144 145 146 147 |
# File 'lib/vacman_controller/token.rb', line 144 def disable! properties[:token_status] = :disabled true end |
#disable_pin! ⇒ Object
Disables the PIN on this token
120 121 122 123 |
# File 'lib/vacman_controller/token.rb', line 120 def disable_pin! properties[:pin_enabled] = false true end |
#enable! ⇒ Object
Set both primary and backup application enabled status
168 169 170 171 |
# File 'lib/vacman_controller/token.rb', line 168 def enable! properties[:token_status] = :enabled true end |
#enable_backup_only! ⇒ Object
Set the backup application enabled status
160 161 162 163 |
# File 'lib/vacman_controller/token.rb', line 160 def enable_backup_only! properties[:token_status] = :backup_only true end |
#enable_pin! ⇒ Object
Enables the PIN on this token
112 113 114 115 |
# File 'lib/vacman_controller/token.rb', line 112 def enable_pin! properties[:pin_enabled] = true true end |
#enable_primary_only! ⇒ Object
Set the primary application enabled status
152 153 154 155 |
# File 'lib/vacman_controller/token.rb', line 152 def enable_primary_only! properties[:token_status] = :primary_only true end |
#force_pin_change! ⇒ Object
Forces PIN change on this token
128 129 130 131 |
# File 'lib/vacman_controller/token.rb', line 128 def force_pin_change! properties[:pin_change_forced] = true true end |
#generate ⇒ Object
Generate an OTPfrom this token. This does the same as hitting the button on the hardware token.
Returns:
The OTP as a String. The OTP is only valid for a limited time period.
Not all tokens support OTP generation.
90 91 92 |
# File 'lib/vacman_controller/token.rb', line 90 def generate VacmanController::LowLevel.generate_password(@token_hash) end |
#inspect ⇒ Object
Renders this token in your development console and in your logs (possibly)
41 42 43 |
# File 'lib/vacman_controller/token.rb', line 41 def inspect "#<#{self.class.name} serial=#{serial.inspect} app_name=#{app_name.inspect}>" end |
#properties ⇒ Object
Returns a Token::Properties object giving low-level access to the token properties.
177 178 179 |
# File 'lib/vacman_controller/token.rb', line 177 def properties @_properties = VacmanController::Token::Properties.new(self) end |
#reset_error_count! ⇒ Object
Resets the token error count
136 137 138 139 |
# File 'lib/vacman_controller/token.rb', line 136 def reset_error_count! properties[:error_count] = 0 true end |
#serial ⇒ Object
Return the token serial number
26 27 28 |
# File 'lib/vacman_controller/token.rb', line 26 def serial @token_hash.fetch('serial').dup end |
#set_pin(pin) ⇒ Object
Set this token’s PIN
Parameters:
- pin
-
the new PIN. Must be coercible to String.
101 102 103 |
# File 'lib/vacman_controller/token.rb', line 101 def set_pin(pin) VacmanController::LowLevel.set_token_pin(@token_hash, pin.to_s) end |
#to_h ⇒ Object
Returns the token as an hash, that is suitable for passing to the low-level functions, or for persistance purposes.
49 50 51 |
# File 'lib/vacman_controller/token.rb', line 49 def to_h @token_hash end |
#verify(otp) ⇒ Object
Verify a password. This is the usecase a user sends you an OTP generated by their token and we have to verify it.
Parameters:
- otp
-
The OTP provided by the user
Returns:
true if the password is valid, false otherwise
ATTENTION: it is very important to persist the token hash afterwards.
67 68 69 70 71 |
# File 'lib/vacman_controller/token.rb', line 67 def verify(otp) verify!(otp) rescue VacmanController::Error false end |
#verify!(otp) ⇒ Object
Same as verify, but raises a VacmanController::Error if OTP verification fails.
77 78 79 |
# File 'lib/vacman_controller/token.rb', line 77 def verify!(otp) VacmanController::LowLevel.verify_password(@token_hash, otp.to_s) end |