authn: Fix form validation of authentication plugins.
- Check if plugin exists. - Display an apropriate error message if it doesn't exist.
This commit is contained in:
parent
f6ac7d1c82
commit
a44e92e154
2 changed files with 14 additions and 18 deletions
|
|
@ -474,12 +474,7 @@ def loadplugin(plugin_id):
|
|||
"""
|
||||
Loads and returns an instantiated authentication plugin.
|
||||
Returns the RhodeCodeAuthPluginBase subclass on success,
|
||||
raises exceptions on failure.
|
||||
|
||||
raises:
|
||||
KeyError -- if no plugin available with given name
|
||||
TypeError -- if the RhodeCodeAuthPlugin is not a subclass of
|
||||
ours RhodeCodeAuthPluginBase
|
||||
or None on failure.
|
||||
"""
|
||||
# TODO: Disusing pyramids thread locals to retrieve the registry.
|
||||
authn_registry = get_current_registry().getUtility(IAuthnPluginRegistry)
|
||||
|
|
|
|||
|
|
@ -995,18 +995,19 @@ def ValidAuthPlugins():
|
|||
from rhodecode.authentication.base import loadplugin
|
||||
module_list = value
|
||||
unique_names = {}
|
||||
try:
|
||||
for module in module_list:
|
||||
plugin = loadplugin(module)
|
||||
plugin_name = plugin.name
|
||||
if plugin_name in unique_names:
|
||||
msg = M(self, 'import_duplicate', state,
|
||||
loaded=unique_names[plugin_name],
|
||||
next_to_load=plugin_name)
|
||||
raise formencode.Invalid(msg, value, state)
|
||||
unique_names[plugin_name] = plugin
|
||||
except (KeyError, AttributeError, TypeError) as e:
|
||||
raise formencode.Invalid(str(e), value, state)
|
||||
for module in module_list:
|
||||
plugin = loadplugin(module)
|
||||
if plugin is None:
|
||||
raise formencode.Invalid(
|
||||
_("Can't find plugin with id '{}'".format(module)),
|
||||
value, state)
|
||||
plugin_name = plugin.name
|
||||
if plugin_name in unique_names:
|
||||
msg = M(self, 'import_duplicate', state,
|
||||
loaded=unique_names[plugin_name],
|
||||
next_to_load=plugin_name)
|
||||
raise formencode.Invalid(msg, value, state)
|
||||
unique_names[plugin_name] = plugin
|
||||
|
||||
return _validator
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue