##// END OF EJS Templates
authn: Load legacy plugin ID's from DB and log them.
johbo -
r129:434a9ac0 default
parent child Browse files
Show More
@@ -1,85 +1,96 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2012-2016 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22
23 23 from pkg_resources import iter_entry_points
24 24 from pyramid.authentication import SessionAuthenticationPolicy
25 25
26 26 from rhodecode.authentication.registry import AuthenticationPluginRegistry
27 27 from rhodecode.authentication.routes import root_factory
28 28 from rhodecode.authentication.routes import AuthnRootResource
29 29 from rhodecode.config.routing import ADMIN_PREFIX
30 from rhodecode.model.settings import SettingsModel
30 31
31 32 log = logging.getLogger(__name__)
32 33
33 34
34 35 # TODO: Currently this is only used to discover the authentication plugins.
35 36 # Later on this may be used in a generic way to look up and include all kinds
36 37 # of supported enterprise plugins. Therefore this has to be moved and
37 38 # refactored to a real 'plugin look up' machinery.
38 39 # TODO: When refactoring this think about splitting it up into distinct
39 40 # discover, load and include phases.
40 41 def _discover_plugins(config, entry_point='enterprise.plugins1'):
41 42 _discovered_plugins = {}
42 43
43 44 for ep in iter_entry_points(entry_point):
44 45 plugin_id = 'egg:{}#{}'.format(ep.dist.project_name, ep.name)
45 46 log.debug('Plugin discovered: "%s"', plugin_id)
46 47 module = ep.load()
47 48 plugin = module(plugin_id=plugin_id)
48 49 config.include(plugin.includeme)
49 50
50 51 return _discovered_plugins
51 52
52 53
54 def _discover_legacy_plugins(config, prefix='py:'):
55 auth_plugins = SettingsModel().get_setting_by_name('auth_plugins')
56 enabled_plugins = auth_plugins.app_settings_value
57 legacy_plugins = [id_ for id_ in enabled_plugins if id_.startswith(prefix)]
58
59 log.debug('Trying to load these legacy authentication plugins {}'.format(
60 legacy_plugins))
61
62
53 63 def includeme(config):
54 64 # Set authentication policy.
55 65 authn_policy = SessionAuthenticationPolicy()
56 66 config.set_authentication_policy(authn_policy)
57 67
58 68 # Create authentication plugin registry and add it to the pyramid registry.
59 69 authn_registry = AuthenticationPluginRegistry(config.get_settings())
60 70 config.add_directive('add_authn_plugin', authn_registry.add_authn_plugin)
61 71 config.registry.registerUtility(authn_registry)
62 72
63 73 # Create authentication traversal root resource.
64 74 authn_root_resource = root_factory()
65 75 config.add_directive('add_authn_resource',
66 76 authn_root_resource.add_authn_resource)
67 77
68 78 # Add the authentication traversal route.
69 79 config.add_route('auth_home',
70 80 ADMIN_PREFIX + '/auth*traverse',
71 81 factory=root_factory)
72 82 # Add the authentication settings root views.
73 83 config.add_view('rhodecode.authentication.views.AuthSettingsView',
74 84 attr='index',
75 85 request_method='GET',
76 86 route_name='auth_home',
77 87 context=AuthnRootResource)
78 88 config.add_view('rhodecode.authentication.views.AuthSettingsView',
79 89 attr='auth_settings',
80 90 request_method='POST',
81 91 route_name='auth_home',
82 92 context=AuthnRootResource)
83 93
84 94 # Auto discover authentication plugins and include their configuration.
85 95 _discover_plugins(config)
96 _discover_legacy_plugins(config)
General Comments 0
You need to be logged in to leave comments. Login now