mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 14:50:29 +00:00
[thirdpart] Add shibboleth
This commit is contained in:
23
thirdpart/shibboleth/decorators.py
Executable file
23
thirdpart/shibboleth/decorators.py
Executable file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
Decorators to use with Shibboleth.
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.contrib import auth
|
||||
from middleware import ShibbolethRemoteUserMiddleware
|
||||
|
||||
def login_optional(func):
|
||||
"""
|
||||
Decorator to pull Shib attributes and log user in, if possible. Does not
|
||||
enforce login.
|
||||
"""
|
||||
def decorator(request,*args, **kwargs):
|
||||
#Do nothing if the remoteuser backend isn't activated
|
||||
if 'shibboleth.backends.ShibbolethRemoteUserBackend' not in settings.AUTHENTICATION_BACKENDS:
|
||||
pass
|
||||
else:
|
||||
shib = ShibbolethRemoteUserMiddleware()
|
||||
#Proccess the request with the Shib middlemare, which will log the
|
||||
#user in if we can.
|
||||
proc = shib.process_request(request)
|
||||
return func(request, *args, **kwargs)
|
||||
return decorator
|
Reference in New Issue
Block a user