auth.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright 2015, 2016 OpenMarket Ltd
  2. # Copyright 2020 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from typing import Any
  16. from synapse.types import JsonDict
  17. from ._base import Config
  18. class AuthConfig(Config):
  19. """Password and login configuration"""
  20. section = "auth"
  21. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  22. password_config = config.get("password_config", {})
  23. if password_config is None:
  24. password_config = {}
  25. passwords_enabled = password_config.get("enabled", True)
  26. # 'only_for_reauth' allows users who have previously set a password to use it,
  27. # even though passwords would otherwise be disabled.
  28. passwords_for_reauth_only = passwords_enabled == "only_for_reauth"
  29. self.password_enabled_for_login = (
  30. passwords_enabled and not passwords_for_reauth_only
  31. )
  32. self.password_enabled_for_reauth = (
  33. passwords_for_reauth_only or passwords_enabled
  34. )
  35. self.password_localdb_enabled = password_config.get("localdb_enabled", True)
  36. self.password_pepper = password_config.get("pepper", "")
  37. # Password policy
  38. self.password_policy = password_config.get("policy") or {}
  39. self.password_policy_enabled = self.password_policy.get("enabled", False)
  40. # User-interactive authentication
  41. ui_auth = config.get("ui_auth") or {}
  42. self.ui_auth_session_timeout = self.parse_duration(
  43. ui_auth.get("session_timeout", 0)
  44. )