gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
cred-manager-external_otp.PersonAuthentication クラス
cred-manager-external_otp.PersonAuthentication の継承関係図
Inheritance graph
cred-manager-external_otp.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)
 
def hasEnrollments (self, configurationAttributes, user)
 

公開変数類

 currentTimeMillis
 
 otpType
 
 otpIssuer
 
 customLabel
 
 customQrOptions
 
 registrationUri
 
 hotpConfiguration
 
 totpConfiguration
 

詳解

構築子と解体子

◆ __init__()

def cred-manager-external_otp.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
41  def __init__(self, currentTimeMillis):
42  self.currentTimeMillis = currentTimeMillis
43 

関数詳解

◆ authenticate()

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

◆ destroy()

def cred-manager-external_otp.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
80  def destroy(self, configurationAttributes):
81  print "OTP. Destroy"
82  print "OTP. Destroyed successfully"
83  return True
84 

◆ findEnrollments()

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

◆ fromBase64Url()

def cred-manager-external_otp.PersonAuthentication.fromBase64Url (   self,
  chars 
)
563  def fromBase64Url(self, chars):
564  return BaseEncoding.base64Url().decode(chars)
565 
566 

◆ generateHotpKey()

def cred-manager-external_otp.PersonAuthentication.generateHotpKey (   self,
  secretKey,
  movingFactor 
)
494  def generateHotpKey(self, secretKey, movingFactor):
495  digits = self.hotpConfiguration["digits"]
496 
497  hotp = HOTP.key(secretKey).digits(digits).movingFactor(movingFactor).build()
498 
499  return hotp.value()
500 

◆ generateHotpSecretKeyUri()

def cred-manager-external_otp.PersonAuthentication.generateHotpSecretKeyUri (   self,
  secretKey,
  issuer,
  userDisplayName 
)
511  def generateHotpSecretKeyUri(self, secretKey, issuer, userDisplayName):
512  digits = self.hotpConfiguration["digits"]
513 
514  secretKeyBase32 = self.toBase32(secretKey)
515  otpKey = OTPKey(secretKeyBase32, OTPType.HOTP)
516  label = issuer + " %s" % userDisplayName
517 
518  otpAuthURI = OTPAuthURIBuilder.fromKey(otpKey).label(label).issuer(issuer).digits(digits).build()
519 
520  return otpAuthURI.toUriString()
521 

◆ generateSecretHotpKey()

def cred-manager-external_otp.PersonAuthentication.generateSecretHotpKey (   self)
489  def generateSecretHotpKey(self):
490  keyLength = self.hotpConfiguration["keyLength"]
491 
492  return self.generateSecretKey(keyLength)
493 

◆ generateSecretKey()

def cred-manager-external_otp.PersonAuthentication.generateSecretKey (   self,
  keyLength 
)
481  def generateSecretKey(self, keyLength):
482  bytes = jarray.zeros(keyLength, "b")
483  secureRandom = SecureRandom()
484  secureRandom.nextBytes(bytes)
485 
486  return bytes
487 

◆ generateSecretTotpKey()

def cred-manager-external_otp.PersonAuthentication.generateSecretTotpKey (   self)
523  def generateSecretTotpKey(self):
524  keyLength = self.totpConfiguration["keyLength"]
525 
526  return self.generateSecretKey(keyLength)
527 

◆ generateTotpKey()

def cred-manager-external_otp.PersonAuthentication.generateTotpKey (   self,
  secretKey 
)
528  def generateTotpKey(self, secretKey):
529  digits = self.totpConfiguration["digits"]
530  timeStep = self.totpConfiguration["timeStep"]
531  hmacShaAlgorithmType = self.totpConfiguration["hmacShaAlgorithmType"]
532 
533  totp = TOTP.key(secretKey).digits(digits).timeStep(TimeUnit.SECONDS.toMillis(timeStep)).hmacSha(hmacShaAlgorithmType).build()
534 
535  return totp.value()
536 

◆ generateTotpSecretKeyUri()

def cred-manager-external_otp.PersonAuthentication.generateTotpSecretKeyUri (   self,
  secretKey,
  issuer,
  userDisplayName 
)
544  def generateTotpSecretKeyUri(self, secretKey, issuer, userDisplayName):
545  digits = self.totpConfiguration["digits"]
546  timeStep = self.totpConfiguration["timeStep"]
547 
548  secretKeyBase32 = self.toBase32(secretKey)
549  otpKey = OTPKey(secretKeyBase32, OTPType.TOTP)
550  label = issuer + " %s" % userDisplayName
551 
552  otpAuthURI = OTPAuthURIBuilder.fromKey(otpKey).label(label).issuer(issuer).digits(digits).timeStep(TimeUnit.SECONDS.toMillis(timeStep)).build()
553 
554  return otpAuthURI.toUriString()
555 

◆ getAlternativeAuthenticationMethod()

def cred-manager-external_otp.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
91  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
92  return None
93 

◆ getApiVersion()

def cred-manager-external_otp.PersonAuthentication.getApiVersion (   self)
85  def getApiVersion(self):
86  return 1
87 

◆ getCountAuthenticationSteps()

def cred-manager-external_otp.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
245  def getCountAuthenticationSteps(self, configurationAttributes):
246  identity = CdiUtil.bean(Identity)
247 
248  if identity.isSetWorkingParameter("otp_count_login_steps"):
249  return StringHelper.toInteger("%s" % identity.getWorkingParameter("otp_count_login_steps"))
250  else:
251  return 2
252 

◆ getExtraParametersForStep()

def cred-manager-external_otp.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
242  def getExtraParametersForStep(self, configurationAttributes, step):
243  return Arrays.asList("otp_auth_method", "otp_count_login_steps", "otp_secret_key", "otp_enrollment_request")
244 

◆ getPageForStep()

def cred-manager-external_otp.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
253  def getPageForStep(self, configurationAttributes, step):
254  if step == 2:
255  identity = CdiUtil.bean(Identity)
256 
257  otp_auth_method = identity.getWorkingParameter("otp_auth_method")
258  print "OTP. Gep page for step 2. otp_auth_method: '%s'" % otp_auth_method
259 
260  if otp_auth_method == 'enroll':
261  return "/auth/otp/enroll.xhtml"
262  else:
263  #Modified for cred-manager compliance
264  return "/cm/otplogin.xhtml"
265  elif step == 3:
266  return "/auth/otp/otplogin.xhtml"
267 
268  return ""
269 

◆ hasEnrollments()

def cred-manager-external_otp.PersonAuthentication.hasEnrollments (   self,
  configurationAttributes,
  user 
)
568  def hasEnrollments(self, configurationAttributes, user):
569 
570  hasEnrollments = False
571  prefix = self.otpType
572  values = user.getAttributeValues("oxExternalUid")
573 
574  if values != None:
575  for extUid in values:
576  if not hasEnrollments:
577  hasEnrollments = extUid.find(prefix + ":") != -1
578 
579  return hasEnrollments
580 

◆ init()

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

◆ isValidAuthenticationMethod()

def cred-manager-external_otp.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
88  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
89  return True
90 

◆ loadOtpConfiguration()

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

◆ logout()

def cred-manager-external_otp.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
270  def logout(self, configurationAttributes, requestParameters):
271  return True
272 

◆ prepareForStep()

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

◆ processBasicAuthentication()

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

◆ processOtpAuthentication()

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

◆ setRequestScopedParameters()

def cred-manager-external_otp.PersonAuthentication.setRequestScopedParameters (   self,
  identity 
)
273  def setRequestScopedParameters(self, identity):
274  if self.registrationUri != None:
275  identity.setWorkingParameter("external_registration_uri", self.registrationUri)
276 
277  if self.customLabel != None:
278  identity.setWorkingParameter("qr_label", self.customLabel)
279 
280  identity.setWorkingParameter("qr_options", self.customQrOptions)
281 

◆ toBase32()

def cred-manager-external_otp.PersonAuthentication.toBase32 (   self,
  bytes 
)
557  def toBase32(self, bytes):
558  return BaseEncoding.base32().omitPadding().encode(bytes)
559 

◆ toBase64Url()

def cred-manager-external_otp.PersonAuthentication.toBase64Url (   self,
  bytes 
)
560  def toBase64Url(self, bytes):
561  return BaseEncoding.base64Url().encode(bytes)
562 

◆ validateHotpKey()

def cred-manager-external_otp.PersonAuthentication.validateHotpKey (   self,
  secretKey,
  movingFactor,
  totpKey 
)
501  def validateHotpKey(self, secretKey, movingFactor, totpKey):
502  lookAheadWindow = self.hotpConfiguration["lookAheadWindow"]
503  digits = self.hotpConfiguration["digits"]
504 
505  htopValidationResult = HOTPValidator.lookAheadWindow(lookAheadWindow).validate(secretKey, movingFactor, digits, totpKey)
506  if htopValidationResult.isValid():
507  return { "result": True, "movingFactor": htopValidationResult.getNewMovingFactor() }
508 
509  return { "result": False, "movingFactor": None }
510 

◆ validateSessionId()

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

◆ validateTotpKey()

def cred-manager-external_otp.PersonAuthentication.validateTotpKey (   self,
  secretKey,
  totpKey 
)
537  def validateTotpKey(self, secretKey, totpKey):
538  localTotpKey = self.generateTotpKey(secretKey)
539  if StringHelper.equals(localTotpKey, totpKey):
540  return { "result": True }
541 
542  return { "result": False }
543 

メンバ詳解

◆ currentTimeMillis

cred-manager-external_otp.PersonAuthentication.currentTimeMillis

◆ customLabel

cred-manager-external_otp.PersonAuthentication.customLabel

◆ customQrOptions

cred-manager-external_otp.PersonAuthentication.customQrOptions

◆ hotpConfiguration

cred-manager-external_otp.PersonAuthentication.hotpConfiguration

◆ otpIssuer

cred-manager-external_otp.PersonAuthentication.otpIssuer

◆ otpType

cred-manager-external_otp.PersonAuthentication.otpType

◆ registrationUri

cred-manager-external_otp.PersonAuthentication.registrationUri

◆ totpConfiguration

cred-manager-external_otp.PersonAuthentication.totpConfiguration

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