1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 05:39:59 +00:00

[shib] Add affiliation role map

This commit is contained in:
zhengxie
2017-01-17 10:38:56 +08:00
parent 19beb9a7c8
commit 1832b2b0c0
2 changed files with 62 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib.auth.middleware import RemoteUserMiddleware
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
@@ -6,6 +7,7 @@ from django.http import HttpResponseRedirect
from shibboleth.app_settings import SHIB_ATTRIBUTE_MAP, LOGOUT_SESSION_KEY, SHIB_USER_HEADER
from seahub import auth
from seahub.base.accounts import User
from seahub.base.sudo_mode import update_sudo_mode_ts
from seahub.profile.models import Profile
@@ -77,6 +79,7 @@ class ShibbolethRemoteUserMiddleware(RemoteUserMiddleware):
user.save()
# call make profile.
self.make_profile(user, shib_meta)
self.update_user_role(user, shib_meta)
#setup session.
self.setup_session(request)
request.shib_login = True
@@ -142,6 +145,22 @@ class ShibbolethRemoteUserMiddleware(RemoteUserMiddleware):
p.save()
def update_user_role(self, user, shib_meta):
affiliation = shib_meta.get('affiliation', '')
if not affiliation:
return
try:
role_map = settings.SHIBBOLETH_AFFILIATION_ROLE_MAP
except AttributeError:
return
for e in affiliation.split(';'):
role = role_map.get(e)
if role:
User.objects.update_role(user.email, role)
return
def setup_session(self, request):
"""
If you want to add custom code to setup user sessions, you