Esempio n. 1
0
def add_federation(user, login=None, name_id=None, provider_id=None):
    assert name_id or (login and login.nameIdentifier), \
        'missing name identifier'
    name_id = name_id or login.nameIdentifier
    kwargs = models.nameid2kwargs(name_id)
    if provider_id:
        kwargs['idp'] = LibertyProvider.objects.get(entity_id=provider_id) \
            .identity_provider
    fed = LibertyFederation(user=user, **kwargs)
    fed.save()
    logger.debug('federation %s linked to user %s', fed.name_id_content, user)
    return fed
Esempio n. 2
0
def add_federation(user, login=None, name_id=None, provider_id=None):
    if not name_id:
        if not login:
            return None
        if not login.nameIdentifier:
            return None
        if not login.nameIdentifier.content or not login.nameIdentifier.nameQualifier:
            return None
        name_id = login.nameIdentifier
    qualifier = name_id.nameQualifier
    if not qualifier and login:
        qualifier = login.get_remoteProviderId()
    fed = LibertyFederation()
    fed.user = user
    fed.name_id_content = name_id.content
    fed.name_id_qualifier = qualifier
    fed.name_id_sp_name_qualifier = name_id.sPNameQualifier
    fed.name_id_format = name_id.format
    if provider_id:
        fed.idp_id = provider_id
    fed.save()
    return fed