__init__.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2008 Nicolas Kandel
  3. # Copyright © 2008 Pascal Halter
  4. # Copyright © 2008-2017 Guillaume Ayoub
  5. # Copyright © 2017-2018 Unrud <unrud@outlook.com>
  6. #
  7. # This library is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  19. """
  20. Authentication module.
  21. Authentication is based on usernames and passwords. If something more
  22. advanced is needed an external WSGI server or reverse proxy can be used
  23. (see ``remote_user`` or ``http_x_remote_user`` backend).
  24. Take a look at the class ``BaseAuth`` if you want to implement your own.
  25. """
  26. from radicale import utils
  27. INTERNAL_TYPES = ("none", "remote_user", "http_x_remote_user", "htpasswd")
  28. def load(configuration):
  29. """Load the authentication module chosen in configuration."""
  30. return utils.load_plugin(INTERNAL_TYPES, "auth", "Auth", configuration)
  31. class BaseAuth:
  32. def __init__(self, configuration):
  33. """Initialize BaseAuth.
  34. ``configuration`` see ``radicale.config`` module.
  35. The ``configuration`` must not change during the lifetime of
  36. this object, it is kept as an internal reference.
  37. """
  38. self.configuration = configuration
  39. def get_external_login(self, environ):
  40. """Optionally provide the login and password externally.
  41. ``environ`` a dict with the WSGI environment
  42. If ``()`` is returned, Radicale handles HTTP authentication.
  43. Otherwise, returns a tuple ``(login, password)``. For anonymous users
  44. ``login`` must be ``""``.
  45. """
  46. return ()
  47. def login(self, login, password):
  48. """Check credentials and map login to internal user
  49. ``login`` the login name
  50. ``password`` the password
  51. Returns the user name or ``""`` for invalid credentials.
  52. """
  53. raise NotImplementedError