Commit e868759c by ichuang Committed by Carson Gee

fix external_auth @ssl_login_shortcut decorator to properly use retfun

parent 74b3a8ab
...@@ -180,7 +180,7 @@ def _external_login_or_signup(request, ...@@ -180,7 +180,7 @@ def _external_login_or_signup(request,
return _signup(request, eamap) return _signup(request, eamap)
else: else:
log.info('No user for %s yet. doing signup', eamap.external_email) log.info('No user for %s yet. doing signup', eamap.external_email)
return _signup(request, eamap) return _signup(request, eamap, retfun)
# We trust shib's authentication, so no need to authenticate using the password again # We trust shib's authentication, so no need to authenticate using the password again
uname = internal_user.username uname = internal_user.username
...@@ -198,7 +198,7 @@ def _external_login_or_signup(request, ...@@ -198,7 +198,7 @@ def _external_login_or_signup(request,
if user is None: if user is None:
# we want to log the failure, but don't want to log the password attempted: # we want to log the failure, but don't want to log the password attempted:
AUDIT_LOG.warning('External Auth Login failed for "%s"', uname) AUDIT_LOG.warning('External Auth Login failed for "%s"', uname)
return _signup(request, eamap) return _signup(request, eamap, retfun)
if not user.is_active: if not user.is_active:
AUDIT_LOG.warning('User "%s" is not active after external login', uname) AUDIT_LOG.warning('User "%s" is not active after external login', uname)
...@@ -237,7 +237,8 @@ def _flatten_to_ascii(txt): ...@@ -237,7 +237,8 @@ def _flatten_to_ascii(txt):
@ensure_csrf_cookie @ensure_csrf_cookie
def _signup(request, eamap): @cache_if_anonymous
def _signup(request, eamap, retfun=None):
""" """
Present form to complete for signup via external authentication. Present form to complete for signup via external authentication.
Even though the user has external credentials, he/she still needs Even though the user has external credentials, he/she still needs
...@@ -246,6 +247,9 @@ def _signup(request, eamap): ...@@ -246,6 +247,9 @@ def _signup(request, eamap):
eamap is an ExternalAuthMap object, specifying the external user eamap is an ExternalAuthMap object, specifying the external user
for which to complete the signup. for which to complete the signup.
retfun is a function to execute for the return value, if immediate
signup is used. That allows @ssl_login_shortcut() to work.
""" """
# save this for use by student.views.create_account # save this for use by student.views.create_account
request.session['ExternalAuthMap'] = eamap request.session['ExternalAuthMap'] = eamap
...@@ -352,10 +356,17 @@ def ssl_login_shortcut(fn): ...@@ -352,10 +356,17 @@ def ssl_login_shortcut(fn):
if not settings.FEATURES['AUTH_USE_MIT_CERTIFICATES']: if not settings.FEATURES['AUTH_USE_MIT_CERTIFICATES']:
return fn(*args, **kwargs) return fn(*args, **kwargs)
request = args[0] request = args[0]
if request.user and request.user.is_authenticated(): # don't re-authenticate
return fn(*args, **kwargs)
cert = _ssl_get_cert_from_request(request) cert = _ssl_get_cert_from_request(request)
if not cert: # no certificate information - show normal login window if not cert: # no certificate information - show normal login window
return fn(*args, **kwargs) return fn(*args, **kwargs)
def retfun():
return fn(*args, **kwargs)
(_user, email, fullname) = _ssl_dn_extract_info(cert) (_user, email, fullname) = _ssl_dn_extract_info(cert)
return _external_login_or_signup( return _external_login_or_signup(
request, request,
...@@ -363,7 +374,8 @@ def ssl_login_shortcut(fn): ...@@ -363,7 +374,8 @@ def ssl_login_shortcut(fn):
external_domain="ssl:MIT", external_domain="ssl:MIT",
credentials=cert, credentials=cert,
email=email, email=email,
fullname=fullname fullname=fullname,
retfun=retfun
) )
return wrapped return wrapped
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment