This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ namespace davina\overwrites; require_once('vendor/autoload.php'); require_once(DIR_LOGIC . '/base.php'); /** */ class class_auth_backend extends \Sabre\DAV\Auth\Backend\AbstractBasic implements \Sabre\DAV\Auth\Backend\BackendInterface { /** * @var array {list<\davina\sources\interface_source>} */ private array $realms; /** */ public function __construct( array $realms ) { // parent::__construct(); $this->realms = $realms; $this->setRealm('davina'); } /** */ protected function validateUserPass( /*string */$identifier, /*string */$password )/* : bool*/ { $parts = \explode('-', $identifier, 2); $realm_name = $parts[0]; $credentials = [ 'username' => ( (\count($parts) >= 2) ? $parts[1] : null ), 'password' => $password, ]; if (! \array_key_exists($realm_name, $this->realms)) { return false; } else { $realm = $this->realms[$realm_name]; if (! $realm->auth->check($credentials)) { return false; } else { /** * @todo check for security */ \davina\set_parameters( \array_merge( $realm->auth->determine_parameters($credentials), [ 'realm_name' => $realm_name, ] ) ); try { $data = $realm->source->read(); return ($data !== null); } catch (\Throwable $throwable) { return false; } } } } } ?>