mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-22 08:47:22 +00:00
[fix] add get_user method for Saml2Backend (#5541)
This commit is contained in:
parent
c32ce41ce3
commit
dda557bea4
@ -32,11 +32,17 @@ from registration.models import notify_admins_on_activate_request, notify_admins
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
SAML_PROVIDER_IDENTIFIER = getattr(settings, 'SAML_PROVIDER_IDENTIFIER', '')
|
||||
SAML_PROVIDER_IDENTIFIER = getattr(settings, 'SAML_PROVIDER_IDENTIFIER', 'saml')
|
||||
SHIBBOLETH_AFFILIATION_ROLE_MAP = getattr(settings, 'SHIBBOLETH_AFFILIATION_ROLE_MAP', False)
|
||||
|
||||
|
||||
class Saml2Backend(ModelBackend):
|
||||
def get_user(self, username):
|
||||
try:
|
||||
user = User.objects.get(email=username)
|
||||
except User.DoesNotExist:
|
||||
user = None
|
||||
return user
|
||||
|
||||
def authenticate(self, session_info=None, attribute_mapping=None, create_unknown_user=True, **kwargs):
|
||||
if session_info is None or attribute_mapping is None:
|
||||
@ -59,10 +65,7 @@ class Saml2Backend(ModelBackend):
|
||||
|
||||
saml_user = SocialAuthUser.objects.get_by_provider_and_uid(SAML_PROVIDER_IDENTIFIER, name_id)
|
||||
if saml_user:
|
||||
try:
|
||||
user = User.objects.get(email=saml_user.username)
|
||||
except User.DoesNotExist:
|
||||
user = None
|
||||
user = self.get_user(saml_user.username)
|
||||
if not user:
|
||||
# Means found user in social_auth_usersocialauth but not found user in EmailUser,
|
||||
# delete it and recreate one.
|
||||
|
@ -24,7 +24,7 @@ if ENABLE_ADFS_LOGIN or ENABLE_MULTI_ADFS:
|
||||
XMLSEC_BINARY_PATH = getattr(settings, 'SAML_XMLSEC_BINARY_PATH', '/usr/bin/xmlsec1')
|
||||
CERTS_DIR = getattr(settings, 'SAML_CERTS_DIR', '/opt/seafile/seahub-data/certs')
|
||||
SAML_ATTRIBUTE_MAPPING = getattr(settings, 'SAML_ATTRIBUTE_MAPPING', {})
|
||||
SAML_PROVIDER_IDENTIFIER = getattr(settings, 'SAML_PROVIDER_IDENTIFIER', '')
|
||||
SAML_PROVIDER_IDENTIFIER = getattr(settings, 'SAML_PROVIDER_IDENTIFIER', 'saml')
|
||||
|
||||
|
||||
def settings_check(func):
|
||||
|
Loading…
Reference in New Issue
Block a user