ENT-3798 Multiple_SSO_Accounts_Association_to_SAML_User (#26170)
This commit is contained in:
@@ -4,6 +4,8 @@ Utility functions for third_party_auth
|
||||
|
||||
from uuid import UUID
|
||||
from django.contrib.auth.models import User
|
||||
from enterprise.models import EnterpriseCustomerUser, EnterpriseCustomerIdentityProvider
|
||||
from . import provider
|
||||
|
||||
|
||||
def user_exists(details):
|
||||
@@ -30,6 +32,23 @@ def user_exists(details):
|
||||
return False
|
||||
|
||||
|
||||
def get_user_from_email(details):
|
||||
"""
|
||||
Return user with given details exist in the system.∂i
|
||||
|
||||
Arguments:
|
||||
details (dict): dictionary containing user email.
|
||||
|
||||
Returns:
|
||||
User: if user with given details exists, None otherwise.
|
||||
"""
|
||||
email = details.get('email')
|
||||
if email:
|
||||
return User.objects.filter(email=email).first()
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def convert_saml_slug_provider_id(provider):
|
||||
"""
|
||||
Provider id is stored with the backend type prefixed to it (ie "saml-")
|
||||
@@ -57,3 +76,19 @@ def validate_uuid4_string(uuid_string):
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def is_saml_provider(backend, kwargs):
|
||||
""" Verify that the third party provider uses SAML """
|
||||
current_provider = provider.Registry.get_from_pipeline({'backend': backend, 'kwargs': kwargs})
|
||||
saml_providers_list = list(provider.Registry.get_enabled_by_backend_name('tpa-saml'))
|
||||
return (current_provider and
|
||||
current_provider.slug in [saml_provider.slug for saml_provider in saml_providers_list]), current_provider
|
||||
|
||||
|
||||
def is_enterprise_customer_user(provider_id, user):
|
||||
""" Verify that the user linked to enterprise customer of current identity provider"""
|
||||
enterprise_idp = EnterpriseCustomerIdentityProvider.objects.get(provider_id=provider_id)
|
||||
|
||||
return EnterpriseCustomerUser.objects.filter(enterprise_customer=enterprise_idp.enterprise_customer,
|
||||
user_id=user.id).exists()
|
||||
|
||||
Reference in New Issue
Block a user