mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-24 10:35:46 +03:00
Merge pull request #2607 from matrix-org/rav/cleanup_ldap_hacks
Clean up backwards-compat hacks for ldap
This commit is contained in:
commit
b8e54fbc08
1 changed files with 19 additions and 20 deletions
|
@ -13,41 +13,40 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from ._base import Config, ConfigError
|
from ._base import Config
|
||||||
|
|
||||||
from synapse.util.module_loader import load_module
|
from synapse.util.module_loader import load_module
|
||||||
|
|
||||||
|
LDAP_PROVIDER = 'ldap_auth_provider.LdapAuthProvider'
|
||||||
|
|
||||||
|
|
||||||
class PasswordAuthProviderConfig(Config):
|
class PasswordAuthProviderConfig(Config):
|
||||||
def read_config(self, config):
|
def read_config(self, config):
|
||||||
self.password_providers = []
|
self.password_providers = []
|
||||||
|
providers = []
|
||||||
provider_config = None
|
|
||||||
|
|
||||||
# We want to be backwards compatible with the old `ldap_config`
|
# We want to be backwards compatible with the old `ldap_config`
|
||||||
# param.
|
# param.
|
||||||
ldap_config = config.get("ldap_config", {})
|
ldap_config = config.get("ldap_config", {})
|
||||||
self.ldap_enabled = ldap_config.get("enabled", False)
|
if ldap_config.get("enabled", False):
|
||||||
if self.ldap_enabled:
|
providers.append[{
|
||||||
from ldap_auth_provider import LdapAuthProvider
|
'module': LDAP_PROVIDER,
|
||||||
parsed_config = LdapAuthProvider.parse_config(ldap_config)
|
'config': ldap_config,
|
||||||
self.password_providers.append((LdapAuthProvider, parsed_config))
|
}]
|
||||||
|
|
||||||
providers = config.get("password_providers", [])
|
providers.extend(config.get("password_providers", []))
|
||||||
for provider in providers:
|
for provider in providers:
|
||||||
|
mod_name = provider['module']
|
||||||
|
|
||||||
# This is for backwards compat when the ldap auth provider resided
|
# This is for backwards compat when the ldap auth provider resided
|
||||||
# in this package.
|
# in this package.
|
||||||
if provider['module'] == "synapse.util.ldap_auth_provider.LdapAuthProvider":
|
if mod_name == "synapse.util.ldap_auth_provider.LdapAuthProvider":
|
||||||
from ldap_auth_provider import LdapAuthProvider
|
mod_name = LDAP_PROVIDER
|
||||||
provider_class = LdapAuthProvider
|
|
||||||
try:
|
(provider_class, provider_config) = load_module({
|
||||||
provider_config = provider_class.parse_config(provider["config"])
|
"module": mod_name,
|
||||||
except Exception as e:
|
"config": provider['config'],
|
||||||
raise ConfigError(
|
})
|
||||||
"Failed to parse config for %r: %r" % (provider['module'], e)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
(provider_class, provider_config) = load_module(provider)
|
|
||||||
|
|
||||||
self.password_providers.append((provider_class, provider_config))
|
self.password_providers.append((provider_class, provider_config))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue