Commit c98b0aaa authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Include auth providers basic logging support

Add logging statements on some important auth providers operations.

Complete auth providers logging support will be merged from the
feature-astakos-authpolicies branch which also includes additional auth
providers improvements.
parent 7a8eb29b
......@@ -44,6 +44,9 @@ from astakos.im import messages as astakos_messages
from astakos.im import auth_providers
from astakos.im.util import prepare_response, get_context
from astakos.im.views import requires_anonymous, render_response
import logging
logger = logging.getLogger(__name__)
def init_third_party_session(request):
......@@ -89,8 +92,12 @@ def handle_third_party_signup(request, userid, provider_module, third_party_key,
provider = auth_providers.get_provider(provider_module)
if not provider.is_available_for_create():
logger.info('%s signup is disabled.' %
(provider_module,))
messages.error(request,
_(astakos_messages.AUTH_PROVIDER_INVALID_LOGIN))
_(astakos_messages.AUTH_PROVIDER_INVALID_LOGIN)
% {'provider_name': provider.get_title_display,
'provider': provider_module})
return HttpResponseRedirect(reverse('login'))
# identifier not stored in astakos models, create pending profile
......@@ -151,6 +158,8 @@ def handle_third_party_login(request, provider_module, identifier,
user = request.user
if not request.user.can_add_auth_provider(provider_module,
identifier=identifier):
logger.info('%s failed to add %s: %r' % \
(user.log_display, provider_module, provider_info))
# TODO: handle existing uuid message separately
messages.error(request, _(astakos_messages.AUTH_PROVIDER_ADD_FAILED) +
u' ' + _(astakos_messages.AUTH_PROVIDER_ADD_EXISTS))
......@@ -159,6 +168,8 @@ def handle_third_party_login(request, provider_module, identifier,
user.add_auth_provider(provider_module, identifier=identifier,
affiliation=affiliation,
provider_info=provider_info)
logger.info('%s added %s: %r' % \
(user.log_display, provider_module, provider_info))
provider = auth_providers.get_provider(provider_module)
message = _(astakos_messages.AUTH_PROVIDER_ADDED) % provider.get_method_prompt_display
messages.success(request, message)
......
......@@ -88,6 +88,14 @@ def login(
tokens = request.META
third_party_key = get_pending_key(request)
shibboleth_headers = {}
for token in dir(Tokens):
if token == token.upper():
shibboleth_headers[token] = tokens.get(token, 'NOT_SET')
# log shibboleth headers
# TODO: info -> debug
logger.info("shibboleth request: %r" % shibboleth_headers)
try:
eppn = tokens.get(Tokens.SHIB_EPPN)
if not eppn:
......@@ -114,10 +122,10 @@ def login(
affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, 'Shibboleth')
email = tokens.get(Tokens.SHIB_MAIL, '')
#eppn, email, realname, affiliation = 'test@grnet-hq.admin.grnet.gr', 'test@grnet.gr', 'sff', None
provider_info = {'eppn': eppn, 'email': email, 'name': realname}
userid = eppn
try:
return handle_third_party_login(request, 'shibboleth',
eppn, provider_info,
......
......@@ -918,6 +918,11 @@ def remove_auth_provider(request, pk):
provider.delete()
message = astakos_messages.AUTH_PROVIDER_REMOVED % \
provider.settings.get_method_prompt_display
user = request.user
logger.info("%s deleted %s provider (%d): %r" % (user.log_display,
provider.module,
int(pk),
provider.info))
messages.success(request, message)
return HttpResponseRedirect(reverse('edit_profile'))
else:
......
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