You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

76 lines
2.8 KiB

  1. # Copyright 2016 Openmarket
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import Any, List, Tuple, Type
  15. from synapse.types import JsonDict
  16. from synapse.util.module_loader import load_module
  17. from ._base import Config
  18. LDAP_PROVIDER = "ldap_auth_provider.LdapAuthProvider"
  19. class PasswordAuthProviderConfig(Config):
  20. section = "authproviders"
  21. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  22. """Parses the old password auth providers config. The config format looks like this:
  23. password_providers:
  24. # Example config for an LDAP auth provider
  25. - module: "ldap_auth_provider.LdapAuthProvider"
  26. config:
  27. enabled: true
  28. uri: "ldap://ldap.example.com:389"
  29. start_tls: true
  30. base: "ou=users,dc=example,dc=com"
  31. attributes:
  32. uid: "cn"
  33. mail: "email"
  34. name: "givenName"
  35. #bind_dn:
  36. #bind_password:
  37. #filter: "(objectClass=posixAccount)"
  38. We expect admins to use modules for this feature (which is why it doesn't appear
  39. in the sample config file), but we want to keep support for it around for a bit
  40. for backwards compatibility.
  41. """
  42. self.password_providers: List[Tuple[Type, Any]] = []
  43. providers = []
  44. # We want to be backwards compatible with the old `ldap_config`
  45. # param.
  46. ldap_config = config.get("ldap_config", {})
  47. if ldap_config.get("enabled", False):
  48. providers.append({"module": LDAP_PROVIDER, "config": ldap_config})
  49. providers.extend(config.get("password_providers") or [])
  50. for i, provider in enumerate(providers):
  51. mod_name = provider["module"]
  52. # This is for backwards compat when the ldap auth provider resided
  53. # in this package.
  54. if mod_name == "synapse.util.ldap_auth_provider.LdapAuthProvider":
  55. mod_name = LDAP_PROVIDER
  56. (provider_class, provider_config) = load_module(
  57. {"module": mod_name, "config": provider["config"]},
  58. ("password_providers", "<item %i>" % i),
  59. )
  60. self.password_providers.append((provider_class, provider_config))