__init__.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2008 Nicolas Kandel
  3. # Copyright © 2008 Pascal Halter
  4. # Copyright © 2008-2016 Guillaume Ayoub
  5. #
  6. # This library is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. Authentication management.
  20. """
  21. import sys
  22. from .. import config, log
  23. def load():
  24. """Load list of available authentication managers."""
  25. auth_type = config.get("auth", "type")
  26. log.LOGGER.debug("Authentication type is %s" % auth_type)
  27. if auth_type == "None":
  28. return None
  29. elif auth_type == 'custom':
  30. auth_module = config.get("auth", "custom_handler")
  31. __import__(auth_module)
  32. module = sys.modules[auth_module]
  33. else:
  34. root_module = __import__(
  35. "auth.%s" % auth_type, globals=globals(), level=2)
  36. module = getattr(root_module, auth_type)
  37. # Override auth.is_authenticated
  38. sys.modules[__name__].is_authenticated = module.is_authenticated
  39. return module
  40. def is_authenticated(user, password):
  41. """Check if the user is authenticated.
  42. This method is overriden if an auth module is loaded.
  43. """
  44. return True # Default is always True: no authentication