sql_domain_controller.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # coding: utf8
  2. from tracim.lib.user import UserApi
  3. class DigestAuthNotImplemented(Exception):
  4. pass
  5. class TracimDomainController(object):
  6. """
  7. The domain controller is used by http_authenticator to authenticate the user every time a request is
  8. sent
  9. """
  10. def __init__(self, presetdomain = None, presetserver = None):
  11. self._api = UserApi(None)
  12. def getDomainRealm(self, inputURL, environ):
  13. return '/'
  14. def getRealmUserPassword(self, realmname, username, environ):
  15. """
  16. This method is normally only use for digest auth. wsgidav need
  17. plain password to deal with it. as we didn't
  18. provide support for this kind of auth, this method raise an exception.
  19. """
  20. raise DigestAuthNotImplemented
  21. def requireAuthentication(self, realmname, environ):
  22. return True
  23. def isRealmUser(self, realmname, username, environ):
  24. """
  25. Called to check if for a given root, the username exists (though here we don't make difference between
  26. root as we're always starting at tracim's root
  27. """
  28. try:
  29. self._api.get_one_by_email(username)
  30. return True
  31. except:
  32. return False
  33. def authDomainUser(self, realmname, username, password, environ):
  34. """
  35. If you ever feel the need to send a request al-mano with a curl, this is the function that'll be called by
  36. http_authenticator to validate the password sent
  37. """
  38. return self.isRealmUser(realmname, username, environ) and \
  39. self._api.get_one_by_email(username).validate_password(password)