gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
OtpExternalAuthenticator.PersonAuthentication クラス
OtpExternalAuthenticator.PersonAuthentication の継承関係図
Inheritance graph
OtpExternalAuthenticator.PersonAuthentication 連携図
Collaboration graph

公開メンバ関数

def __init__ (self, currentTimeMillis)
 
def init (self, configurationAttributes)
 
def destroy (self, configurationAttributes)
 
def getApiVersion (self)
 
def isValidAuthenticationMethod (self, usageType, configurationAttributes)
 
def getAlternativeAuthenticationMethod (self, usageType, configurationAttributes)
 
def authenticate (self, configurationAttributes, requestParameters, step)
 
def prepareForStep (self, configurationAttributes, requestParameters, step)
 
def getExtraParametersForStep (self, configurationAttributes, step)
 
def getCountAuthenticationSteps (self, configurationAttributes)
 
def getPageForStep (self, configurationAttributes, step)
 
def logout (self, configurationAttributes, requestParameters)
 
def setRequestScopedParameters (self, identity)
 
def loadOtpConfiguration (self, configurationAttributes)
 
def processBasicAuthentication (self, credentials)
 
def findEnrollments (self, user_name, skipPrefix=True)
 
def validateSessionId (self, identity)
 
def processOtpAuthentication (self, requestParameters, user_name, identity, otp_auth_method)
 
def generateSecretKey (self, keyLength)
 
def generateSecretHotpKey (self)
 
def generateHotpKey (self, secretKey, movingFactor)
 
def validateHotpKey (self, secretKey, movingFactor, totpKey)
 
def generateHotpSecretKeyUri (self, secretKey, issuer, userDisplayName)
 
def generateSecretTotpKey (self)
 
def generateTotpKey (self, secretKey)
 
def validateTotpKey (self, secretKey, totpKey)
 
def generateTotpSecretKeyUri (self, secretKey, issuer, userDisplayName)
 
def toBase32 (self, bytes)
 
def toBase64Url (self, bytes)
 
def fromBase64Url (self, chars)
 

公開変数類

 currentTimeMillis
 
 otpType
 
 otpIssuer
 
 customLabel
 
 customQrOptions
 
 registrationUri
 
 hotpConfiguration
 
 totpConfiguration
 

詳解

構築子と解体子

◆ __init__()

def OtpExternalAuthenticator.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
42  def __init__(self, currentTimeMillis):
43  self.currentTimeMillis = currentTimeMillis
44 

関数詳解

◆ authenticate()

def OtpExternalAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
95  def authenticate(self, configurationAttributes, requestParameters, step):
96  authenticationService = CdiUtil.bean(AuthenticationService)
97 
98  identity = CdiUtil.bean(Identity)
99  credentials = identity.getCredentials()
100 
101  self.setRequestScopedParameters(identity)
102 
103  if step == 1:
104  print "OTP. Authenticate for step 1"
105  authenticated_user = self.processBasicAuthentication(credentials)
106  if authenticated_user == None:
107  return False
108 
109  otp_auth_method = "authenticate"
110  # Uncomment this block if you need to allow user second OTP registration
111  #enrollment_mode = ServerUtil.getFirstValue(requestParameters, "loginForm:registerButton")
112  #if StringHelper.isNotEmpty(enrollment_mode):
113  # otp_auth_method = "enroll"
114 
115  if otp_auth_method == "authenticate":
116  user_enrollments = self.findEnrollments(authenticated_user.getUserId())
117  if len(user_enrollments) == 0:
118  otp_auth_method = "enroll"
119  print "OTP. Authenticate for step 1. There is no OTP enrollment for user '%s'. Changing otp_auth_method to '%s'" % (authenticated_user.getUserId(), otp_auth_method)
120 
121  if otp_auth_method == "enroll":
122  print "OTP. Authenticate for step 1. Setting count steps: '%s'" % 3
123  identity.setWorkingParameter("otp_count_login_steps", 3)
124 
125  print "OTP. Authenticate for step 1. otp_auth_method: '%s'" % otp_auth_method
126  identity.setWorkingParameter("otp_auth_method", otp_auth_method)
127 
128  return True
129  elif step == 2:
130  print "OTP. Authenticate for step 2"
131 
132  authenticationService = CdiUtil.bean(AuthenticationService)
133  user = authenticationService.getAuthenticatedUser()
134  if user == None:
135  print "OTP. Authenticate for step 2. Failed to determine user name"
136  return False
137 
138  session_id_validation = self.validateSessionId(identity)
139  if not session_id_validation:
140  return False
141 
142  # Restore state from session
143  otp_auth_method = identity.getWorkingParameter("otp_auth_method")
144  if otp_auth_method == 'enroll':
145  auth_result = ServerUtil.getFirstValue(requestParameters, "auth_result")
146  if not StringHelper.isEmpty(auth_result):
147  print "OTP. Authenticate for step 2. User not enrolled OTP"
148  return False
149 
150  print "OTP. Authenticate for step 2. Skipping this step during enrollment"
151  return True
152 
153  otp_auth_result = self.processOtpAuthentication(requestParameters, user.getUserId(), identity, otp_auth_method)
154  print "OTP. Authenticate for step 2. OTP authentication result: '%s'" % otp_auth_result
155 
156  return otp_auth_result
157  elif step == 3:
158  print "OTP. Authenticate for step 3"
159 
160  authenticationService = CdiUtil.bean(AuthenticationService)
161  user = authenticationService.getAuthenticatedUser()
162  if user == None:
163  print "OTP. Authenticate for step 2. Failed to determine user name"
164  return False
165 
166  session_id_validation = self.validateSessionId(identity)
167  if not session_id_validation:
168  return False
169 
170  # Restore state from session
171  otp_auth_method = identity.getWorkingParameter("otp_auth_method")
172  if otp_auth_method != 'enroll':
173  return False
174 
175  otp_auth_result = self.processOtpAuthentication(requestParameters, user.getUserId(), identity, otp_auth_method)
176  print "OTP. Authenticate for step 3. OTP authentication result: '%s'" % otp_auth_result
177 
178  return otp_auth_result
179  else:
180  return False
181 

◆ destroy()

def OtpExternalAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
81  def destroy(self, configurationAttributes):
82  print "OTP. Destroy"
83  print "OTP. Destroyed successfully"
84  return True
85 

◆ findEnrollments()

def OtpExternalAuthenticator.PersonAuthentication.findEnrollments (   self,
  user_name,
  skipPrefix = True 
)
341  def findEnrollments(self, user_name, skipPrefix = True):
342  result = []
343 
344  userService = CdiUtil.bean(UserService)
345  user = userService.getUser(user_name, "oxExternalUid")
346  if user == None:
347  print "OTP. Find enrollments. Failed to find user"
348  return result
349 
350  user_custom_ext_attribute = userService.getCustomAttribute(user, "oxExternalUid")
351  if user_custom_ext_attribute == None:
352  return result
353 
354  otp_prefix = "%s:" % self.otpType
355 
356  otp_prefix_length = len(otp_prefix)
357  for user_external_uid in user_custom_ext_attribute.getValues():
358  index = user_external_uid.find(otp_prefix)
359  if index != -1:
360  if skipPrefix:
361  enrollment_uid = user_external_uid[otp_prefix_length:]
362  else:
363  enrollment_uid = user_external_uid
364 
365  result.append(enrollment_uid)
366 
367  return result
368 

◆ fromBase64Url()

def OtpExternalAuthenticator.PersonAuthentication.fromBase64Url (   self,
  chars 
)
559  def fromBase64Url(self, chars):
560  return BaseEncoding.base64Url().decode(chars)
561 

◆ generateHotpKey()

def OtpExternalAuthenticator.PersonAuthentication.generateHotpKey (   self,
  secretKey,
  movingFactor 
)
490  def generateHotpKey(self, secretKey, movingFactor):
491  digits = self.hotpConfiguration["digits"]
492 
493  hotp = HOTP.key(secretKey).digits(digits).movingFactor(movingFactor).build()
494 
495  return hotp.value()
496 

◆ generateHotpSecretKeyUri()

def OtpExternalAuthenticator.PersonAuthentication.generateHotpSecretKeyUri (   self,
  secretKey,
  issuer,
  userDisplayName 
)
507  def generateHotpSecretKeyUri(self, secretKey, issuer, userDisplayName):
508  digits = self.hotpConfiguration["digits"]
509 
510  secretKeyBase32 = self.toBase32(secretKey)
511  otpKey = OTPKey(secretKeyBase32, OTPType.HOTP)
512  label = issuer + " %s" % userDisplayName
513 
514  otpAuthURI = OTPAuthURIBuilder.fromKey(otpKey).label(label).issuer(issuer).digits(digits).build()
515 
516  return otpAuthURI.toUriString()
517 

◆ generateSecretHotpKey()

def OtpExternalAuthenticator.PersonAuthentication.generateSecretHotpKey (   self)
485  def generateSecretHotpKey(self):
486  keyLength = self.hotpConfiguration["keyLength"]
487 
488  return self.generateSecretKey(keyLength)
489 

◆ generateSecretKey()

def OtpExternalAuthenticator.PersonAuthentication.generateSecretKey (   self,
  keyLength 
)
477  def generateSecretKey(self, keyLength):
478  bytes = jarray.zeros(keyLength, "b")
479  secureRandom = SecureRandom()
480  secureRandom.nextBytes(bytes)
481 
482  return bytes
483 

◆ generateSecretTotpKey()

def OtpExternalAuthenticator.PersonAuthentication.generateSecretTotpKey (   self)
519  def generateSecretTotpKey(self):
520  keyLength = self.totpConfiguration["keyLength"]
521 
522  return self.generateSecretKey(keyLength)
523 

◆ generateTotpKey()

def OtpExternalAuthenticator.PersonAuthentication.generateTotpKey (   self,
  secretKey 
)
524  def generateTotpKey(self, secretKey):
525  digits = self.totpConfiguration["digits"]
526  timeStep = self.totpConfiguration["timeStep"]
527  hmacShaAlgorithmType = self.totpConfiguration["hmacShaAlgorithmType"]
528 
529  totp = TOTP.key(secretKey).digits(digits).timeStep(TimeUnit.SECONDS.toMillis(timeStep)).hmacSha(hmacShaAlgorithmType).build()
530 
531  return totp.value()
532 

◆ generateTotpSecretKeyUri()

def OtpExternalAuthenticator.PersonAuthentication.generateTotpSecretKeyUri (   self,
  secretKey,
  issuer,
  userDisplayName 
)
540  def generateTotpSecretKeyUri(self, secretKey, issuer, userDisplayName):
541  digits = self.totpConfiguration["digits"]
542  timeStep = self.totpConfiguration["timeStep"]
543 
544  secretKeyBase32 = self.toBase32(secretKey)
545  otpKey = OTPKey(secretKeyBase32, OTPType.TOTP)
546  label = issuer + " %s" % userDisplayName
547 
548  otpAuthURI = OTPAuthURIBuilder.fromKey(otpKey).label(label).issuer(issuer).digits(digits).timeStep(TimeUnit.SECONDS.toMillis(timeStep)).build()
549 
550  return otpAuthURI.toUriString()
551 

◆ getAlternativeAuthenticationMethod()

def OtpExternalAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
92  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
93  return None
94 

◆ getApiVersion()

def OtpExternalAuthenticator.PersonAuthentication.getApiVersion (   self)
86  def getApiVersion(self):
87  return 1
88 

◆ getCountAuthenticationSteps()

def OtpExternalAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
242  def getCountAuthenticationSteps(self, configurationAttributes):
243  identity = CdiUtil.bean(Identity)
244 
245  if identity.isSetWorkingParameter("otp_count_login_steps"):
246  return StringHelper.toInteger("%s" % identity.getWorkingParameter("otp_count_login_steps"))
247  else:
248  return 2
249 

◆ getExtraParametersForStep()

def OtpExternalAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
239  def getExtraParametersForStep(self, configurationAttributes, step):
240  return Arrays.asList("otp_auth_method", "otp_count_login_steps", "otp_secret_key", "otp_enrollment_request")
241 

◆ getPageForStep()

def OtpExternalAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
250  def getPageForStep(self, configurationAttributes, step):
251  if step == 2:
252  identity = CdiUtil.bean(Identity)
253 
254  otp_auth_method = identity.getWorkingParameter("otp_auth_method")
255  print "OTP. Gep page for step 2. otp_auth_method: '%s'" % otp_auth_method
256 
257  if otp_auth_method == 'enroll':
258  return "/auth/otp/enroll.xhtml"
259  else:
260  return "/auth/otp/otplogin.xhtml"
261  elif step == 3:
262  return "/auth/otp/otplogin.xhtml"
263 
264  return ""
265 

◆ init()

def OtpExternalAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
45  def init(self, configurationAttributes):
46  print "OTP. Initialization"
47 
48  if not configurationAttributes.containsKey("otp_type"):
49  print "OTP. Initialization. Property otp_type is mandatory"
50  return False
51  self.otpType = configurationAttributes.get("otp_type").getValue2()
52 
53  if not self.otpType in ["hotp", "totp"]:
54  print "OTP. Initialization. Property value otp_type is invalid"
55  return False
56 
57  if not configurationAttributes.containsKey("issuer"):
58  print "OTP. Initialization. Property issuer is mandatory"
59  return False
60  self.otpIssuer = configurationAttributes.get("issuer").getValue2()
61 
62  self.customLabel = None
63  if configurationAttributes.containsKey("label"):
64  self.customLabel = configurationAttributes.get("label").getValue2()
65 
66  self.customQrOptions = {}
67  if configurationAttributes.containsKey("qr_options"):
68  self.customQrOptions = configurationAttributes.get("qr_options").getValue2()
69 
70  self.registrationUri = None
71  if configurationAttributes.containsKey("registration_uri"):
72  self.registrationUri = configurationAttributes.get("registration_uri").getValue2()
73 
74  validOtpConfiguration = self.loadOtpConfiguration(configurationAttributes)
75  if not validOtpConfiguration:
76  return False
77 
78  print "OTP. Initialized successfully"
79  return True
80 

◆ isValidAuthenticationMethod()

def OtpExternalAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
89  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
90  return True
91 

◆ loadOtpConfiguration()

def OtpExternalAuthenticator.PersonAuthentication.loadOtpConfiguration (   self,
  configurationAttributes 
)
278  def loadOtpConfiguration(self, configurationAttributes):
279  print "OTP. Load OTP configuration"
280  if not configurationAttributes.containsKey("otp_conf_file"):
281  return False
282 
283  otp_conf_file = configurationAttributes.get("otp_conf_file").getValue2()
284 
285  # Load configuration from file
286  f = open(otp_conf_file, 'r')
287  try:
288  otpConfiguration = json.loads(f.read())
289  except:
290  print "OTP. Load OTP configuration. Failed to load configuration from file:", otp_conf_file
291  return False
292  finally:
293  f.close()
294 
295  # Check configuration file settings
296  try:
297  self.hotpConfiguration = otpConfiguration["htop"]
298  self.totpConfiguration = otpConfiguration["totp"]
299 
300  hmacShaAlgorithm = self.totpConfiguration["hmacShaAlgorithm"]
301  hmacShaAlgorithmType = None
302 
303  if StringHelper.equalsIgnoreCase(hmacShaAlgorithm, "sha1"):
304  hmacShaAlgorithmType = HmacShaAlgorithm.HMAC_SHA_1
305  elif StringHelper.equalsIgnoreCase(hmacShaAlgorithm, "sha256"):
306  hmacShaAlgorithmType = HmacShaAlgorithm.HMAC_SHA_256
307  elif StringHelper.equalsIgnoreCase(hmacShaAlgorithm, "sha512"):
308  hmacShaAlgorithmType = HmacShaAlgorithm.HMAC_SHA_512
309  else:
310  print "OTP. Load OTP configuration. Invalid TOTP HMAC SHA algorithm: '%s'" % hmacShaAlgorithm
311 
312  self.totpConfiguration["hmacShaAlgorithmType"] = hmacShaAlgorithmType
313  except:
314  print "OTP. Load OTP configuration. Invalid configuration file '%s' format. Exception: '%s'" % (otp_conf_file, sys.exc_info()[1])
315  return False
316 
317 
318  return True
319 

◆ logout()

def OtpExternalAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
266  def logout(self, configurationAttributes, requestParameters):
267  return True
268 

◆ prepareForStep()

def OtpExternalAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
182  def prepareForStep(self, configurationAttributes, requestParameters, step):
183  identity = CdiUtil.bean(Identity)
184  credentials = identity.getCredentials()
185 
186  self.setRequestScopedParameters(identity)
187 
188  if step == 1:
189  print "OTP. Prepare for step 1"
190 
191  return True
192  elif step == 2:
193  print "OTP. Prepare for step 2"
194 
195  session_id_validation = self.validateSessionId(identity)
196  if not session_id_validation:
197  return False
198 
199  otp_auth_method = identity.getWorkingParameter("otp_auth_method")
200  print "OTP. Prepare for step 2. otp_auth_method: '%s'" % otp_auth_method
201 
202  if otp_auth_method == 'enroll':
203  authenticationService = CdiUtil.bean(AuthenticationService)
204  user = authenticationService.getAuthenticatedUser()
205  if user == None:
206  print "OTP. Prepare for step 2. Failed to load user enty"
207  return False
208 
209  if self.otpType == "hotp":
210  otp_secret_key = self.generateSecretHotpKey()
211  otp_enrollment_request = self.generateHotpSecretKeyUri(otp_secret_key, self.otpIssuer, user.getAttribute("displayName"))
212  elif self.otpType == "totp":
213  otp_secret_key = self.generateSecretTotpKey()
214  otp_enrollment_request = self.generateTotpSecretKeyUri(otp_secret_key, self.otpIssuer, user.getAttribute("displayName"))
215  else:
216  print "OTP. Prepare for step 2. Unknown OTP type: '%s'" % self.otpType
217  return False
218 
219  print "OTP. Prepare for step 2. Prepared enrollment request for user: '%s'" % user.getUserId()
220  identity.setWorkingParameter("otp_secret_key", self.toBase64Url(otp_secret_key))
221  identity.setWorkingParameter("otp_enrollment_request", otp_enrollment_request)
222 
223  return True
224  elif step == 3:
225  print "OTP. Prepare for step 3"
226 
227  session_id_validation = self.validateSessionId(identity)
228  if not session_id_validation:
229  return False
230 
231  otp_auth_method = identity.getWorkingParameter("otp_auth_method")
232  print "OTP. Prepare for step 3. otp_auth_method: '%s'" % otp_auth_method
233 
234  if otp_auth_method == 'enroll':
235  return True
236 
237  return False
238 

◆ processBasicAuthentication()

def OtpExternalAuthenticator.PersonAuthentication.processBasicAuthentication (   self,
  credentials 
)
320  def processBasicAuthentication(self, credentials):
321  userService = CdiUtil.bean(UserService)
322  authenticationService = CdiUtil.bean(AuthenticationService)
323 
324  user_name = credentials.getUsername()
325  user_password = credentials.getPassword()
326 
327  logged_in = False
328  if StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password):
329  logged_in = authenticationService.authenticate(user_name, user_password)
330 
331  if not logged_in:
332  return None
333 
334  find_user_by_uid = authenticationService.getAuthenticatedUser()
335  if find_user_by_uid == None:
336  print "OTP. Process basic authentication. Failed to find user '%s'" % user_name
337  return None
338 
339  return find_user_by_uid
340 

◆ processOtpAuthentication()

def OtpExternalAuthenticator.PersonAuthentication.processOtpAuthentication (   self,
  requestParameters,
  user_name,
  identity,
  otp_auth_method 
)
382  def processOtpAuthentication(self, requestParameters, user_name, identity, otp_auth_method):
383  facesMessages = CdiUtil.bean(FacesMessages)
384  facesMessages.setKeepMessages()
385 
386  userService = CdiUtil.bean(UserService)
387 
388  otpCode = ServerUtil.getFirstValue(requestParameters, "loginForm:otpCode")
389  if StringHelper.isEmpty(otpCode):
390  facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to authenticate. OTP code is empty")
391  print "OTP. Process OTP authentication. otpCode is empty"
392 
393  return False
394 
395  if otp_auth_method == "enroll":
396  # Get key from session
397  otp_secret_key_encoded = identity.getWorkingParameter("otp_secret_key")
398  if otp_secret_key_encoded == None:
399  print "OTP. Process OTP authentication. OTP secret key is invalid"
400  return False
401 
402  otp_secret_key = self.fromBase64Url(otp_secret_key_encoded)
403 
404  if self.otpType == "hotp":
405  validation_result = self.validateHotpKey(otp_secret_key, 1, otpCode)
406 
407  if (validation_result != None) and validation_result["result"]:
408  print "OTP. Process HOTP authentication during enrollment. otpCode is valid"
409  # Store HOTP Secret Key and moving factor in user entry
410  otp_user_external_uid = "hotp:%s;%s" % ( otp_secret_key_encoded, validation_result["movingFactor"] )
411 
412  # Add otp_user_external_uid to user's external GUID list
413  find_user_by_external_uid = userService.addUserAttribute(user_name, "oxExternalUid", otp_user_external_uid)
414  if find_user_by_external_uid != None:
415  return True
416 
417  print "OTP. Process HOTP authentication during enrollment. Failed to update user entry"
418  elif self.otpType == "totp":
419  validation_result = self.validateTotpKey(otp_secret_key, otpCode)
420  if (validation_result != None) and validation_result["result"]:
421  print "OTP. Process TOTP authentication during enrollment. otpCode is valid"
422  # Store TOTP Secret Key and moving factor in user entry
423  otp_user_external_uid = "totp:%s" % otp_secret_key_encoded
424 
425  # Add otp_user_external_uid to user's external GUID list
426  find_user_by_external_uid = userService.addUserAttribute(user_name, "oxExternalUid", otp_user_external_uid)
427  if find_user_by_external_uid != None:
428  return True
429 
430  print "OTP. Process TOTP authentication during enrollment. Failed to update user entry"
431  elif otp_auth_method == "authenticate":
432  user_enrollments = self.findEnrollments(user_name)
433 
434  if len(user_enrollments) == 0:
435  print "OTP. Process OTP authentication. There is no OTP enrollment for user '%s'" % user_name
436  facesMessages.add(FacesMessage.SEVERITY_ERROR, "There is no valid OTP user enrollments")
437  return False
438 
439  if self.otpType == "hotp":
440  for user_enrollment in user_enrollments:
441  user_enrollment_data = user_enrollment.split(";")
442  otp_secret_key_encoded = user_enrollment_data[0]
443 
444  # Get current moving factor from user entry
445  moving_factor = StringHelper.toInteger(user_enrollment_data[1])
446  otp_secret_key = self.fromBase64Url(otp_secret_key_encoded)
447 
448  # Validate TOTP
449  validation_result = self.validateHotpKey(otp_secret_key, moving_factor, otpCode)
450  if (validation_result != None) and validation_result["result"]:
451  print "OTP. Process HOTP authentication during authentication. otpCode is valid"
452  otp_user_external_uid = "hotp:%s;%s" % ( otp_secret_key_encoded, moving_factor )
453  new_otp_user_external_uid = "hotp:%s;%s" % ( otp_secret_key_encoded, validation_result["movingFactor"] )
454 
455  # Update moving factor in user entry
456  find_user_by_external_uid = userService.replaceUserAttribute(user_name, "oxExternalUid", otp_user_external_uid, new_otp_user_external_uid)
457  if find_user_by_external_uid != None:
458  return True
459 
460  print "OTP. Process HOTP authentication during authentication. Failed to update user entry"
461  elif self.otpType == "totp":
462  for user_enrollment in user_enrollments:
463  otp_secret_key = self.fromBase64Url(user_enrollment)
464 
465  # Validate TOTP
466  validation_result = self.validateTotpKey(otp_secret_key, otpCode)
467  if (validation_result != None) and validation_result["result"]:
468  print "OTP. Process TOTP authentication during authentication. otpCode is valid"
469  return True
470 
471  facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to authenticate. OTP code is invalid")
472  print "OTP. Process OTP authentication. OTP code is invalid"
473 
474  return False
475 

◆ setRequestScopedParameters()

def OtpExternalAuthenticator.PersonAuthentication.setRequestScopedParameters (   self,
  identity 
)
269  def setRequestScopedParameters(self, identity):
270  if self.registrationUri != None:
271  identity.setWorkingParameter("external_registration_uri", self.registrationUri)
272 
273  if self.customLabel != None:
274  identity.setWorkingParameter("qr_label", self.customLabel)
275 
276  identity.setWorkingParameter("qr_options", self.customQrOptions)
277 

◆ toBase32()

def OtpExternalAuthenticator.PersonAuthentication.toBase32 (   self,
  bytes 
)
553  def toBase32(self, bytes):
554  return BaseEncoding.base32().omitPadding().encode(bytes)
555 

◆ toBase64Url()

def OtpExternalAuthenticator.PersonAuthentication.toBase64Url (   self,
  bytes 
)
556  def toBase64Url(self, bytes):
557  return BaseEncoding.base64Url().encode(bytes)
558 

◆ validateHotpKey()

def OtpExternalAuthenticator.PersonAuthentication.validateHotpKey (   self,
  secretKey,
  movingFactor,
  totpKey 
)
497  def validateHotpKey(self, secretKey, movingFactor, totpKey):
498  lookAheadWindow = self.hotpConfiguration["lookAheadWindow"]
499  digits = self.hotpConfiguration["digits"]
500 
501  htopValidationResult = HOTPValidator.lookAheadWindow(lookAheadWindow).validate(secretKey, movingFactor, digits, totpKey)
502  if htopValidationResult.isValid():
503  return { "result": True, "movingFactor": htopValidationResult.getNewMovingFactor() }
504 
505  return { "result": False, "movingFactor": None }
506 

◆ validateSessionId()

def OtpExternalAuthenticator.PersonAuthentication.validateSessionId (   self,
  identity 
)
369  def validateSessionId(self, identity):
370  session_id = CdiUtil.bean(SessionIdService).getSessionIdFromCookie()
371  if StringHelper.isEmpty(session_id):
372  print "OTP. Validate session id. Failed to determine session_id"
373  return False
374 
375  otp_auth_method = identity.getWorkingParameter("otp_auth_method")
376  if not otp_auth_method in ['enroll', 'authenticate']:
377  print "OTP. Validate session id. Failed to authenticate user. otp_auth_method: '%s'" % otp_auth_method
378  return False
379 
380  return True
381 

◆ validateTotpKey()

def OtpExternalAuthenticator.PersonAuthentication.validateTotpKey (   self,
  secretKey,
  totpKey 
)
533  def validateTotpKey(self, secretKey, totpKey):
534  localTotpKey = self.generateTotpKey(secretKey)
535  if StringHelper.equals(localTotpKey, totpKey):
536  return { "result": True }
537 
538  return { "result": False }
539 

メンバ詳解

◆ currentTimeMillis

OtpExternalAuthenticator.PersonAuthentication.currentTimeMillis

◆ customLabel

OtpExternalAuthenticator.PersonAuthentication.customLabel

◆ customQrOptions

OtpExternalAuthenticator.PersonAuthentication.customQrOptions

◆ hotpConfiguration

OtpExternalAuthenticator.PersonAuthentication.hotpConfiguration

◆ otpIssuer

OtpExternalAuthenticator.PersonAuthentication.otpIssuer

◆ otpType

OtpExternalAuthenticator.PersonAuthentication.otpType

◆ registrationUri

OtpExternalAuthenticator.PersonAuthentication.registrationUri

◆ totpConfiguration

OtpExternalAuthenticator.PersonAuthentication.totpConfiguration

このクラス詳解は次のファイルから抽出されました: