auth-token: allow other authentication types to use auth-token.
Fixes #4070
This commit is contained in:
parent
52015c0c8f
commit
ab6750c9a7
3 changed files with 21 additions and 11 deletions
|
|
@ -490,13 +490,19 @@ def loadplugin(plugin_id):
|
|||
or None on failure.
|
||||
"""
|
||||
# TODO: Disusing pyramids thread locals to retrieve the registry.
|
||||
authn_registry = get_current_registry().getUtility(IAuthnPluginRegistry)
|
||||
authn_registry = get_authn_registry()
|
||||
plugin = authn_registry.get_plugin(plugin_id)
|
||||
if plugin is None:
|
||||
log.error('Authentication plugin not found: "%s"', plugin_id)
|
||||
return plugin
|
||||
|
||||
|
||||
def get_authn_registry(registry=None):
|
||||
registry = registry or get_current_registry()
|
||||
authn_registry = registry.getUtility(IAuthnPluginRegistry)
|
||||
return authn_registry
|
||||
|
||||
|
||||
def get_auth_cache_manager(custom_ttl=None):
|
||||
return caches.get_cache_manager(
|
||||
'auth_plugins', 'rhodecode.authentication', custom_ttl)
|
||||
|
|
@ -520,7 +526,7 @@ def authenticate(username, password, environ=None, auth_type=None,
|
|||
% auth_type)
|
||||
headers_only = environ and not (username and password)
|
||||
|
||||
authn_registry = get_current_registry().getUtility(IAuthnPluginRegistry)
|
||||
authn_registry = get_authn_registry()
|
||||
for plugin in authn_registry.get_plugins_for_authentication():
|
||||
plugin.set_auth_type(auth_type)
|
||||
user = plugin.get_user(username)
|
||||
|
|
|
|||
|
|
@ -83,13 +83,17 @@ class RhodeCodeAuthPlugin(RhodeCodeAuthPluginBase):
|
|||
allowed_auth_plugins=None, allowed_auth_sources=None):
|
||||
"""
|
||||
Custom method for this auth that doesn't accept empty users. And also
|
||||
allows rhodecode and authtoken extern_type to auth with this. But only
|
||||
via vcs mode
|
||||
allows users from all other active plugins to use it and also
|
||||
authenticate against it. But only via vcs mode
|
||||
"""
|
||||
# only this and rhodecode plugins can use this type
|
||||
from rhodecode.authentication.plugins import auth_rhodecode
|
||||
allowed_auth_plugins = [
|
||||
self.name, auth_rhodecode.RhodeCodeAuthPlugin.name]
|
||||
from rhodecode.authentication.base import get_authn_registry
|
||||
authn_registry = get_authn_registry()
|
||||
|
||||
active_plugins = set(
|
||||
[x.name for x in authn_registry.get_plugins_for_authentication()])
|
||||
active_plugins.discard(self.name)
|
||||
|
||||
allowed_auth_plugins = [self.name] + list(active_plugins)
|
||||
# only for vcs operations
|
||||
allowed_auth_sources = [VCS_TYPE]
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ from pyramid.httpexceptions import HTTPFound
|
|||
from pyramid.renderers import render
|
||||
from pyramid.response import Response
|
||||
|
||||
from rhodecode.authentication.base import get_auth_cache_manager
|
||||
from rhodecode.authentication.interface import IAuthnPluginRegistry
|
||||
from rhodecode.authentication.base import (
|
||||
get_auth_cache_manager, get_authn_registry)
|
||||
from rhodecode.lib import auth
|
||||
from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
|
||||
from rhodecode.model.forms import AuthSettingsForm
|
||||
|
|
@ -125,7 +125,7 @@ class AuthSettingsView(object):
|
|||
@HasPermissionAllDecorator('hg.admin')
|
||||
def index(self, defaults=None, errors=None, prefix_error=False):
|
||||
defaults = defaults or {}
|
||||
authn_registry = self.request.registry.getUtility(IAuthnPluginRegistry)
|
||||
authn_registry = get_authn_registry(self.request.registry)
|
||||
enabled_plugins = SettingsModel().get_auth_plugins()
|
||||
|
||||
# Create template context and render it.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue