3 use Friendica\Model\User;
5 class Sabre_DAV_Auth_Backend_Std extends Sabre_DAV_Auth_Backend_AbstractBasic
8 * @var Sabre_DAV_Auth_Backend_Std|null
10 private static $instance = null;
14 * @return Sabre_DAV_Auth_Backend_Std
16 public static function getInstance()
18 if (is_null(self::$instance)) {
19 self::$instance = new Sabre_DAV_Auth_Backend_Std();
21 return self::$instance;
27 public function getUsers()
29 return [$this->currentUser];
35 public function getCurrentUser()
37 return $this->currentUser;
41 * Authenticates the user based on the current request.
43 * If authentication is successful, true must be returned.
44 * If authentication fails, an exception must be thrown.
46 * @param Sabre_DAV_Server $server
47 * @param string $realm
48 * @throws Sabre_DAV_Exception_NotAuthenticated
51 public function authenticate(Sabre_DAV_Server $server, $realm)
54 if (isset($a->user["uid"])) {
55 $this->currentUser = strtolower($a->user["nickname"]);
59 $auth = new Sabre_HTTP_BasicAuth();
60 $auth->setHTTPRequest($server->httpRequest);
61 $auth->setHTTPResponse($server->httpResponse);
62 $auth->setRealm($realm);
63 $userpass = $auth->getUserPass();
65 $auth->requireLogin();
66 throw new Sabre_DAV_Exception_NotAuthenticated('No basic authentication headers were found');
69 // Authenticates the user
70 if (!$this->validateUserPass($userpass[0], $userpass[1])) {
71 $auth->requireLogin();
72 throw new Sabre_DAV_Exception_NotAuthenticated('Username or password does not match');
74 $this->currentUser = strtolower($userpass[0]);
79 * @param string $username
80 * @param string $password
83 protected function validateUserPass($username, $password)
85 return User::authenticate($username, $password);