Created
December 4, 2012 10:22
-
-
Save dmiyakawa/4202458 to your computer and use it in GitHub Desktop.
Code snnipet for moinmoinsaml with "GivenFamily" account support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = None | |
given = saml_attributes.get('givenName', None) | |
family = saml_attributes.get('sn', None) | |
if given and family: | |
# custom flow by me. | |
# If both given and family names are available, combine them | |
# into one and treat it as a MoinMoin candidate | |
logging.debug('Found both given and family names') | |
candidate = (given[0] + family[0]).replace(' ', '') | |
if user.isValidName(request, candidate): | |
name = candidate | |
logging.debug('SAML: Using %s as a MoinMoin name' % name) | |
# The original flow which has been the default. | |
if not name: | |
try: | |
name = saml_attributes[attribute][0] | |
except KeyError: | |
logging.debug('SAML: The attribute %s was not found in the assertion' | |
% attribute) | |
return CancelLogin(_('The assetion is missing required attributes')) | |
# check if the user is valid | |
name = name.replace(' ', '') # remove spaces | |
if not user.isValidName(request, name): | |
logging.debug('SAML: the name is not a valid MoinMoin name') | |
return CancelLogin(_('Invalid MoinMoin name')) | |
u = user.User(request, name=name, auth_method=self.name, auth_username=name) | |
u.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment