Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

73 řádky
2.7 KiB

  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. # The default value of password_config.enabled is True, unless msc3861 is enabled.
  26. msc3861_enabled = (
  27. (config.get("experimental_features") or {})
  28. .get("msc3861", {})
  29. .get("enabled", False)
  30. )
  31. passwords_enabled = password_config.get("enabled", not msc3861_enabled)
  32. # 'only_for_reauth' allows users who have previously set a password to use it,
  33. # even though passwords would otherwise be disabled.
  34. passwords_for_reauth_only = passwords_enabled == "only_for_reauth"
  35. self.password_enabled_for_login = (
  36. passwords_enabled and not passwords_for_reauth_only
  37. )
  38. self.password_enabled_for_reauth = (
  39. passwords_for_reauth_only or passwords_enabled
  40. )
  41. self.password_localdb_enabled = password_config.get("localdb_enabled", True)
  42. self.password_pepper = password_config.get("pepper", "")
  43. # Password policy
  44. self.password_policy = password_config.get("policy") or {}
  45. self.password_policy_enabled = self.password_policy.get("enabled", False)
  46. # User-interactive authentication
  47. ui_auth = config.get("ui_auth") or {}
  48. self.ui_auth_session_timeout = self.parse_duration(
  49. ui_auth.get("session_timeout", 0)
  50. )
  51. # Logging in with an existing session.
  52. login_via_existing = config.get("login_via_existing_session", {})
  53. self.login_via_existing_enabled = login_via_existing.get("enabled", False)
  54. self.login_via_existing_require_ui_auth = login_via_existing.get(
  55. "require_ui_auth", True
  56. )
  57. self.login_via_existing_token_timeout = self.parse_duration(
  58. login_via_existing.get("token_timeout", "5m")
  59. )