Changeset - 6056c0e8244f
[Not reviewed]
default
0 4 0
Mads Kiilerich - 6 years ago 2020-03-22 23:05:36
mads@kiilerich.com
Grafted from: 74b0fae3756f
auth: don't use json for debug logging

The json formatting is just a source of error - it will for example crash if
there should be bytes anywhere.
4 files changed with 8 insertions and 9 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/auth_settings.py
Show inline comments
 
@@ -34,13 +34,12 @@ from webob.exc import HTTPFound
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib import auth_modules
 
from kallithea.lib import helpers as h
 
from kallithea.lib.auth import HasPermissionAnyDecorator, LoginRequired
 
from kallithea.lib.base import BaseController, render
 
from kallithea.lib.compat import formatted_json
 
from kallithea.model.db import Setting
 
from kallithea.model.forms import AuthSettingsForm
 
from kallithea.model.meta import Session
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -84,13 +83,13 @@ class AuthSettingsController(BaseControl
 
        if defaults:
 
            c.defaults.update(defaults)
 

	
 
        # we want to show , separated list of enabled plugins
 
        c.defaults['auth_plugins'] = ','.join(c.enabled_plugin_names)
 

	
 
        log.debug(formatted_json(defaults))
 
        log.debug('defaults: %s', defaults)
 
        return formencode.htmlfill.render(
 
            render('admin/auth/auth_settings.html'),
 
            defaults=c.defaults,
 
            errors=errors,
 
            prefix_error=False,
 
            encoding="UTF-8",
 
@@ -100,13 +99,13 @@ class AuthSettingsController(BaseControl
 
        self.__load_defaults()
 
        return self.__render(defaults=None, errors=None)
 

	
 
    def auth_settings(self):
 
        """POST create and store auth settings"""
 
        self.__load_defaults()
 
        log.debug("POST Result: %s", formatted_json(dict(request.POST)))
 
        log.debug("POST Result: %s", dict(request.POST))
 

	
 
        # First, parse only the plugin list (not the plugin settings).
 
        _auth_plugins_validator = AuthSettingsForm([]).fields['auth_plugins']
 
        try:
 
            new_enabled_plugins = _auth_plugins_validator.to_python(request.POST.get('auth_plugins'))
 
        except formencode.Invalid:
kallithea/lib/auth_modules/__init__.py
Show inline comments
 
@@ -17,13 +17,13 @@ Authentication modules
 

	
 
import importlib
 
import logging
 
import traceback
 

	
 
from kallithea.lib.auth import AuthUser, PasswordGenerator
 
from kallithea.lib.compat import formatted_json, hybrid_property
 
from kallithea.lib.compat import hybrid_property
 
from kallithea.lib.utils2 import str2bool
 
from kallithea.model.db import Setting, User
 
from kallithea.model.meta import Session
 
from kallithea.model.user import UserModel
 
from kallithea.model.user_group import UserGroupModel
 

	
 
@@ -345,13 +345,13 @@ def authenticate(username, password, env
 
        plugin_name = plugin.name
 
        plugin_settings = {}
 
        for v in plugin.plugin_settings():
 
            conf_key = "auth_%s_%s" % (plugin_name, v["name"])
 
            setting = Setting.get_by_name(conf_key)
 
            plugin_settings[v["name"]] = setting.app_settings_value if setting else None
 
        log.debug('Settings for auth plugin %s:\n%s', plugin_name, formatted_json(plugin_settings))
 
        log.debug('Settings for auth plugin %s: %s', plugin_name, plugin_settings)
 

	
 
        if not str2bool(plugin_settings["enabled"]):
 
            log.info("Authentication plugin %s is disabled, skipping for %s",
 
                     module, username)
 
            continue
 

	
kallithea/lib/auth_modules/auth_internal.py
Show inline comments
 
@@ -26,13 +26,13 @@ Original author and date, and relevant c
 
"""
 

	
 

	
 
import logging
 

	
 
from kallithea.lib import auth_modules
 
from kallithea.lib.compat import formatted_json, hybrid_property
 
from kallithea.lib.compat import hybrid_property
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class KallitheaAuthPlugin(auth_modules.KallitheaAuthPluginBase):
 
@@ -73,13 +73,13 @@ class KallitheaAuthPlugin(auth_modules.K
 
            "lastname": userobj.lastname,
 
            "groups": [],
 
            "email": userobj.email,
 
            "admin": userobj.admin,
 
            "extern_name": userobj.user_id,
 
        }
 
        log.debug(formatted_json(user_data))
 
        log.debug('user data: %s', user_data)
 

	
 
        from kallithea.lib import auth
 
        password_match = auth.check_password(password, userobj.password)
 
        if userobj.is_default_user:
 
            log.info('user %s authenticated correctly as anonymous user',
 
                     username)
kallithea/lib/auth_modules/auth_pam.py
Show inline comments
 
@@ -29,13 +29,13 @@ import pwd
 
import re
 
import socket
 
import threading
 
import time
 

	
 
from kallithea.lib import auth_modules
 
from kallithea.lib.compat import formatted_json, hybrid_property
 
from kallithea.lib.compat import hybrid_property
 

	
 

	
 
try:
 
    from pam import authenticate as pam_authenticate
 
except ImportError:
 
    # work around pam.authenticate missing in python-pam 1.8.*
 
@@ -139,12 +139,12 @@ class KallitheaAuthPlugin(auth_modules.K
 
                user_data["firstname"] = match.group('first_name')
 
                user_data["lastname"] = match.group('last_name')
 
        except Exception:
 
            log.warning("Cannot extract additional info for PAM user %s", username)
 
            pass
 

	
 
        log.debug("pamuser: \n%s", formatted_json(user_data))
 
        log.debug("pamuser: %s", user_data)
 
        log.info('user %s authenticated correctly', user_data['username'])
 
        return user_data
 

	
 
    def get_managed_fields(self):
 
        return ['username', 'password']
0 comments (0 inline, 0 general)