core/source/overwrites/auth_backend.php

87 lines
1.3 KiB
PHP
Raw Normal View History

2025-09-21 18:49:03 +02:00
<?php
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,
]
)
);
$data = $realm->source->read();
return ($data !== null);
}
}
}
}
?>