PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Sabre/DAV/Auth/Backend/Apache.php

https://github.com/KOLANICH/SabreDAV
PHP | 63 lines | 17 code | 12 blank | 34 comment | 1 complexity | 85b36701e3da74eac3a3150f48bbc904 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Sabre\DAV\Auth\Backend;
  3. use Sabre\DAV;
  4. /**
  5. * Apache authenticator
  6. *
  7. * This authentication backend assumes that authentication has been
  8. * configured in apache, rather than within SabreDAV.
  9. *
  10. * Make sure apache is properly configured for this to work.
  11. *
  12. * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
  13. * @author Evert Pot (http://evertpot.com/)
  14. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  15. */
  16. class Apache implements BackendInterface {
  17. /**
  18. * Current apache user
  19. *
  20. * @var string
  21. */
  22. protected $remoteUser;
  23. /**
  24. * Authenticates the user based on the current request.
  25. *
  26. * If authentication is successful, true must be returned.
  27. * If authentication fails, an exception must be thrown.
  28. *
  29. * @param DAV\Server $server
  30. * @param string $realm
  31. * @return bool
  32. */
  33. public function authenticate(DAV\Server $server, $realm) {
  34. $remoteUser = $server->httpRequest->getRawServerValue('REMOTE_USER');
  35. if (is_null($remoteUser)) {
  36. throw new DAV\Exception('We did not receive the $_SERVER[REMOTE_USER] property. This means that apache might have been misconfigured');
  37. }
  38. $this->remoteUser = $remoteUser;
  39. return true;
  40. }
  41. /**
  42. * Returns information about the currently logged in user.
  43. *
  44. * If nobody is currently logged in, this method should return null.
  45. *
  46. * @return array|null
  47. */
  48. public function getCurrentUser() {
  49. return $this->remoteUser;
  50. }
  51. }