gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
SamlExternalAuthenticator.PersonAuthentication クラス
SamlExternalAuthenticator.PersonAuthentication の継承関係図
Inheritance graph
SamlExternalAuthenticator.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 isPassedStep1 ()
 
def loadCeritificate (self, asimba_saml_certificate_file)
 
def getClientConfiguration (self, configurationAttributes, requestParameters)
 
def getCurrentSamlConfiguration (self, currentSamlConfiguration, configurationAttributes, requestParameters)
 
def prepareAttributesMapping (self, saml_idp_attributes_mapping)
 
def prepareUserObjectClasses (self, configurationAttributes)
 
def prepareUserEnforceUniquenessAttributes (self, configurationAttributes)
 
def prepareCurrentAttributesMapping (self, currentAttributesMapping, configurationAttributes, requestParameters)
 
def samlExtensionPostLogin (self, configurationAttributes, user)
 
def checkUserUniqueness (self, user)
 
def getMappedUser (self, configurationAttributes, requestParameters, saml_response_attributes)
 
def getMappedAllAttributesUser (self, saml_response_attributes)
 
def getNameId (self, samlResponse, newUser)
 
def getSamlNameId (self, samlResponse)
 
def generateNameUid (self, user)
 
def setDefaultUid (self, user, saml_user_uid)
 

公開変数類

 currentTimeMillis
 
 samlConfiguration
 
 generateNameId
 
 updateUser
 
 userObjectClasses
 
 userEnforceAttributesUniqueness
 
 attributesMapping
 
 samlExtensionModule
 
 debugEnrollment
 

詳解

構築子と解体子

◆ __init__()

def SamlExternalAuthenticator.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
26  def __init__(self, currentTimeMillis):
27  self.currentTimeMillis = currentTimeMillis
28 

関数詳解

◆ authenticate()

def SamlExternalAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
128  def authenticate(self, configurationAttributes, requestParameters, step):
129  identity = CdiUtil.bean(Identity)
130  credentials = identity.getCredentials()
131 
132  userService = CdiUtil.bean(UserService)
133  authenticationService = CdiUtil.bean(AuthenticationService)
134 
135  saml_map_user = False
136  saml_enroll_user = False
137  saml_enroll_all_user_attr = False
138  # Use saml_deployment_type only if there is no attributes mapping
139  if configurationAttributes.containsKey("saml_deployment_type"):
140  saml_deployment_type = StringHelper.toLowerCase(configurationAttributes.get("saml_deployment_type").getValue2())
141 
142  if StringHelper.equalsIgnoreCase(saml_deployment_type, "map"):
143  saml_map_user = True
144 
145  if StringHelper.equalsIgnoreCase(saml_deployment_type, "enroll"):
146  saml_enroll_user = True
147 
148  if StringHelper.equalsIgnoreCase(saml_deployment_type, "enroll_all_attr"):
149  saml_enroll_all_user_attr = True
150 
151  saml_allow_basic_login = False
152  if configurationAttributes.containsKey("saml_allow_basic_login"):
153  saml_allow_basic_login = StringHelper.toBoolean(configurationAttributes.get("saml_allow_basic_login").getValue2(), False)
154 
155  use_basic_auth = False
156  if saml_allow_basic_login:
157  # Detect if user used basic authnetication method
158 
159  user_name = credentials.getUsername()
160  user_password = credentials.getPassword()
161  if StringHelper.isNotEmpty(user_name) and StringHelper.isNotEmpty(user_password):
162  use_basic_auth = True
163 
164  if (step == 1) and saml_allow_basic_login and use_basic_auth:
165  print "Asimba. Authenticate for step 1. Basic authentication"
166 
167  identity.setWorkingParameter("saml_count_login_steps", 1)
168 
169  user_name = credentials.getUsername()
170  user_password = credentials.getPassword()
171 
172  logged_in = False
173  if StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password):
174  logged_in = authenticationService.authenticate(user_name, user_password)
175 
176  if (not logged_in):
177  return False
178 
179  return True
180 
181  if (step == 1):
182  print "Asimba. Authenticate for step 1"
183 
184  currentSamlConfiguration = self.getCurrentSamlConfiguration(self.samlConfiguration, configurationAttributes, requestParameters)
185  if (currentSamlConfiguration == None):
186  print "Asimba. Prepare for step 1. Client saml configuration is invalid"
187  return False
188 
189  saml_response_array = requestParameters.get("SAMLResponse")
190  if ArrayHelper.isEmpty(saml_response_array):
191  print "Asimba. Authenticate for step 1. saml_response is empty"
192  return False
193 
194  saml_response = saml_response_array[0]
195 
196  print "Asimba. Authenticate for step 1. saml_response: '%s'" % saml_response
197 
198  samlResponse = Response(currentSamlConfiguration)
199  samlResponse.loadXmlFromBase64(saml_response)
200 
201  saml_validate_response = True
202  if configurationAttributes.containsKey("saml_validate_response"):
203  saml_validate_response = StringHelper.toBoolean(configurationAttributes.get("saml_validate_response").getValue2(), False)
204 
205  if saml_validate_response:
206  if not samlResponse.isValid():
207  print "Asimba. Authenticate for step 1. saml_response isn't valid"
208  return False
209 
210  if samlResponse.isAuthnFailed():
211  print "Asimba. Authenticate for step 1. saml_response AuthnFailed"
212  return False
213 
214  saml_response_attributes = samlResponse.getAttributes()
215  print "Asimba. Authenticate for step 1. attributes: '%s'" % saml_response_attributes
216 
217  if saml_map_user:
218  saml_user_uid = self.getSamlNameId(samlResponse)
219  if saml_user_uid == None:
220  return False
221 
222  # Use mapping to local IDP user
223  print "Asimba. Authenticate for step 1. Attempting to find user by oxExternalUid: saml: '%s'" % saml_user_uid
224 
225  # Check if the is user with specified saml_user_uid
226  find_user_by_uid = userService.getUserByAttribute("oxExternalUid", "saml:%s" % saml_user_uid)
227 
228  if find_user_by_uid == None:
229  print "Asimba. Authenticate for step 1. Failed to find user"
230  print "Asimba. Authenticate for step 1. Setting count steps to 2"
231  identity.setWorkingParameter("saml_count_login_steps", 2)
232  identity.setWorkingParameter("saml_user_uid", saml_user_uid)
233  return True
234 
235  found_user_name = find_user_by_uid.getUserId()
236  print "Asimba. Authenticate for step 1. found_user_name: '%s'" % found_user_name
237 
238  user_authenticated = authenticationService.authenticate(found_user_name)
239  if user_authenticated == False:
240  print "Asimba. Authenticate for step 1. Failed to authenticate user"
241  return False
242 
243  print "Asimba. Authenticate for step 1. Setting count steps to 1"
244  identity.setWorkingParameter("saml_count_login_steps", 1)
245 
246  post_login_result = self.samlExtensionPostLogin(configurationAttributes, find_user_by_uid)
247  print "Asimba. Authenticate for step 1. post_login_result: '%s'" % post_login_result
248 
249  return post_login_result
250  elif saml_enroll_user:
251  # Convert SAML response to user entry
252  newUser = self.getMappedUser(configurationAttributes, requestParameters, saml_response_attributes)
253 
254  saml_user_uid = self.getNameId(samlResponse, newUser)
255  if saml_user_uid == None:
256  return False
257 
258  self.setDefaultUid(newUser, saml_user_uid)
259  newUser.setAttribute("oxExternalUid", "saml:%s" % saml_user_uid)
260 
261  # Use auto enrollment to local IDP
262  print "Asimba. Authenticate for step 1. Attempting to find user by oxExternalUid: saml: '%s'" % saml_user_uid
263 
264  # Check if there is user with specified saml_user_uid
265  find_user_by_uid = userService.getUserByAttribute("oxExternalUid", "saml:%s" % saml_user_uid)
266  if find_user_by_uid == None:
267  # Auto user enrollment
268  print "Asimba. Authenticate for step 1. There is no user in LDAP. Adding user to local LDAP"
269 
270  print "Asimba. Authenticate for step 1. Attempting to add user '%s' with next attributes: '%s'" % (saml_user_uid, newUser.getCustomAttributes())
271  user_unique = self.checkUserUniqueness(newUser)
272  if not user_unique:
273  print "Asimba. Authenticate for step 1. Failed to add user: '%s'. User not unique" % newUser.getUserId()
274  facesMessages = CdiUtil.bean(FacesMessages)
275  facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to enroll. User with same key attributes exist already")
276  facesMessages.setKeepMessages()
277  return False
278 
279  find_user_by_uid = userService.addUser(newUser, True)
280  print "Asimba. Authenticate for step 1. Added new user with UID: '%s'" % find_user_by_uid.getUserId()
281  else:
282  if self.updateUser:
283  print "Asimba. Authenticate for step 1. Attempting to update user '%s' with next attributes: '%s'" % (saml_user_uid, newUser.getCustomAttributes())
284  find_user_by_uid.setCustomAttributes(newUser.getCustomAttributes())
285  userService.updateUser(find_user_by_uid)
286  print "Asimba. Authenticate for step 1. Updated user with UID: '%s'" % saml_user_uid
287 
288  found_user_name = find_user_by_uid.getUserId()
289  print "Asimba. Authenticate for step 1. found_user_name: '%s'" % found_user_name
290 
291  user_authenticated = authenticationService.authenticate(found_user_name)
292  if user_authenticated == False:
293  print "Asimba. Authenticate for step 1. Failed to authenticate user: '%s'" % found_user_name
294  return False
295 
296  print "Asimba. Authenticate for step 1. Setting count steps to 1"
297  identity.setWorkingParameter("saml_count_login_steps", 1)
298 
299  post_login_result = self.samlExtensionPostLogin(configurationAttributes, find_user_by_uid)
300  print "Asimba. Authenticate for step 1. post_login_result: '%s'" % post_login_result
301 
302  return post_login_result
303  elif saml_enroll_all_user_attr:
304  # Convert SAML response to user entry
305  newUser = self.getMappedAllAttributesUser(saml_response_attributes)
306 
307  saml_user_uid = self.getNameId(samlResponse, newUser)
308  if saml_user_uid == None:
309  return False
310 
311  self.setDefaultUid(newUser, saml_user_uid)
312  newUser.setAttribute("oxExternalUid", "saml:%s" % saml_user_uid)
313 
314  print "Asimba. Authenticate for step 1. Attempting to find user by oxExternalUid: saml:%s" % saml_user_uid
315 
316  # Check if there is user with specified saml_user_uid
317  find_user_by_uid = userService.getUserByAttribute("oxExternalUid", "saml:%s" % saml_user_uid)
318  if find_user_by_uid == None:
319  # Auto user enrollment
320  print "Asimba. Authenticate for step 1. There is no user in LDAP. Adding user to local LDAP"
321 
322  print "Asimba. Authenticate for step 1. Attempting to add user '%s' with next attributes: '%s'" % (saml_user_uid, newUser.getCustomAttributes())
323  user_unique = self.checkUserUniqueness(newUser)
324  if not user_unique:
325  print "Asimba. Authenticate for step 1. Failed to add user: '%s'. User not unique" % newUser.getUserId()
326  facesMessages = CdiUtil.bean(FacesMessages)
327  facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to enroll. User with same key attributes exist already")
328  facesMessages.setKeepMessages()
329  return False
330 
331  find_user_by_uid = userService.addUser(newUser, True)
332  print "Asimba. Authenticate for step 1. Added new user with UID: '%s'" % find_user_by_uid.getUserId()
333  else:
334  if self.updateUser:
335  print "Asimba. Authenticate for step 1. Attempting to update user '%s' with next attributes: '%s'" % (saml_user_uid, newUser.getCustomAttributes())
336  find_user_by_uid.setCustomAttributes(newUser.getCustomAttributes())
337  userService.updateUser(find_user_by_uid)
338  print "Asimba. Authenticate for step 1. Updated user with UID: '%s'" % saml_user_uid
339 
340  found_user_name = find_user_by_uid.getUserId()
341  print "Asimba. Authenticate for step 1. found_user_name: '%s'" % found_user_name
342 
343  user_authenticated = authenticationService.authenticate(found_user_name)
344  if user_authenticated == False:
345  print "Asimba. Authenticate for step 1. Failed to authenticate user"
346  return False
347 
348  print "Asimba. Authenticate for step 1. Setting count steps to 1"
349  identity.setWorkingParameter("saml_count_login_steps", 1)
350 
351  post_login_result = self.samlExtensionPostLogin(configurationAttributes, find_user_by_uid)
352  print "Asimba. Authenticate for step 1. post_login_result: '%s'" % post_login_result
353 
354  return post_login_result
355  else:
356  if saml_user_uid == None:
357  return False
358 
359  # Check if the is user with specified saml_user_uid
360  print "Asimba. Authenticate for step 1. Attempting to find user by uid: '%s'" % saml_user_uid
361 
362  find_user_by_uid = userService.getUser(saml_user_uid)
363  if find_user_by_uid == None:
364  print "Asimba. Authenticate for step 1. Failed to find user"
365  return False
366 
367  found_user_name = find_user_by_uid.getUserId()
368  print "Asimba. Authenticate for step 1. found_user_name: '%s'" % found_user_name
369 
370  user_authenticated = authenticationService.authenticate(found_user_name)
371  if user_authenticated == False:
372  print "Asimba. Authenticate for step 1. Failed to authenticate user"
373  return False
374 
375  print "Asimba. Authenticate for step 1. Setting count steps to 1"
376  identity.setWorkingParameter("saml_count_login_steps", 1)
377 
378  post_login_result = self.samlExtensionPostLogin(configurationAttributes, find_user_by_uid)
379  print "Asimba. Authenticate for step 1. post_login_result: '%s'" % post_login_result
380 
381  return post_login_result
382  elif (step == 2):
383  print "Asimba. Authenticate for step 2"
384 
385  sessionAttributes = identity.getSessionId().getSessionAttributes()
386  if (sessionAttributes == None) or not sessionAttributes.containsKey("saml_user_uid"):
387  print "Asimba. Authenticate for step 2. saml_user_uid is empty"
388  return False
389 
390  saml_user_uid = sessionAttributes.get("saml_user_uid")
391  passed_step1 = StringHelper.isNotEmptyString(saml_user_uid)
392  if not passed_step1:
393  return False
394 
395  user_name = credentials.getUsername()
396  user_password = credentials.getPassword()
397 
398  logged_in = False
399  if StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password):
400  logged_in = authenticationService.authenticate(user_name, user_password)
401 
402  if not logged_in:
403  return False
404 
405  # Check if there is user which has saml_user_uid
406  # Avoid mapping Saml account to more than one IDP account
407  find_user_by_uid = userService.getUserByAttribute("oxExternalUid", "saml:%s" % saml_user_uid)
408 
409  if find_user_by_uid == None:
410  # Add saml_user_uid to user one id UIDs
411  find_user_by_uid = userService.addUserAttribute(user_name, "oxExternalUid", "saml:%s" % saml_user_uid)
412  if find_user_by_uid == None:
413  print "Asimba. Authenticate for step 2. Failed to update current user"
414  return False
415 
416  post_login_result = self.samlExtensionPostLogin(configurationAttributes, find_user_by_uid)
417  print "Asimba. Authenticate for step 2. post_login_result: '%s'" % post_login_result
418 
419  return post_login_result
420  else:
421  found_user_name = find_user_by_uid.getUserId()
422  print "Asimba. Authenticate for step 2. found_user_name: '%s'" % found_user_name
423 
424  if StringHelper.equals(user_name, found_user_name):
425  post_login_result = self.samlExtensionPostLogin(configurationAttributes, find_user_by_uid)
426  print "Asimba. Authenticate for step 2. post_login_result: '%s'" % post_login_result
427 
428  return post_login_result
429 
430  return False
431  else:
432  return False
433 

◆ checkUserUniqueness()

def SamlExternalAuthenticator.PersonAuthentication.checkUserUniqueness (   self,
  user 
)
651  def checkUserUniqueness(self, user):
652  if self.userEnforceAttributesUniqueness == None:
653  return True
654 
655  userService = CdiUtil.bean(UserService)
656 
657  # Prepare user object to search by pattern
658  userBaseDn = userService.getDnForUser(None)
659 
660  userToSearch = User()
661  userToSearch.setDn(userBaseDn)
662 
663  for userAttributeName in self.userEnforceAttributesUniqueness:
664  attribute_values_list = user.getAttributeValues(userAttributeName)
665  if (attribute_values_list != None) and (attribute_values_list.size() > 0):
666  userToSearch.setAttribute(userAttributeName, attribute_values_list)
667 
668  users = userService.getUsersBySample(userToSearch, 1)
669  if users.size() > 0:
670  return False
671 
672  return True
673 

◆ destroy()

def SamlExternalAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
114  def destroy(self, configurationAttributes):
115  print "Asimba. Destroy"
116  print "Asimba. Destroyed successfully"
117  return True
118 

◆ generateNameUid()

def SamlExternalAuthenticator.PersonAuthentication.generateNameUid (   self,
  user 
)
763  def generateNameUid(self, user):
764  if self.userEnforceAttributesUniqueness == None:
765  print "Asimba. Build local external uid. User enforce attributes uniqueness not specified"
766  return None
767 
768  sb = StringBuilder()
769  first = True
770  for userAttributeName in self.userEnforceAttributesUniqueness:
771  if not first:
772  sb.append("!")
773  first = False
774  attribute_values_list = user.getAttributeValues(userAttributeName)
775  if (attribute_values_list != None) and (attribute_values_list.size() > 0):
776  first_attribute_value = attribute_values_list.get(0)
777  sb.append(first_attribute_value)
778 
779  return sb.toString()
780 

◆ getAlternativeAuthenticationMethod()

def SamlExternalAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
125  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
126  return None
127 

◆ getApiVersion()

def SamlExternalAuthenticator.PersonAuthentication.getApiVersion (   self)
119  def getApiVersion(self):
120  return 1
121 

◆ getClientConfiguration()

def SamlExternalAuthenticator.PersonAuthentication.getClientConfiguration (   self,
  configurationAttributes,
  requestParameters 
)
519  def getClientConfiguration(self, configurationAttributes, requestParameters):
520  # Get client configuration
521  if configurationAttributes.containsKey("saml_client_configuration_attribute"):
522  saml_client_configuration_attribute = configurationAttributes.get("saml_client_configuration_attribute").getValue2()
523  print "Asimba. GetClientConfiguration. Using client attribute: '%s'" % saml_client_configuration_attribute
524 
525  if requestParameters == None:
526  return None
527 
528  client_id = None
529  client_id_array = requestParameters.get("client_id")
530  if ArrayHelper.isNotEmpty(client_id_array) and StringHelper.isNotEmptyString(client_id_array[0]):
531  client_id = client_id_array[0]
532 
533  if client_id == None:
534  identity = CdiUtil.bean(Identity)
535  if identity.getSessionId() != None:
536  client_id = identity.getSessionId().getSessionAttributes().get("client_id")
537 
538  if client_id == None:
539  print "Asimba. GetClientConfiguration. client_id is empty"
540  return None
541 
542  clientService = CdiUtil.bean(ClientService)
543  client = clientService.getClient(client_id)
544  if client == None:
545  print "Asimba. GetClientConfiguration. Failed to find client '%s' in local LDAP" % client_id
546  return None
547 
548  saml_client_configuration = clientService.getCustomAttribute(client, saml_client_configuration_attribute)
549  if (saml_client_configuration == None) or StringHelper.isEmpty(saml_client_configuration.getValue()):
550  print "Asimba. GetClientConfiguration. Client '%s' attribute '%s' is empty" % ( client_id, saml_client_configuration_attribute )
551  else:
552  print "Asimba. GetClientConfiguration. Client '%s' attribute '%s' is '%s'" % ( client_id, saml_client_configuration_attribute, saml_client_configuration )
553  return saml_client_configuration
554 
555  return None
556 

◆ getCountAuthenticationSteps()

def SamlExternalAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
473  def getCountAuthenticationSteps(self, configurationAttributes):
474  identity = CdiUtil.bean(Identity)
475  if identity.isSetWorkingParameter("saml_count_login_steps"):
476  return identity.getWorkingParameter("saml_count_login_steps")
477 
478  return 2
479 

◆ getCurrentSamlConfiguration()

def SamlExternalAuthenticator.PersonAuthentication.getCurrentSamlConfiguration (   self,
  currentSamlConfiguration,
  configurationAttributes,
  requestParameters 
)
557  def getCurrentSamlConfiguration(self, currentSamlConfiguration, configurationAttributes, requestParameters):
558  saml_client_configuration = self.getClientConfiguration(configurationAttributes, requestParameters)
559  if saml_client_configuration == None:
560  return currentSamlConfiguration
561 
562  saml_client_configuration_value = json.loads(saml_client_configuration.getValue())
563 
564  client_asimba_saml_certificate = None
565  client_asimba_saml_certificate_file = saml_client_configuration_value["asimba_saml_certificate_file"]
566  if StringHelper.isNotEmpty(client_asimba_saml_certificate_file):
567  client_asimba_saml_certificate = self.loadCeritificate(client_asimba_saml_certificate_file)
568  if StringHelper.isEmpty(client_asimba_saml_certificate):
569  print "Asimba. BuildClientSamlConfiguration. File with x509 certificate should be not empty. Using default configuration"
570  return currentSamlConfiguration
571 
572  clientSamlConfiguration = currentSamlConfiguration.clone()
573 
574  if client_asimba_saml_certificate != None:
575  clientSamlConfiguration.loadCertificateFromString(client_asimba_saml_certificate)
576 
577  client_asimba_entity_id = saml_client_configuration_value["asimba_entity_id"]
578  clientSamlConfiguration.setIssuer(client_asimba_entity_id)
579 
580  saml_use_authn_context = saml_client_configuration_value["saml_use_authn_context"]
581  client_use_saml_use_authn_context = StringHelper.toBoolean(saml_use_authn_context, True)
582  clientSamlConfiguration.setUseRequestedAuthnContext(client_use_saml_use_authn_context)
583 
584  return clientSamlConfiguration
585 

◆ getExtraParametersForStep()

def SamlExternalAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
467  def getExtraParametersForStep(self, configurationAttributes, step):
468  if (step == 2):
469  return Arrays.asList("saml_user_uid")
470 
471  return None
472 

◆ getMappedAllAttributesUser()

def SamlExternalAuthenticator.PersonAuthentication.getMappedAllAttributesUser (   self,
  saml_response_attributes 
)
708  def getMappedAllAttributesUser(self, saml_response_attributes):
709  user = User()
710 
711  # Set custom object classes
712  if self.userObjectClasses != None:
713  print "Asimba. Get mapped all attributes user. User custom objectClasses to add persons: '%s'" % Util.array2ArrayList(self.userObjectClasses)
714  user.setCustomObjectClasses(self.userObjectClasses)
715 
716  # Prepare map to do quick mapping
717  attributeService = CdiUtil.bean(AttributeService)
718  ldapAttributes = attributeService.getAllAttributes()
719  samlUriToAttributesMap = HashMap()
720  for ldapAttribute in ldapAttributes:
721  saml2Uri = ldapAttribute.getSaml2Uri()
722  if saml2Uri == None:
723  saml2Uri = attributeService.getDefaultSaml2Uri(ldapAttribute.getName())
724  samlUriToAttributesMap.put(saml2Uri, ldapAttribute.getName())
725 
726  customAttributes = ArrayList()
727  for key in saml_response_attributes.keySet():
728  ldapAttributeName = samlUriToAttributesMap.get(key)
729  if ldapAttributeName == None:
730  print "Asimba. Get mapped all attributes user. Skipping saml attribute: '%s'" % key
731  continue
732 
733  if StringHelper.equalsIgnoreCase(ldapAttributeName, "uid"):
734  continue
735 
736  attribute = CustomAttribute(ldapAttributeName)
737  attribute.setValues(saml_response_attributes.get(key))
738  customAttributes.add(attribute)
739 
740  user.setCustomAttributes(customAttributes)
741 
742  return user
743 

◆ getMappedUser()

def SamlExternalAuthenticator.PersonAuthentication.getMappedUser (   self,
  configurationAttributes,
  requestParameters,
  saml_response_attributes 
)
674  def getMappedUser(self, configurationAttributes, requestParameters, saml_response_attributes):
675  # Convert Saml result attributes keys to lover case
676  saml_response_normalized_attributes = HashMap()
677  for saml_response_attribute_entry in saml_response_attributes.entrySet():
678  saml_response_normalized_attributes.put(StringHelper.toLowerCase(saml_response_attribute_entry.getKey()), saml_response_attribute_entry.getValue())
679 
680  currentAttributesMapping = self.prepareCurrentAttributesMapping(self.attributesMapping, configurationAttributes, requestParameters)
681  print "Asimba. Get mapped user. Using next attributes mapping '%s'" % currentAttributesMapping
682 
683  newUser = User()
684 
685  # Set custom object classes
686  if self.userObjectClasses != None:
687  print "Asimba. Get mapped user. User custom objectClasses to add persons: '%s'" % Util.array2ArrayList(self.userObjectClasses)
688  newUser.setCustomObjectClasses(self.userObjectClasses)
689 
690  for attributesMappingEntry in currentAttributesMapping.entrySet():
691  idpAttribute = attributesMappingEntry.getKey()
692  localAttribute = attributesMappingEntry.getValue()
693 
694  if self.debugEnrollment:
695  print "Asimba. Get mapped user. Trying to map '%s' into '%s'" % (idpAttribute, localAttribute)
696 
697  localAttributeValue = saml_response_normalized_attributes.get(idpAttribute)
698  if localAttributeValue != None:
699  if self.debugEnrollment:
700  print "Asimba. Get mapped user. Setting attribute '%s' value '%s'" % (localAttribute, localAttributeValue)
701  newUser.setAttribute(localAttribute, localAttributeValue)
702  else:
703  if newUser.getAttribute(localAttribute) == None:
704  newUser.setAttribute(localAttribute, ArrayList())
705 
706  return newUser
707 

◆ getNameId()

def SamlExternalAuthenticator.PersonAuthentication.getNameId (   self,
  samlResponse,
  newUser 
)
744  def getNameId(self, samlResponse, newUser):
745  if self.generateNameId:
746  saml_user_uid = self.generateNameUid(newUser)
747  else:
748  saml_user_uid = self.getSamlNameId(samlResponse)
749 
750  return saml_user_uid
751 

◆ getPageForStep()

def SamlExternalAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
480  def getPageForStep(self, configurationAttributes, step):
481  if (step == 1):
482  saml_allow_basic_login = False
483  if configurationAttributes.containsKey("saml_allow_basic_login"):
484  saml_allow_basic_login = StringHelper.toBoolean(configurationAttributes.get("saml_allow_basic_login").getValue2(), False)
485 
486  if saml_allow_basic_login:
487  return "/login.xhtml"
488  else:
489  return "/auth/saml/samllogin.xhtml"
490 
491  return "/auth/saml/samlpostlogin.xhtml"
492 

◆ getSamlNameId()

def SamlExternalAuthenticator.PersonAuthentication.getSamlNameId (   self,
  samlResponse 
)
752  def getSamlNameId(self, samlResponse):
753  saml_response_name_id = samlResponse.getNameId()
754  if StringHelper.isEmpty(saml_response_name_id):
755  print "Asimba. Get Saml response. saml_response_name_id is invalid"
756  return None
757 
758  print "Asimba. Get Saml response. saml_response_name_id: '%s'" % saml_response_name_id
759 
760  # Use persistent Id as saml_user_uid
761  return saml_response_name_id
762 

◆ init()

def SamlExternalAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
29  def init(self, configurationAttributes):
30  print "Asimba. Initialization"
31 
32  asimba_saml_certificate_file = configurationAttributes.get("asimba_saml_certificate_file").getValue2()
33  saml_idp_sso_target_url = configurationAttributes.get("saml_idp_sso_target_url").getValue2()
34  asimba_entity_id = configurationAttributes.get("asimba_entity_id").getValue2()
35  saml_use_authn_context = StringHelper.toBoolean(configurationAttributes.get("saml_use_authn_context").getValue2(), True)
36  if saml_use_authn_context:
37  saml_name_identifier_format = configurationAttributes.get("saml_name_identifier_format").getValue2()
38  else:
39  saml_name_identifier_format = None
40 
41  asimba_saml_certificate = self.loadCeritificate(asimba_saml_certificate_file)
42  if StringHelper.isEmpty(asimba_saml_certificate):
43  print "Asimba. Initialization. File with x509 certificate should be not empty"
44  return False
45 
46  samlConfiguration = SamlConfiguration()
47 
48  # Set the issuer of the authentication request. This would usually be the URL of the issuing web application
49  samlConfiguration.setIssuer(asimba_entity_id)
50 
51  # Tells the IdP to return a persistent identifier for the user
52  samlConfiguration.setNameIdentifierFormat(saml_name_identifier_format)
53 
54  # The URL at the Identity Provider where to the authentication request should be sent
55  samlConfiguration.setIdpSsoTargetUrl(saml_idp_sso_target_url)
56 
57  # Enablediable RequestedAuthnContext
58  samlConfiguration.setUseRequestedAuthnContext(saml_use_authn_context)
59 
60  # Load x509 certificate
61  samlConfiguration.loadCertificateFromString(asimba_saml_certificate)
62 
63  self.samlConfiguration = samlConfiguration
64 
65  self.generateNameId = False
66  if configurationAttributes.containsKey("saml_generate_name_id"):
67  self.generateNameId = StringHelper.toBoolean(configurationAttributes.get("saml_generate_name_id").getValue2(), False)
68  print "Asimba. Initialization. The property saml_generate_name_id is %s" % self.generateNameId
69 
70  self.updateUser = False
71  if configurationAttributes.containsKey("saml_update_user"):
72  self.updateUser = StringHelper.toBoolean(configurationAttributes.get("saml_update_user").getValue2(), False)
73 
74  print "Asimba. Initialization. The property saml_update_user is %s" % self.updateUser
75 
76  self.userObjectClasses = None
77  if configurationAttributes.containsKey("user_object_classes"):
78  self.userObjectClasses = self.prepareUserObjectClasses(configurationAttributes)
79 
80  self.userEnforceAttributesUniqueness = None
81  if configurationAttributes.containsKey("enforce_uniqueness_attr_list"):
82  self.userEnforceAttributesUniqueness = self.prepareUserEnforceUniquenessAttributes(configurationAttributes)
83 
84  self.attributesMapping = None
85  if configurationAttributes.containsKey("saml_idp_attributes_mapping"):
86  saml_idp_attributes_mapping = configurationAttributes.get("saml_idp_attributes_mapping").getValue2()
87  if StringHelper.isEmpty(saml_idp_attributes_mapping):
88  print "Asimba. Initialization. The property saml_idp_attributes_mapping is empty"
89  return False
90 
91  self.attributesMapping = self.prepareAttributesMapping(saml_idp_attributes_mapping)
92  if self.attributesMapping == None:
93  print "Asimba. Initialization. The attributes mapping isn't valid"
94  return False
95 
96  self.samlExtensionModule = None
97  if configurationAttributes.containsKey("saml_extension_module"):
98  saml_extension_module_name = configurationAttributes.get("saml_extension_module").getValue2()
99  try:
100  self.samlExtensionModule = __import__(saml_extension_module_name)
101  saml_extension_module_init_result = self.samlExtensionModule.init(configurationAttributes)
102  if not saml_extension_module_init_result:
103  return False
104  except ImportError, ex:
105  print "Asimba. Initialization. Failed to load saml_extension_module: '%s'" % saml_extension_module_name
106  print "Asimba. Initialization. Unexpected error:", ex
107  return False
108 
109  self.debugEnrollment = False
110 
111  print "Asimba. Initialized successfully"
112  return True
113 

◆ isPassedStep1()

def SamlExternalAuthenticator.PersonAuthentication.isPassedStep1 ( )
496  def isPassedStep1():
497  identity = CdiUtil.bean(Identity)
498  credentials = identity.getCredentials()
499  user_name = credentials.getUsername()
500  passed_step1 = StringHelper.isNotEmptyString(user_name)
501 
502  return passed_step1
503 

◆ isValidAuthenticationMethod()

def SamlExternalAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
122  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
123  return True
124 

◆ loadCeritificate()

def SamlExternalAuthenticator.PersonAuthentication.loadCeritificate (   self,
  asimba_saml_certificate_file 
)
504  def loadCeritificate(self, asimba_saml_certificate_file):
505  asimba_saml_certificate = None
506 
507  # Load certificate from file
508  f = open(asimba_saml_certificate_file, 'r')
509  try:
510  asimba_saml_certificate = f.read()
511  except:
512  print "Asimba. Failed to load certificate from file: '%s'" % asimba_saml_certificate_file
513  return None
514  finally:
515  f.close()
516 
517  return asimba_saml_certificate
518 

◆ logout()

def SamlExternalAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
493  def logout(self, configurationAttributes, requestParameters):
494  return True
495 

◆ prepareAttributesMapping()

def SamlExternalAuthenticator.PersonAuthentication.prepareAttributesMapping (   self,
  saml_idp_attributes_mapping 
)
586  def prepareAttributesMapping(self, saml_idp_attributes_mapping):
587  saml_idp_attributes_mapping_json = json.loads(saml_idp_attributes_mapping)
588 
589  if len(saml_idp_attributes_mapping_json) == 0:
590  print "Asimba. PrepareAttributesMapping. There is no attributes mapping specified in saml_idp_attributes_mapping property"
591  return None
592 
593  attributeMapping = IdentityHashMap()
594  for local_attribute_name in saml_idp_attributes_mapping_json:
595  localAttribute = StringHelper.toLowerCase(local_attribute_name)
596  for idp_attribute_name in saml_idp_attributes_mapping_json[local_attribute_name]:
597  idpAttribute = StringHelper.toLowerCase(idp_attribute_name)
598  attributeMapping.put(idpAttribute, localAttribute)
599 
600  return attributeMapping
601 

◆ prepareCurrentAttributesMapping()

def SamlExternalAuthenticator.PersonAuthentication.prepareCurrentAttributesMapping (   self,
  currentAttributesMapping,
  configurationAttributes,
  requestParameters 
)
620  def prepareCurrentAttributesMapping(self, currentAttributesMapping, configurationAttributes, requestParameters):
621  saml_client_configuration = self.getClientConfiguration(configurationAttributes, requestParameters)
622  if saml_client_configuration == None:
623  return currentAttributesMapping
624 
625  saml_client_configuration_value = json.loads(saml_client_configuration.getValue())
626 
627  clientAttributesMapping = self.prepareAttributesMapping(saml_client_configuration_value["saml_idp_attributes_mapping"])
628  if clientAttributesMapping == None:
629  print "Asimba. PrepareCurrentAttributesMapping. Client attributes mapping is invalid. Using default one"
630  return currentAttributesMapping
631 
632  return clientAttributesMapping
633 

◆ prepareForStep()

def SamlExternalAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
434  def prepareForStep(self, configurationAttributes, requestParameters, step):
435  authenticationService = CdiUtil.bean(AuthenticationService)
436 
437  if (step == 1):
438  print "Asimba. Prepare for step 1"
439 
440  httpService = CdiUtil.bean(HttpService)
441  facesContext = CdiUtil.bean(FacesContext)
442  request = facesContext.getExternalContext().getRequest()
443  assertionConsumerServiceUrl = httpService.constructServerUrl(request) + "/postlogin.htm"
444  print "Asimba. Prepare for step 1. Prepared assertionConsumerServiceUrl: '%s'" % assertionConsumerServiceUrl
445 
446  currentSamlConfiguration = self.getCurrentSamlConfiguration(self.samlConfiguration, configurationAttributes, requestParameters)
447  if currentSamlConfiguration == None:
448  print "Asimba. Prepare for step 1. Client saml configuration is invalid"
449  return False
450 
451  # Generate an AuthRequest and send it to the identity provider
452  samlAuthRequest = AuthRequest(currentSamlConfiguration)
453  external_auth_request_uri = currentSamlConfiguration.getIdpSsoTargetUrl() + "?SAMLRequest=" + samlAuthRequest.getRequest(True, assertionConsumerServiceUrl)
454 
455  print "Asimba. Prepare for step 1. external_auth_request_uri: '%s'" % external_auth_request_uri
456  facesService = CdiUtil.bean(FacesService)
457  facesService.redirectToExternalURL(external_auth_request_uri)
458 
459  return True
460  elif (step == 2):
461  print "Asimba. Prepare for step 2"
462 
463  return True
464  else:
465  return False
466 

◆ prepareUserEnforceUniquenessAttributes()

def SamlExternalAuthenticator.PersonAuthentication.prepareUserEnforceUniquenessAttributes (   self,
  configurationAttributes 
)
611  def prepareUserEnforceUniquenessAttributes(self, configurationAttributes):
612  enforce_uniqueness_attr_list = configurationAttributes.get("enforce_uniqueness_attr_list").getValue2()
613 
614  enforce_uniqueness_attr_list_array = StringHelper.split(enforce_uniqueness_attr_list, ",")
615  if ArrayHelper.isEmpty(enforce_uniqueness_attr_list_array):
616  return None
617 
618  return enforce_uniqueness_attr_list_array
619 

◆ prepareUserObjectClasses()

def SamlExternalAuthenticator.PersonAuthentication.prepareUserObjectClasses (   self,
  configurationAttributes 
)
602  def prepareUserObjectClasses(self, configurationAttributes):
603  user_object_classes = configurationAttributes.get("user_object_classes").getValue2()
604 
605  user_object_classes_list_array = StringHelper.split(user_object_classes, ",")
606  if ArrayHelper.isEmpty(user_object_classes_list_array):
607  return None
608 
609  return user_object_classes_list_array
610 

◆ samlExtensionPostLogin()

def SamlExternalAuthenticator.PersonAuthentication.samlExtensionPostLogin (   self,
  configurationAttributes,
  user 
)
634  def samlExtensionPostLogin(self, configurationAttributes, user):
635  if self.samlExtensionModule == None:
636  return True
637  try:
638  post_login_result = self.samlExtensionModule.postLogin(configurationAttributes, user)
639  print "Asimba. ExtensionPostlogin result: '%s'" % post_login_result
640 
641  return post_login_result
642  except Exception, ex:
643  print "Asimba. ExtensionPostlogin. Failed to execute postLogin method"
644  print "Asimba. ExtensionPostlogin. Unexpected error:", ex
645  return False
646  except java.lang.Throwable, ex:
647  print "Asimba. ExtensionPostlogin. Failed to execute postLogin method"
648  ex.printStackTrace()
649  return False
650 

◆ setDefaultUid()

def SamlExternalAuthenticator.PersonAuthentication.setDefaultUid (   self,
  user,
  saml_user_uid 
)
781  def setDefaultUid(self, user, saml_user_uid):
782  if StringHelper.isEmpty(user.getUserId()):
783  user.setUserId(saml_user_uid)
784 

メンバ詳解

◆ attributesMapping

SamlExternalAuthenticator.PersonAuthentication.attributesMapping

◆ currentTimeMillis

SamlExternalAuthenticator.PersonAuthentication.currentTimeMillis

◆ debugEnrollment

SamlExternalAuthenticator.PersonAuthentication.debugEnrollment

◆ generateNameId

SamlExternalAuthenticator.PersonAuthentication.generateNameId

◆ samlConfiguration

SamlExternalAuthenticator.PersonAuthentication.samlConfiguration

◆ samlExtensionModule

SamlExternalAuthenticator.PersonAuthentication.samlExtensionModule

◆ updateUser

SamlExternalAuthenticator.PersonAuthentication.updateUser

◆ userEnforceAttributesUniqueness

SamlExternalAuthenticator.PersonAuthentication.userEnforceAttributesUniqueness

◆ userObjectClasses

SamlExternalAuthenticator.PersonAuthentication.userObjectClasses

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