utils.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012 Yaco Sistemas (http://www.yaco.es)
  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 django.conf import settings
  15. def get_custom_setting(name, default=None):
  16. if hasattr(settings, name):
  17. return getattr(settings, name)
  18. else:
  19. return default
  20. def available_idps(config, langpref=None):
  21. if langpref is None:
  22. langpref = "en"
  23. idps = set()
  24. for metadata_name, metadata in config.metadata.metadata.items():
  25. result = metadata.any('idpsso_descriptor', 'single_sign_on_service')
  26. if result:
  27. idps = idps.union(set(result.keys()))
  28. return dict([(idp, config.metadata.name(idp, langpref)) for idp in idps])
  29. def get_location(http_info):
  30. """Extract the redirect URL from a pysaml2 http_info object"""
  31. assert 'headers' in http_info
  32. headers = http_info['headers']
  33. assert len(headers) == 1
  34. header_name, header_value = headers[0]
  35. assert header_name == 'Location'
  36. return header_value