1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-17 06:27:28 +00:00
seahub/thirdpart/shibboleth/decorators.py
2014-12-25 18:29:13 +08:00

24 lines
797 B
Python
Executable File

"""
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