##// END OF EJS Templates
auth-token: allow other authentication types to use auth-token....
marcink -
r440:23eb57a0 default
parent child Browse files
Show More
@@ -490,13 +490,19 b' def loadplugin(plugin_id):'
490 or None on failure.
490 or None on failure.
491 """
491 """
492 # TODO: Disusing pyramids thread locals to retrieve the registry.
492 # TODO: Disusing pyramids thread locals to retrieve the registry.
493 authn_registry = get_current_registry().getUtility(IAuthnPluginRegistry)
493 authn_registry = get_authn_registry()
494 plugin = authn_registry.get_plugin(plugin_id)
494 plugin = authn_registry.get_plugin(plugin_id)
495 if plugin is None:
495 if plugin is None:
496 log.error('Authentication plugin not found: "%s"', plugin_id)
496 log.error('Authentication plugin not found: "%s"', plugin_id)
497 return plugin
497 return plugin
498
498
499
499
500 def get_authn_registry(registry=None):
501 registry = registry or get_current_registry()
502 authn_registry = registry.getUtility(IAuthnPluginRegistry)
503 return authn_registry
504
505
500 def get_auth_cache_manager(custom_ttl=None):
506 def get_auth_cache_manager(custom_ttl=None):
501 return caches.get_cache_manager(
507 return caches.get_cache_manager(
502 'auth_plugins', 'rhodecode.authentication', custom_ttl)
508 'auth_plugins', 'rhodecode.authentication', custom_ttl)
@@ -520,7 +526,7 b' def authenticate(username, password, env'
520 % auth_type)
526 % auth_type)
521 headers_only = environ and not (username and password)
527 headers_only = environ and not (username and password)
522
528
523 authn_registry = get_current_registry().getUtility(IAuthnPluginRegistry)
529 authn_registry = get_authn_registry()
524 for plugin in authn_registry.get_plugins_for_authentication():
530 for plugin in authn_registry.get_plugins_for_authentication():
525 plugin.set_auth_type(auth_type)
531 plugin.set_auth_type(auth_type)
526 user = plugin.get_user(username)
532 user = plugin.get_user(username)
@@ -83,13 +83,17 b' class RhodeCodeAuthPlugin(RhodeCodeAuthP'
83 allowed_auth_plugins=None, allowed_auth_sources=None):
83 allowed_auth_plugins=None, allowed_auth_sources=None):
84 """
84 """
85 Custom method for this auth that doesn't accept empty users. And also
85 Custom method for this auth that doesn't accept empty users. And also
86 allows rhodecode and authtoken extern_type to auth with this. But only
86 allows users from all other active plugins to use it and also
87 via vcs mode
87 authenticate against it. But only via vcs mode
88 """
88 """
89 # only this and rhodecode plugins can use this type
89 from rhodecode.authentication.base import get_authn_registry
90 from rhodecode.authentication.plugins import auth_rhodecode
90 authn_registry = get_authn_registry()
91 allowed_auth_plugins = [
91
92 self.name, auth_rhodecode.RhodeCodeAuthPlugin.name]
92 active_plugins = set(
93 [x.name for x in authn_registry.get_plugins_for_authentication()])
94 active_plugins.discard(self.name)
95
96 allowed_auth_plugins = [self.name] + list(active_plugins)
93 # only for vcs operations
97 # only for vcs operations
94 allowed_auth_sources = [VCS_TYPE]
98 allowed_auth_sources = [VCS_TYPE]
95
99
@@ -26,8 +26,8 b' from pyramid.httpexceptions import HTTPF'
26 from pyramid.renderers import render
26 from pyramid.renderers import render
27 from pyramid.response import Response
27 from pyramid.response import Response
28
28
29 from rhodecode.authentication.base import get_auth_cache_manager
29 from rhodecode.authentication.base import (
30 from rhodecode.authentication.interface import IAuthnPluginRegistry
30 get_auth_cache_manager, get_authn_registry)
31 from rhodecode.lib import auth
31 from rhodecode.lib import auth
32 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
32 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
33 from rhodecode.model.forms import AuthSettingsForm
33 from rhodecode.model.forms import AuthSettingsForm
@@ -125,7 +125,7 b' class AuthSettingsView(object):'
125 @HasPermissionAllDecorator('hg.admin')
125 @HasPermissionAllDecorator('hg.admin')
126 def index(self, defaults=None, errors=None, prefix_error=False):
126 def index(self, defaults=None, errors=None, prefix_error=False):
127 defaults = defaults or {}
127 defaults = defaults or {}
128 authn_registry = self.request.registry.getUtility(IAuthnPluginRegistry)
128 authn_registry = get_authn_registry(self.request.registry)
129 enabled_plugins = SettingsModel().get_auth_plugins()
129 enabled_plugins = SettingsModel().get_auth_plugins()
130
130
131 # Create template context and render it.
131 # Create template context and render it.
General Comments 0
You need to be logged in to leave comments. Login now