gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
SamlPassportAuthenticator.PersonAuthentication クラス
SamlPassportAuthenticator.PersonAuthentication の継承関係図
Inheritance graph
SamlPassportAuthenticator.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 getNextStep (self, configurationAttributes, requestParameters, step)
 
def logout (self, configurationAttributes, requestParameters)
 
def extensionInit (self, configurationAttributes)
 
def extensionAuthenticate (self, configurationAttributes, requestParameters, step)
 
def extensionPrepareForStep (self, configurationAttributes, requestParameters, step)
 
def extensionGetPageForStep (self, configurationAttributes, step)
 
def loadExternalModule (self, simpleCustProperty)
 
def readBehaviour (self, configurationAttributes)
 
def prepareAttributesMapping (self, attrs)
 
def processKeyStoreProperties (self, attrs)
 
def getCustomAuthzParameter (self, simpleCustProperty)
 
def parseProviderConfigs (self)
 
def getProviderFromJson (self, providerJson)
 
def getPassportRedirectUrl (self, provider)
 
def validSignature (self, jwt)
 
def getUserProfile (self, jwt)
 
def getProfileFromJson (self, user_profile_json)
 
def attemptAuthentication (self, identity, user_profile, user_profile_json)
 
def setEmailMessageError (self)
 
def getRemoteAttr (self, name)
 
def checkRequiredAttributes (self, profile, attrs)
 
def addUser (self, externalUid, profile, userService)
 
def updateUser (self, foundUser, profile, userService)
 
def fillUser (self, foundUser, profile)
 
def flatValues (self, value)
 

公開変数類

 currentTimeMillis
 
 extensionModule
 
 behaveAs
 
 attributesMapping
 
 customAuthzParameter
 
 keyStoreFile
 
 keyStorePassword
 
 registeredProviders
 

詳解

構築子と解体子

◆ __init__()

def SamlPassportAuthenticator.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
33  def __init__(self, currentTimeMillis):
34  self.currentTimeMillis = currentTimeMillis
35 

関数詳解

◆ addUser()

def SamlPassportAuthenticator.PersonAuthentication.addUser (   self,
  externalUid,
  profile,
  userService 
)
618  def addUser(self, externalUid, profile, userService):
619 
620  newUser = User()
621  #Fill user attrs
622  newUser.setAttribute("oxExternalUid", externalUid)
623  self.fillUser(newUser, profile)
624  newUser = userService.addUser(newUser, True)
625  return newUser
626 
627 

◆ attemptAuthentication()

def SamlPassportAuthenticator.PersonAuthentication.attemptAuthentication (   self,
  identity,
  user_profile,
  user_profile_json 
)
489  def attemptAuthentication(self, identity, user_profile, user_profile_json):
490 
491  # "uid" is always present in mapping, see prepareAttributesMapping
492  uidRemoteAttr = self.getRemoteAttr("uid")
493  providerKey = "provider" if self.behaveAs == "social" else "providerkey"
494  if not self.checkRequiredAttributes(user_profile, [uidRemoteAttr, providerKey]):
495  return False
496 
497  provider = user_profile[providerKey]
498  if not provider in self.registeredProviders:
499  print "Passport. attemptAuthentication. Identity Provider %s not recognized" % provider
500  return False
501 
502  uidRemoteAttr = user_profile[uidRemoteAttr]
503  if self.behaveAs == "social":
504  externalUid = "passport-%s:%s" % (provider, uidRemoteAttr)
505  else:
506  # This is for backwards compat. Should it be passport-saml-provider:...??
507  externalUid = "passport-%s:%s" % ("saml", uidRemoteAttr)
508 
509  userService = CdiUtil.bean(UserService)
510  userByUid = userService.getUserByAttribute("oxExternalUid", externalUid)
511 
512  mailRemoteAttr = self.getRemoteAttr("mail")
513  email = None
514  if mailRemoteAttr in user_profile:
515  email = self.flatValues(user_profile[mailRemoteAttr])
516  if len(email) == 0:
517  email = None
518  else:
519  email = email[0]
520  user_profile[mailRemoteAttr] = email
521 
522  if email == None and self.registeredProviders[provider]["requestForEmail"]:
523  print "Passport. attemptAuthentication. Email was not received"
524 
525  if userByUid != None:
526  # This helps asking for the email over every login attempt
527  email = userByUid.getAttribute("mail")
528  if email != None:
529  print "Passport. attemptAuthentication. Filling missing email value with %s" % email
530  # Assumes mailRemoteAttr is not None
531  user_profile[mailRemoteAttr] = email
532 
533  if email == None:
534  # Store user profile in session and abort this routine
535  identity.setWorkingParameter("passport_user_profile", user_profile_json)
536  return True
537 
538  userByMail = None if email == None else userService.getUserByAttribute("mail", email)
539 
540  # Determine if we should add entry, update existing, or deny access
541  doUpdate = False
542  doAdd = False
543  if userByUid != None:
544  print "User with externalUid '%s' already exists" % externalUid
545  if userByMail == None:
546  doUpdate = True
547  else:
548  if userByMail.getUserId() == userByUid.getUserId():
549  doUpdate = True
550  else:
551  print "Users with externalUid '%s' and mail '%s' are different. Access will be denied. Impersonation attempt?" % (externalUid, email)
552  else:
553  if userByMail == None:
554  doAdd = True
555  elif self.registeredProviders[provider]["emailLinkingSafe"]:
556 
557  tmpList = userByMail.getAttributeValues("oxExternalUid")
558  tmpList = ArrayList() if tmpList == None else ArrayList(tmpList)
559  tmpList.add(externalUid)
560  userByMail.setAttribute("oxExternalUid", tmpList)
561 
562  userByUid = userByMail
563  print "External user supplying mail %s will be linked to existing account '%s'" % (email, userByMail.getUserId())
564  doUpdate = True
565  else:
566  print "An attempt to supply an email of an existing user was made. Turn on 'emailLinkingSafe' if you want to enable linking"
567 
568  username = None
569  try:
570  if doUpdate:
571  username = userByUid.getUserId()
572  print "Passport. attemptAuthentication. Updating user %s" % username
573  self.updateUser(userByUid, user_profile, userService)
574  elif doAdd:
575  print "Passport. attemptAuthentication. Creating user %s" % externalUid
576  newUser = self.addUser(externalUid, user_profile, userService)
577  username = newUser.getUserId()
578  except:
579  print "Exception: ", sys.exc_info()[1]
580  print "Passport. attemptAuthentication. Authentication failed"
581  return False
582 
583  if username == None:
584  print "Passport. attemptAuthentication. Authentication attempt was rejected"
585  return False
586  else:
587  logged_in = CdiUtil.bean(AuthenticationService).authenticate(username)
588  print "Passport. attemptAuthentication. Authentication for %s returned %s" % (username, logged_in)
589  return logged_in
590 
591 

◆ authenticate()

def SamlPassportAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
71  def authenticate(self, configurationAttributes, requestParameters, step):
72 
73  extensionResult = self.extensionAuthenticate(configurationAttributes, requestParameters, step)
74  if extensionResult != None:
75  return extensionResult
76 
77  print "Passport. authenticate called %s" % str(step)
78  identity = CdiUtil.bean(Identity)
79 
80  if step == 1:
81  # Get JWT token
82  jwt_param = ServerUtil.getFirstValue(requestParameters, "user")
83  if jwt_param != None:
84  print "Passport. authenticate for step 1. JWT user profile token found"
85 
86  # Parse JWT and validate
87  jwt = Jwt.parse(jwt_param)
88  if not self.validSignature(jwt):
89  return False
90 
91  (user_profile, json) = self.getUserProfile(jwt)
92  if user_profile == None:
93  return False
94 
95  return self.attemptAuthentication(identity, user_profile, json)
96 
97  #See passportlogin.xhtml
98  provider = ServerUtil.getFirstValue(requestParameters, "loginForm:provider")
99  if StringHelper.isEmpty(provider):
100 
101  #it's username + passw auth
102  print "Passport. authenticate for step 1. Basic authentication detected"
103  logged_in = False
104 
105  credentials = identity.getCredentials()
106  user_name = credentials.getUsername()
107  user_password = credentials.getPassword()
108 
109  if StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password):
110  authenticationService = CdiUtil.bean(AuthenticationService)
111  logged_in = authenticationService.authenticate(user_name, user_password)
112 
113  print "Passport. authenticate for step 1. Basic authentication returned: %s" % logged_in
114  return logged_in
115 
116  elif provider in self.registeredProviders:
117  #it's a recognized external IDP
118  identity.setWorkingParameter("selectedProvider", provider)
119  print "Passport. authenticate for step 1. Retrying step 1"
120  #see prepareForStep (step = 1)
121  return True
122 
123  if step == 2:
124  mail = ServerUtil.getFirstValue(requestParameters, "loginForm:email")
125  json = identity.getWorkingParameter("passport_user_profile")
126 
127  if mail == None:
128  self.setEmailMessageError()
129  elif json != None:
130  # Completion of profile takes place
131  attr = self.getRemoteAttr("mail")
132  user_profile = self.getProfileFromJson(json)
133  user_profile[attr] = mail
134 
135  return self.attemptAuthentication(identity, user_profile, json)
136 
137  print "Passport. authenticate for step 2. Failed: expected mail value in HTTP request and json profile in session"
138  return False
139 
140 

◆ checkRequiredAttributes()

def SamlPassportAuthenticator.PersonAuthentication.checkRequiredAttributes (   self,
  profile,
  attrs 
)
609  def checkRequiredAttributes(self, profile, attrs):
610 
611  for attr in attrs:
612  if (not attr in profile) or len(self.flatValues(profile[attr])) == 0:
613  print "Passport. checkRequiredAttributes. Attribute '%s' is missing in profile" % attr
614  return False
615  return True
616 
617 

◆ destroy()

def SamlPassportAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
54  def destroy(self, configurationAttributes):
55  print "Passport. destroy called"
56  return True
57 
58 

◆ extensionAuthenticate()

def SamlPassportAuthenticator.PersonAuthentication.extensionAuthenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
240  def extensionAuthenticate(self, configurationAttributes, requestParameters, step):
241 
242  if self.extensionModule == None:
243  return None
244  return self.extensionModule.authenticate(configurationAttributes, requestParameters, step)
245 
246 

◆ extensionGetPageForStep()

def SamlPassportAuthenticator.PersonAuthentication.extensionGetPageForStep (   self,
  configurationAttributes,
  step 
)
254  def extensionGetPageForStep(self, configurationAttributes, step):
255 
256  if self.extensionModule == None:
257  return None
258  return self.extensionModule.getPageForStep(configurationAttributes, step)
259 
260 # Initalization routines
261 

◆ extensionInit()

def SamlPassportAuthenticator.PersonAuthentication.extensionInit (   self,
  configurationAttributes 
)
233  def extensionInit(self, configurationAttributes):
234 
235  if self.extensionModule == None:
236  return None
237  return self.extensionModule.init(configurationAttributes)
238 
239 

◆ extensionPrepareForStep()

def SamlPassportAuthenticator.PersonAuthentication.extensionPrepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
247  def extensionPrepareForStep(self, configurationAttributes, requestParameters, step):
248 
249  if self.extensionModule == None:
250  return None
251  return self.extensionModule.prepareForStep(configurationAttributes, requestParameters, step)
252 
253 

◆ fillUser()

def SamlPassportAuthenticator.PersonAuthentication.fillUser (   self,
  foundUser,
  profile 
)
633  def fillUser(self, foundUser, profile):
634 
635  # mapping is already lower cased
636  mapping = self.attributesMapping
637  for remoteAttr in mapping:
638  values = self.flatValues(profile[remoteAttr])
639 
640  # "provider" is disregarded if part of mapping
641  if remoteAttr != "provider":
642  localAttr = mapping[remoteAttr]
643  print "Remote (%s), Local (%s) = %s" % (remoteAttr, localAttr, values)
644  foundUser.setAttribute(localAttr, values)
645 

◆ flatValues()

def SamlPassportAuthenticator.PersonAuthentication.flatValues (   self,
  value 
)
654  def flatValues(self, value):
655 
656  try:
657  typ = type(value)
658  if typ is str or typ is unicode:
659  return [] if len(value) == 0 else [value]
660  elif typ is dict:
661  return [json.dumps(value)]
662  elif typ is list:
663  if len(value) > 0 and type(value[0]) is dict:
664  # it's an array of objects
665  l = []
666  for i in range(len(value)):
667  l.append(json.dumps(value[i]))
668  return l
669  else:
670  return value
671  else:
672  # value = None?
673  return []
674  except:
675  # failed!
676  print "Passport. flatValues. Failed to convert %s to an array" % value
677  return []
678 

◆ getAlternativeAuthenticationMethod()

def SamlPassportAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
67  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
68  return None
69 
70 

◆ getApiVersion()

def SamlPassportAuthenticator.PersonAuthentication.getApiVersion (   self)
59  def getApiVersion(self):
60  return 2
61 
62 

◆ getCountAuthenticationSteps()

def SamlPassportAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
198  def getCountAuthenticationSteps(self, configurationAttributes):
199  print "Passport. getCountAuthenticationSteps called"
200  identity = CdiUtil.bean(Identity)
201  if identity.getWorkingParameter("passport_user_profile") != None:
202  return 2
203  return 1
204 
205 

◆ getCustomAuthzParameter()

def SamlPassportAuthenticator.PersonAuthentication.getCustomAuthzParameter (   self,
  simpleCustProperty 
)
345  def getCustomAuthzParameter(self, simpleCustProperty):
346 
347  customAuthzParameter = None
348  if simpleCustProperty != None:
349  prop = simpleCustProperty.getValue2()
350  if StringHelper.isNotEmpty(prop):
351  customAuthzParameter = prop
352 
353  if customAuthzParameter == None:
354  print "Passport. getCustomAuthzParameter. No custom param for OIDC authz request in script properties"
355  print "Passport. getCustomAuthzParameter. Passport flow cannot be initiated by doing an OpenID connect authorization request"
356  else:
357  print "Passport. getCustomAuthzParameter. Custom param for OIDC authz request in script properties: %s" % customAuthzParameter
358 
359  return customAuthzParameter
360 
361 # Configuration parsing
362 

◆ getExtraParametersForStep()

def SamlPassportAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
189  def getExtraParametersForStep(self, configurationAttributes, step):
190  print "Passport. getExtraParametersForStep called"
191  if step == 1:
192  return Arrays.asList("selectedProvider")
193  elif step == 2:
194  return Arrays.asList("passport_user_profile")
195  return None
196 
197 

◆ getNextStep()

def SamlPassportAuthenticator.PersonAuthentication.getNextStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
217  def getNextStep(self, configurationAttributes, requestParameters, step):
218 
219  if step == 1:
220  identity = CdiUtil.bean(Identity)
221  provider = identity.getWorkingParameter("selectedProvider")
222  if provider != None:
223  return 1
224 
225  return -1
226 
227 

◆ getPageForStep()

def SamlPassportAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
206  def getPageForStep(self, configurationAttributes, step):
207 
208  extensionResult = self.extensionGetPageForStep(configurationAttributes, step)
209  if extensionResult != None:
210  return extensionResult
211 
212  if (step == 1):
213  return "/auth/passport/passportlogin.xhtml"
214  return "/auth/passport/passportpostlogin.xhtml"
215 
216 

◆ getPassportRedirectUrl()

def SamlPassportAuthenticator.PersonAuthentication.getPassportRedirectUrl (   self,
  provider 
)
415  def getPassportRedirectUrl(self, provider):
416 
417  # provider is assumed to exist in self.registeredProviders
418  url = None
419  try:
420  facesContext = CdiUtil.bean(FacesContext)
421  tokenEndpoint = "https://%s/passport/token" % facesContext.getExternalContext().getRequest().getServerName()
422 
423  httpService = CdiUtil.bean(HttpService)
424  httpclient = httpService.getHttpsClient()
425 
426  print "Passport. getPassportRedirectUrl. Obtaining token from passport at %s" % tokenEndpoint
427  resultResponse = httpService.executeGet(httpclient, tokenEndpoint, Collections.singletonMap("Accept", "text/json"))
428  httpResponse = resultResponse.getHttpResponse()
429  bytes = httpService.getResponseContent(httpResponse)
430 
431  response = httpService.convertEntityToString(bytes)
432  print "Passport. getPassportRedirectUrl. Response was %s" % httpResponse.getStatusLine().getStatusCode()
433 
434  tokenObj = json.loads(response)
435 
436  if self.registeredProviders[provider]["saml"]:
437  provider = "saml/" + provider
438 
439  url = "/passport/auth/%s/%s" % (provider, tokenObj["token_"])
440 
441  except:
442  print "Passport. getPassportRedirectUrl. Error building redirect URL: ", sys.exc_info()[1]
443 
444  return url
445 
446 

◆ getProfileFromJson()

def SamlPassportAuthenticator.PersonAuthentication.getProfileFromJson (   self,
  user_profile_json 
)
481  def getProfileFromJson(self, user_profile_json):
482  data = json.loads(user_profile_json)
483  user_profile = {}
484  for key in data.keys():
485  user_profile[key.lower()] = data[key]
486  return user_profile
487 
488 

◆ getProviderFromJson()

def SamlPassportAuthenticator.PersonAuthentication.getProviderFromJson (   self,
  providerJson 
)
403  def getProviderFromJson(self, providerJson):
404 
405  provider = None
406  try:
407  obj = json.loads(Base64Util.base64urldecodeToString(providerJson))
408  provider = obj["provider"]
409  except:
410  print "Passport. getProviderFromJson. Could not parse provided Json string. Returning None"
411 
412  return provider
413 
414 

◆ getRemoteAttr()

def SamlPassportAuthenticator.PersonAuthentication.getRemoteAttr (   self,
  name 
)
599  def getRemoteAttr(self, name):
600 
601  # It's guaranteed this does not return None when name == "uid" (see prepareAttributesMapping)
602  mapping = self.attributesMapping
603  for remoteAttr in mapping.keys():
604  if mapping[remoteAttr] == name:
605  return remoteAttr
606  return None
607 
608 

◆ getUserProfile()

def SamlPassportAuthenticator.PersonAuthentication.getUserProfile (   self,
  jwt 
)
468  def getUserProfile(self, jwt):
469  # Check if there is user profile
470  jwt_claims = jwt.getClaims()
471  user_profile_json = jwt_claims.getClaimAsString("data")
472  if StringHelper.isEmpty(user_profile_json):
473  print "Passport. getUserProfile. User profile missing in JWT token"
474  user_profile = None
475  else:
476  user_profile = self.getProfileFromJson(user_profile_json)
477 
478  return (user_profile, user_profile_json)
479 
480 

◆ init()

def SamlPassportAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
36  def init(self, configurationAttributes):
37  print "Passport. init called"
38 
39  self.extensionModule = self.loadExternalModule(configurationAttributes.get("extension_module"))
40  extensionResult = self.extensionInit(configurationAttributes)
41  if extensionResult != None:
42  return extensionResult
43 
44  self.behaveAs = self.readBehaviour(configurationAttributes)
45  self.attributesMapping = self.prepareAttributesMapping(configurationAttributes)
46  success = self.behaveAs != None and self.attributesMapping != None and self.processKeyStoreProperties(configurationAttributes)
47 
48  print "Passport. init. Behaviour is %s" % self.behaveAs
49  self.customAuthzParameter = self.getCustomAuthzParameter(configurationAttributes.get("authz_req_param_provider"))
50  print "Passport. init. Initialization success" if success else "Passport. init. Initialization failed"
51  return success
52 
53 

◆ isValidAuthenticationMethod()

def SamlPassportAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
63  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
64  return True
65 
66 

◆ loadExternalModule()

def SamlPassportAuthenticator.PersonAuthentication.loadExternalModule (   self,
  simpleCustProperty 
)
262  def loadExternalModule(self, simpleCustProperty):
263 
264  if simpleCustProperty != None:
265  print "Passport. loadExternalModule. Loading passport extension module..."
266  moduleName = simpleCustProperty.getValue2()
267  try:
268  module = __import__(moduleName)
269  return module
270  except:
271  print "Passport. loadExternalModule. Failed to load module %s" % moduleName
272  print "Exception: ", sys.exc_info()[1]
273  print "Passport. loadExternalModule. Flow will be driven entirely by routines of main passport script"
274  return None
275 
276 

◆ logout()

def SamlPassportAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
228  def logout(self, configurationAttributes, requestParameters):
229  return True
230 
231 # Extension module related functions
232 

◆ parseProviderConfigs()

def SamlPassportAuthenticator.PersonAuthentication.parseProviderConfigs (   self)
363  def parseProviderConfigs(self):
364 
365  self.registeredProviders = {}
366  try:
367  if self.behaveAs == "social":
368  print "Passport. parseProviderConfigs. Adding social providers"
369  passportDN = CdiUtil.bean(ConfigurationFactory).getLdapConfiguration().getString("oxpassport_ConfigurationEntryDN")
370  entryManager = CdiUtil.bean(AppInitializer).getLdapEntryManager()
371  config = LdapOxPassportConfiguration()
372  config = entryManager.find(config.getClass(), passportDN).getPassportConfigurations()
373 
374  if config != None:
375  for strategy in config:
376  provider = strategy.getStrategy()
377  self.registeredProviders[provider] = { "emailLinkingSafe" : False, "requestForEmail" : False }
378  for field in strategy.getFieldset():
379  for property in self.registeredProviders[provider]:
380  if StringHelper.equalsIgnoreCase(field.getValue1(), property) and StringHelper.equalsIgnoreCase(field.getValue2(), "true"):
381  self.registeredProviders[provider][property] = True
382 
383  self.registeredProviders[provider]["saml"] = False
384 
385  if self.behaveAs == "saml":
386  print "Passport. parseProviderConfigs. Adding SAML IDPs"
387  f = open("/etc/gluu/conf/passport-saml-config.json", 'r')
388  config = json.loads(f.read())
389 
390  for provider in config:
391  providerCfg = config[provider]
392  if "enable" in providerCfg and StringHelper.equalsIgnoreCase(providerCfg["enable"], "true"):
393  self.registeredProviders[provider] = {
394  "emailLinkingSafe" : "emailLinkingSafe" in providerCfg and providerCfg["emailLinkingSafe"],
395  "requestForEmail" : "requestForEmail" in providerCfg and providerCfg["requestForEmail"],
396  "saml" : True }
397 
398  except:
399  print "Passport. parseProviderConfigs. An error occurred while building the list of supported authentication providers", sys.exc_info()[1]
400 
401 # Auxiliary routines
402 

◆ prepareAttributesMapping()

def SamlPassportAuthenticator.PersonAuthentication.prepareAttributesMapping (   self,
  attrs 
)
295  def prepareAttributesMapping(self, attrs):
296 
297  remote = attrs.get("generic_remote_attributes_list")
298  local = attrs.get("generic_local_attributes_list")
299 
300  if remote == None or local == None:
301  print "Passport. checkPropertiesConsistency. Property generic_remote_attributes_list or generic_local_attributes_list was not supplied"
302  return None
303 
304  remote = StringHelper.split(remote.getValue2().lower(), ",")
305  local = StringHelper.split(local.getValue2().lower(), ",")
306  llocal = len(local)
307 
308  if len(remote) != llocal:
309  print "Passport. checkPropertiesConsistency. Number of items in generic_remote_attributes_list and generic_local_attributes_list not equal"
310  return None
311 
312  for i in range(llocal):
313  if len(remote[i]) == 0 or len(local[i]) == 0:
314  print "Passport. checkPropertiesConsistency. Empty attribute name detected in generic_remote_attributes_list or generic_local_attributes_list"
315  return None
316 
317  if not "uid" in local:
318  print "Passport. checkPropertiesConsistency. Property generic_local_attributes_list must contain 'uid'"
319  return None
320 
321  mapping = {}
322  for i in range(llocal):
323  mapping[remote[i]] = local[i]
324 
325  return mapping
326 
327 

◆ prepareForStep()

def SamlPassportAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
141  def prepareForStep(self, configurationAttributes, requestParameters, step):
142 
143  extensionResult = self.extensionPrepareForStep(configurationAttributes, requestParameters, step)
144  if extensionResult != None:
145  return extensionResult
146 
147  print "Passport. prepareForStep called %s" % str(step)
148  identity = CdiUtil.bean(Identity)
149 
150  if step == 1:
151  # This param is needed in passportlogin.xhtml
152  identity.setWorkingParameter("behaviour", self.behaveAs)
153 
154  #re-read the strategies config (for instance to know which strategies have enabled the email account linking)
155  self.parseProviderConfigs()
156  providerParam = self.customAuthzParameter
157  url = None
158 
159  #this param could have been set previously in authenticate step if current step is being retried
160  provider = identity.getWorkingParameter("selectedProvider")
161  if provider != None:
162  url = self.getPassportRedirectUrl(provider)
163  identity.setWorkingParameter("selectedProvider", None)
164 
165  elif providerParam != None:
166  sessionAttributes = identity.getSessionId().getSessionAttributes()
167  paramValue = sessionAttributes.get(providerParam)
168 
169  if paramValue != None:
170  print "Passport. prepareForStep. Found value in custom param of authorization request: %s" % paramValue
171  provider = self.getProviderFromJson(paramValue)
172 
173  if provider == None:
174  print "Passport. prepareForStep. A provider value could not be extracted from custom authorization request parameter"
175  elif not provider in self.registeredProviders:
176  print "Passport. prepareForStep. Provider '%s' not part of known configured IDPs/OPs" % provider
177  else:
178  url = self.getPassportRedirectUrl(provider)
179 
180  if url == None:
181  print "Passport. prepareForStep. A page to manually select an identity provider will be shown"
182  else:
183  facesService = CdiUtil.bean(FacesService)
184  facesService.redirectToExternalURL(url)
185 
186  return True
187 
188 

◆ processKeyStoreProperties()

def SamlPassportAuthenticator.PersonAuthentication.processKeyStoreProperties (   self,
  attrs 
)
328  def processKeyStoreProperties(self, attrs):
329  file = attrs.get("key_store_file")
330  password = attrs.get("key_store_password")
331 
332  if file != None and password != None:
333  file = file.getValue2()
334  password = password.getValue2()
335 
336  if StringHelper.isNotEmpty(file) and StringHelper.isNotEmpty(password):
337  self.keyStoreFile = file
338  self.keyStorePassword = password
339  return True
340 
341  print "Passport. readKeyStoreProperties. Properties key_store_file or key_store_password not found or empty"
342  return False
343 
344 

◆ readBehaviour()

def SamlPassportAuthenticator.PersonAuthentication.readBehaviour (   self,
  configurationAttributes 
)
277  def readBehaviour(self, configurationAttributes):
278 
279  behave = configurationAttributes.get("behaviour")
280  if behave != None:
281  behave = behave.getValue2()
282 
283  if behave != None:
284  if StringHelper.equalsIgnoreCase(behave, "saml") or StringHelper.equalsIgnoreCase(behave, "social"):
285  behave = behave.lower()
286  else:
287  behave = None
288 
289  if behave == None:
290  print "readBehaviour. Failure to determine behaviour. Check script config properties (valid values are 'social' or 'saml')"
291 
292  return behave
293 
294 

◆ setEmailMessageError()

def SamlPassportAuthenticator.PersonAuthentication.setEmailMessageError (   self)
592  def setEmailMessageError(self):
593  facesMessages = CdiUtil.bean(FacesMessages)
594  facesMessages.setKeepMessages()
595  facesMessages.clear()
596  facesMessages.add(FacesMessage.SEVERITY_ERROR, "Email was missing in user profile")
597 
598 

◆ updateUser()

def SamlPassportAuthenticator.PersonAuthentication.updateUser (   self,
  foundUser,
  profile,
  userService 
)
628  def updateUser(self, foundUser, profile, userService):
629  self.fillUser(foundUser, profile)
630  userService.updateUser(foundUser)
631 
632 

◆ validSignature()

def SamlPassportAuthenticator.PersonAuthentication.validSignature (   self,
  jwt 
)
447  def validSignature(self, jwt):
448 
449  print "Passport. validSignature. Checking JWT token signature"
450  valid = False
451 
452  try:
453  appConfiguration = AppConfiguration()
454  appConfiguration.setWebKeysStorage(WebKeyStorage.KEYSTORE)
455  appConfiguration.setKeyStoreFile(self.keyStoreFile)
456  appConfiguration.setKeyStoreSecret(self.keyStorePassword)
457 
458  cryptoProvider = CryptoProviderFactory.getCryptoProvider(appConfiguration)
459  valid = cryptoProvider.verifySignature(jwt.getSigningInput(), jwt.getEncodedSignature(), jwt.getHeader().getKeyId(),
460  None, None, jwt.getHeader().getAlgorithm())
461  except:
462  print "Exception: ", sys.exc_info()[1]
463 
464  print "Passport. validSignature. Validation result was %s" % valid
465  return valid
466 
467 

メンバ詳解

◆ attributesMapping

SamlPassportAuthenticator.PersonAuthentication.attributesMapping

◆ behaveAs

SamlPassportAuthenticator.PersonAuthentication.behaveAs

◆ currentTimeMillis

SamlPassportAuthenticator.PersonAuthentication.currentTimeMillis

◆ customAuthzParameter

SamlPassportAuthenticator.PersonAuthentication.customAuthzParameter

◆ extensionModule

SamlPassportAuthenticator.PersonAuthentication.extensionModule

◆ keyStoreFile

SamlPassportAuthenticator.PersonAuthentication.keyStoreFile

◆ keyStorePassword

SamlPassportAuthenticator.PersonAuthentication.keyStorePassword

◆ registeredProviders

SamlPassportAuthenticator.PersonAuthentication.registeredProviders

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