From a705fc94db58915dbf997e6f549c04ec6abbb728 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 3 Jun 2015 16:16:04 +0200 Subject: [PATCH] Fix all log to log unicode strings --- src/authentic2/attribute_aggregator/attributes.py | 15 ++++----------- src/authentic2/attribute_aggregator/core.py | 8 ++------ src/authentic2/attribute_aggregator/ldap_sources.py | 3 +-- src/authentic2/auth2_auth/auth2_ssl/views.py | 9 ++++----- src/authentic2/idp/saml/common.py | 3 +-- src/authentic2/idp/saml/saml2_endpoints.py | 12 ++++++------ src/authentic2/log_filters.py | 2 +- src/authentic2/managers.py | 2 +- src/authentic2/registration_backend/views.py | 2 +- src/authentic2/user_login_failure.py | 5 ++--- 10 files changed, 23 insertions(+), 38 deletions(-) diff --git a/src/authentic2/attribute_aggregator/attributes.py b/src/authentic2/attribute_aggregator/attributes.py index 5683869..7f46bbd 100644 --- a/src/authentic2/attribute_aggregator/attributes.py +++ b/src/authentic2/attribute_aggregator/attributes.py @@ -184,31 +184,24 @@ def provide_attributes_at_sso(request, user, audience, **kwargs): In parameter, the service provider id and the user authenticated.''' if not user or not audience: return None - logger.debug('provide_attributes_at_sso: search attribute for %s' \ - % user) - logger.debug('provide_attributes_at_sso: attributes for %s' \ - % audience) provider = None try: provider = LibertyProvider.objects.get(entity_id=audience) except LibertyProvider.DoesNotExist: - logger.debug('provide_attributes_at_sso: Provider with name %s not ' - 'found' % audience) + logger.debug('provide_attributes_at_sso: provider not found') attribute_policy = get_attribute_policy(provider) if not attribute_policy: - logger.debug('provide_attributes_at_sso: no attribute policy found ' - 'for %s' % audience) + logger.debug('provide_attributes_at_sso: no attribute policy found') return None p = load_or_create_user_profile(user=user) if not p: - logger.error('provide_attributes_at_sso: unable to load or create a ' - 'profile for %s' % user) + logger.error('provide_attributes_at_sso: unable to load or create a profile') return None # XXX: hack so that UserAttributeProfile.user is the same as request.user # which can contain monkey patched fields p.user = user - logger.debug('provide_attributes_at_sso: profile loaded %s' % p) + logger.debug('provide_attributes_at_sso: profile loaded %r', p) '''Returned dictionnary''' dic = dict() diff --git a/src/authentic2/attribute_aggregator/core.py b/src/authentic2/attribute_aggregator/core.py index 245c525..4748d13 100644 --- a/src/authentic2/attribute_aggregator/core.py +++ b/src/authentic2/attribute_aggregator/core.py @@ -282,8 +282,6 @@ def get_user_alias_in_source(user, source): def set_user_alias_in_source(user, source, name, force_change=False): from authentic2.attribute_aggregator.models import UserAliasInSource - logger.debug('set_user_alias_in_source: set alias %s for user %s in \ - source %s' % (name, user, source)) alias = None try: ''' @@ -306,11 +304,9 @@ def set_user_alias_in_source(user, source, name, force_change=False): pass else: if not force_change: - logger.warn('set_user_alias_in_source: \ - a user has already this alias, we do nothing.') + logger.warn('set_user_alias_in_source: a user has already this alias, we do nothing.') return None - logger.warn('set_user_alias_in_source: \ - a user has already this alias, we give it to %s.' % user) + logger.warn('set_user_alias_in_source: a user has already this alias, we take it.') alias.delete() try: alias = UserAliasInSource(user=user, name=name, source=source) diff --git a/src/authentic2/attribute_aggregator/ldap_sources.py b/src/authentic2/attribute_aggregator/ldap_sources.py index 1542ea2..5a860a5 100644 --- a/src/authentic2/attribute_aggregator/ldap_sources.py +++ b/src/authentic2/attribute_aggregator/ldap_sources.py @@ -55,8 +55,7 @@ def get_attributes(user, definitions=None, source=None, auth_source=False, **kwa if not user: logger.error('get_attributes: No user provided') return None - logger.debug('get_attributes: Searching attributes for user %s' \ - % user) + logger.debug('get_attributes: Searching attributes') from authentic2.attribute_aggregator.models import LdapSource sources = None diff --git a/src/authentic2/auth2_auth/auth2_ssl/views.py b/src/authentic2/auth2_auth/auth2_ssl/views.py index 4a815a3..a5fef7b 100644 --- a/src/authentic2/auth2_auth/auth2_ssl/views.py +++ b/src/authentic2/auth2_auth/auth2_ssl/views.py @@ -47,10 +47,9 @@ def handle_request(request): if 'do_creation' in request.session and not user \ and not request.user.is_authenticated(): from backends import SSLBackend - logger.info('Account creation treatment') if SSLBackend().create_user(ssl_info): user = authenticate(ssl_info=ssl_info) - logger.info('account created for %s' % user.username) + logger.info(u'account created for %s', user) else: logger.error('account creation failure') messages.add_message(request, messages.ERROR, @@ -85,9 +84,9 @@ def handle_request(request): # check that the SSL entry for the certificate is this user. # else, we make this certificate point on that user. if user.username != request.user.username: - logger.warning('[auth2_ssl]: The certificate belongs to %s, ' - 'but %s is logged with, we change the association!' - % (user.username, request.user.username)) + logger.warning(u'The certificate belongs to %s, ' + 'but %s is logged with, we change the association!', + user, request.user) from backends import SSLBackend cert = SSLBackend().get_certificate(ssl_info) cert.user = request.user diff --git a/src/authentic2/idp/saml/common.py b/src/authentic2/idp/saml/common.py index 0620939..f983249 100644 --- a/src/authentic2/idp/saml/common.py +++ b/src/authentic2/idp/saml/common.py @@ -21,8 +21,7 @@ def kill_django_sessions(session_key): try: for key in session_key: store = engine.SessionStore(key) - logging.debug('Killing session %s of user %s' % - (key, store[SESSION_KEY])) + logging.debug('Killing session %s', key) store.delete() except Exception, e: logging.error(e) diff --git a/src/authentic2/idp/saml/saml2_endpoints.py b/src/authentic2/idp/saml/saml2_endpoints.py index 67610b7..e656374 100644 --- a/src/authentic2/idp/saml/saml2_endpoints.py +++ b/src/authentic2/idp/saml/saml2_endpoints.py @@ -400,8 +400,8 @@ def build_assertion(request, login, nid_format='transient', attributes=None): kwargs = nameid2kwargs(login.assertion.subject.nameID) kwargs['entity_id'] = login.remoteProviderId kwargs['user'] = request.user - logger.info("sending nameID %(name_id_format)s: " - "%(name_id_content)s to %(entity_id)s for user %(user)s" % kwargs) + logger.info(u'sending nameID %(name_id_format)s: ' + '%(name_id_content)s to %(entity_id)s for user %(user)s' % kwargs) if attributes: logger.debug("add attributes to the assertion") saml2_add_attribute_values(login.assertion, attributes) @@ -421,8 +421,8 @@ def sso(request): logger.debug('called by GET') consent_answer = request.GET.get('consent_answer', '') if consent_answer: - logger.info('back from the consent page for federation with \ - answer %s' % consent_answer) + logger.info(u'back from the consent page for federation with answer ' + '%s', consent_answer) message = get_saml2_request_message(request) server = create_server(request) login = lasso.Login(server) @@ -431,7 +431,7 @@ def sso(request): logger.warn("missing query string") return HttpResponseForbidden("A SAMLv2 Single Sign On request need a " "query string") - logger.debug('processing sso request %r' % message) + logger.debug('processing sso request %r', message) policy = None signed = True while True: @@ -1032,6 +1032,7 @@ def idp_sso(request, provider_id=None, save=True, return_profile=False): if not provider_id: return error_redirect(request, N_('missing provider identifier')) + logger.info('start of an idp initiated sso toward %r', provider_id) server = create_server(request) login = lasso.Login(server) liberty_provider = load_provider(request, provider_id, @@ -1051,7 +1052,6 @@ def idp_sso(request, provider_id=None, save=True, return_profile=False): N_('you cannot login as %r as it does not exist'), username) else: user = request.user - logger.info('sso by %r', user) policy = get_sp_options_policy(liberty_provider) # Control assertion consumer binding if not policy: diff --git a/src/authentic2/log_filters.py b/src/authentic2/log_filters.py index 6c7d713..5d621c1 100644 --- a/src/authentic2/log_filters.py +++ b/src/authentic2/log_filters.py @@ -17,7 +17,7 @@ class RequestContextFilter(logging.Filter): request_id = self.DEFAULT_REQUEST_ID if not request is None: if hasattr(request, 'user') and request.user.is_authenticated(): - user = unicode(request.user).encode('utf-8') + user = unicode(request.user) ip = request.META['REMOTE_ADDR'] request_id = request.request_id record.user = user diff --git a/src/authentic2/managers.py b/src/authentic2/managers.py index dbc3907..a7954a7 100644 --- a/src/authentic2/managers.py +++ b/src/authentic2/managers.py @@ -40,7 +40,7 @@ class DeletedUserManager(models.Manager): user = deleted_user.user deleted_user.delete() user.delete() - logger.info(u'deleted account %s' % user) + logger.info(u'deleted account %s', user) class AuthenticationEventManager(models.Manager): def cleanup(self): diff --git a/src/authentic2/registration_backend/views.py b/src/authentic2/registration_backend/views.py index 4eefb95..f661e52 100644 --- a/src/authentic2/registration_backend/views.py +++ b/src/authentic2/registration_backend/views.py @@ -151,7 +151,7 @@ class DeleteView(TemplateView): or request.GET.get('next_url')) if 'submit' in request.POST: models.DeletedUser.objects.delete_user(request.user) - logger.info(u'deletion of account %s requested' % request.user) + logger.info(u'deletion of account %s requested', request.user) messages.info(request, _('Your account has been scheduled for deletion. You cannot use it anymore.')) return redirect(request, 'auth_logout') else: diff --git a/src/authentic2/user_login_failure.py b/src/authentic2/user_login_failure.py index ad05460..bc02580 100644 --- a/src/authentic2/user_login_failure.py +++ b/src/authentic2/user_login_failure.py @@ -17,7 +17,6 @@ def user_login_failure(identifier): count = cache.incr(key(identifier)) if app_settings.A2_LOGIN_FAILURE_COUNT_BEFORE_WARNING and count >= app_settings.A2_LOGIN_FAILURE_COUNT_BEFORE_WARNING: logger = logging.getLogger('authentic2.user_login_failure') - identifier = unicode(identifier) - identifier = identifier.encode('utf-8') - logger.warning('user %s failed to login more than %d times in a row', identifier, count) + logger.warning(u'user %s failed to login more than %d times in a row', + identifier, count) -- 2.1.4