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