##// END OF EJS Templates
authentication: register global shared session key used for external authentication session data storeage....
authentication: register global shared session key used for external authentication session data storeage. - We'll have more plugins not only oauth so this should be a constant name, instead of repating the same name all over the code.

File last commit:

r3246:ef7f5bf1 default
r3247:3c175ca2 default
Show More
auth_rhodecode.py
149 lines | 5.6 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2012-2018 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
RhodeCode authentication plugin for built in internal auth
"""
import logging
auth: remove usage of pylons translator
r2098 from rhodecode.translation import _
project: added all source files and assets
r1
auth: refactor code and simplified instructions....
r1454 from rhodecode.authentication.base import RhodeCodeAuthPluginBase, hybrid_property
project: added all source files and assets
r1 from rhodecode.authentication.routes import AuthnPluginResourceBase
from rhodecode.lib.utils2 import safe_str
from rhodecode.model.db import User
log = logging.getLogger(__name__)
def plugin_factory(plugin_id, *args, **kwds):
plugin = RhodeCodeAuthPlugin(plugin_id)
return plugin
class RhodecodeAuthnResource(AuthnPluginResourceBase):
pass
class RhodeCodeAuthPlugin(RhodeCodeAuthPluginBase):
authentication: use registerd UID for plugin definition for more consistent loading of auth plugins.
r3246 uid = 'rhodecode'
project: added all source files and assets
r1
def includeme(self, config):
config.add_authn_plugin(self)
config.add_authn_resource(self.get_id(), RhodecodeAuthnResource(self))
config.add_view(
'rhodecode.authentication.views.AuthnPluginViewBase',
attr='settings_get',
templating: use .mako as extensions for template files.
r1282 renderer='rhodecode:templates/admin/auth/plugin_settings.mako',
project: added all source files and assets
r1 request_method='GET',
route_name='auth_home',
context=RhodecodeAuthnResource)
config.add_view(
'rhodecode.authentication.views.AuthnPluginViewBase',
attr='settings_post',
templating: use .mako as extensions for template files.
r1282 renderer='rhodecode:templates/admin/auth/plugin_settings.mako',
project: added all source files and assets
r1 request_method='POST',
route_name='auth_home',
context=RhodecodeAuthnResource)
def get_display_name(self):
auth-plugins: updated display names of plugins, and root resource.
r3234 return _('RhodeCode Internal')
project: added all source files and assets
r1
@hybrid_property
def name(self):
return "rhodecode"
def user_activation_state(self):
users: make AuthUser propert a method, and allow override of params.
r1997 def_user_perms = User.get_default_user().AuthUser().permissions['global']
project: added all source files and assets
r1 return 'hg.register.auto_activate' in def_user_perms
def allows_authentication_from(
self, user, allows_non_existing_user=True,
allowed_auth_plugins=None, allowed_auth_sources=None):
"""
Custom method for this auth that doesn't accept non existing users.
We know that user exists in our database.
"""
allows_non_existing_user = False
return super(RhodeCodeAuthPlugin, self).allows_authentication_from(
user, allows_non_existing_user=allows_non_existing_user)
def auth(self, userobj, username, password, settings, **kwargs):
if not userobj:
logging: use lazy parameter evaluation in log calls.
r3061 log.debug('userobj was:%s skipping', userobj)
project: added all source files and assets
r1 return None
if userobj.extern_type != self.name:
log.warning(
logging: use lazy parameter evaluation in log calls.
r3061 "userobj:%s extern_type mismatch got:`%s` expected:`%s`",
userobj, userobj.extern_type, self.name)
project: added all source files and assets
r1 return None
user_attrs = {
"username": userobj.username,
"firstname": userobj.firstname,
"lastname": userobj.lastname,
"groups": [],
authentication: introduce a group sync flag for plugins....
r2495 'user_group_sync': False,
project: added all source files and assets
r1 "email": userobj.email,
"admin": userobj.admin,
"active": userobj.active,
"active_from_extern": userobj.active,
"extern_name": userobj.user_id,
"extern_type": userobj.extern_type,
}
logging: use lazy parameter evaluation in log calls.
r3061 log.debug("User attributes:%s", user_attrs)
project: added all source files and assets
r1 if userobj.active:
from rhodecode.lib import auth
crypto_backend = auth.crypto_backend()
password_encoded = safe_str(password)
password_match, new_hash = crypto_backend.hash_check_with_upgrade(
auth-rhodecode: don't fail on bcrypt if user password is set to None....
r2153 password_encoded, userobj.password or '')
project: added all source files and assets
r1
if password_match and new_hash:
log.debug('user %s properly authenticated, but '
'requires hash change to bcrypt', userobj)
# if password match, and we use OLD deprecated hash,
# we should migrate this user hash password to the new hash
# we store the new returned by hash_check_with_upgrade function
user_attrs['_hash_migrate'] = new_hash
if userobj.username == User.DEFAULT_USER and userobj.active:
log.info(
auth: use more consistent logging on failed logs....
r2679 'user `%s` authenticated correctly as anonymous user', userobj.username)
project: added all source files and assets
r1 return user_attrs
elif userobj.username == username and password_match:
auth: use more consistent logging on failed logs....
r2679 log.info('user `%s` authenticated correctly', userobj.username)
project: added all source files and assets
r1 return user_attrs
auth: use more consistent logging on failed logs....
r2679 log.warn("user `%s` used a wrong password when "
"authenticating on this plugin", userobj.username)
project: added all source files and assets
r1 return None
else:
auth: made the message about not-active user consisten with token plugin
r441 log.warning(
'user `%s` failed to authenticate via %s, reason: account not '
'active.', username, self.name)
project: added all source files and assets
r1 return None
core: change from homebrew plugin system into pyramid machinery....
r3240
def includeme(config):
authentication: use registerd UID for plugin definition for more consistent loading of auth plugins.
r3246 plugin_id = 'egg:rhodecode-enterprise-ce#{}'.format(RhodeCodeAuthPlugin.uid)
core: change from homebrew plugin system into pyramid machinery....
r3240 plugin_factory(plugin_id).includeme(config)