1
0
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:
WJH 2023-07-11 09:35:38 +08:00 committed by GitHub
parent c32ce41ce3
commit dda557bea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -32,11 +32,17 @@ from registration.models import notify_admins_on_activate_request, notify_admins
logger = logging.getLogger(__name__) 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) SHIBBOLETH_AFFILIATION_ROLE_MAP = getattr(settings, 'SHIBBOLETH_AFFILIATION_ROLE_MAP', False)
class Saml2Backend(ModelBackend): 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): def authenticate(self, session_info=None, attribute_mapping=None, create_unknown_user=True, **kwargs):
if session_info is None or attribute_mapping is None: 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) saml_user = SocialAuthUser.objects.get_by_provider_and_uid(SAML_PROVIDER_IDENTIFIER, name_id)
if saml_user: if saml_user:
try: user = self.get_user(saml_user.username)
user = User.objects.get(email=saml_user.username)
except User.DoesNotExist:
user = None
if not user: if not user:
# Means found user in social_auth_usersocialauth but not found user in EmailUser, # Means found user in social_auth_usersocialauth but not found user in EmailUser,
# delete it and recreate one. # delete it and recreate one.

View File

@ -24,7 +24,7 @@ if ENABLE_ADFS_LOGIN or ENABLE_MULTI_ADFS:
XMLSEC_BINARY_PATH = getattr(settings, 'SAML_XMLSEC_BINARY_PATH', '/usr/bin/xmlsec1') XMLSEC_BINARY_PATH = getattr(settings, 'SAML_XMLSEC_BINARY_PATH', '/usr/bin/xmlsec1')
CERTS_DIR = getattr(settings, 'SAML_CERTS_DIR', '/opt/seafile/seahub-data/certs') CERTS_DIR = getattr(settings, 'SAML_CERTS_DIR', '/opt/seafile/seahub-data/certs')
SAML_ATTRIBUTE_MAPPING = getattr(settings, 'SAML_ATTRIBUTE_MAPPING', {}) 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): def settings_check(func):