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.
 
 
 
 
 
 

82 lines
3.0 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
  15. from synapse.util.module_loader import load_module
  16. from ._base import Config
  17. LDAP_PROVIDER = "ldap_auth_provider.LdapAuthProvider"
  18. class PasswordAuthProviderConfig(Config):
  19. section = "authproviders"
  20. def read_config(self, config, **kwargs):
  21. self.password_providers = [] # type: List[Any]
  22. providers = []
  23. # We want to be backwards compatible with the old `ldap_config`
  24. # param.
  25. ldap_config = config.get("ldap_config", {})
  26. if ldap_config.get("enabled", False):
  27. providers.append({"module": LDAP_PROVIDER, "config": ldap_config})
  28. providers.extend(config.get("password_providers") or [])
  29. for i, provider in enumerate(providers):
  30. mod_name = provider["module"]
  31. # This is for backwards compat when the ldap auth provider resided
  32. # in this package.
  33. if mod_name == "synapse.util.ldap_auth_provider.LdapAuthProvider":
  34. mod_name = LDAP_PROVIDER
  35. (provider_class, provider_config) = load_module(
  36. {"module": mod_name, "config": provider["config"]},
  37. ("password_providers", "<item %i>" % i),
  38. )
  39. self.password_providers.append((provider_class, provider_config))
  40. def generate_config_section(self, **kwargs):
  41. return """\
  42. # Password providers allow homeserver administrators to integrate
  43. # their Synapse installation with existing authentication methods
  44. # ex. LDAP, external tokens, etc.
  45. #
  46. # For more information and known implementations, please see
  47. # https://github.com/matrix-org/synapse/blob/master/docs/password_auth_providers.md
  48. #
  49. # Note: instances wishing to use SAML or CAS authentication should
  50. # instead use the `saml2_config` or `cas_config` options,
  51. # respectively.
  52. #
  53. password_providers:
  54. # # Example config for an LDAP auth provider
  55. # - module: "ldap_auth_provider.LdapAuthProvider"
  56. # config:
  57. # enabled: true
  58. # uri: "ldap://ldap.example.com:389"
  59. # start_tls: true
  60. # base: "ou=users,dc=example,dc=com"
  61. # attributes:
  62. # uid: "cn"
  63. # mail: "email"
  64. # name: "givenName"
  65. # #bind_dn:
  66. # #bind_password:
  67. # #filter: "(objectClass=posixAccount)"
  68. """