saml2.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Ericsson
  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 ._base import Config
  16. class SAML2Config(Config):
  17. """SAML2 Configuration
  18. Synapse uses pysaml2 libraries for providing SAML2 support
  19. config_path: Path to the sp_conf.py configuration file
  20. idp_redirect_url: Identity provider URL which will redirect
  21. the user back to /login/saml2 with proper info.
  22. sp_conf.py file is something like:
  23. https://github.com/rohe/pysaml2/blob/master/example/sp-repoze/sp_conf.py.example
  24. More information: https://pythonhosted.org/pysaml2/howto/config.html
  25. """
  26. def read_config(self, config):
  27. saml2_config = config.get("saml2_config", None)
  28. if saml2_config:
  29. self.saml2_enabled = saml2_config.get("enabled", True)
  30. self.saml2_config_path = saml2_config["config_path"]
  31. self.saml2_idp_redirect_url = saml2_config["idp_redirect_url"]
  32. else:
  33. self.saml2_enabled = False
  34. self.saml2_config_path = None
  35. self.saml2_idp_redirect_url = None
  36. def default_config(self, config_dir_path, server_name, **kwargs):
  37. return """
  38. # Enable SAML2 for registration and login. Uses pysaml2
  39. # config_path: Path to the sp_conf.py configuration file
  40. # idp_redirect_url: Identity provider URL which will redirect
  41. # the user back to /login/saml2 with proper info.
  42. # See pysaml2 docs for format of config.
  43. #saml2_config:
  44. # enabled: true
  45. # config_path: "%s/sp_conf.py"
  46. # idp_redirect_url: "http://%s/idp"
  47. """ % (config_dir_path, server_name)