Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions userportal/authentication.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from djangosaml2.backends import Saml2Backend
from django.contrib.auth.backends import RemoteUserBackend
from django.conf import settings


class staffSaml2Backend(Saml2Backend):
Expand Down Expand Up @@ -32,3 +33,22 @@ def configure_user(self, request, user, created=True):
user.is_staff = False
user.save()
return user


try:
from django_auth_ldap.backend import LDAPBackend

class staffLdapBackend(LDAPBackend):
def get_or_build_user(self, username, ldap_user):
user, built = super().get_or_build_user(username, ldap_user)

user.is_staff = False
for attribute, value in settings.LDAP_CONFIG['staff_attributes']:
if attribute in ldap_user.attrs.data and value in ldap_user.attrs.data[attribute]:
user.is_staff = True

return user, built


except ImportError:
pass
2 changes: 2 additions & 0 deletions userportal/settings/10-base.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@

LDAP_BASE_DN = 'dc=computecanada,dc=ca'

LDAP_CONFIG = {}

LOGIN_REDIRECT_URL = '/'

# Set to DEMO to True to enable demo mode with anonymized data
Expand Down
Loading