generated from Nodarx/template
Initial service DAV module
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ServiceDav\Auth;
|
||||
|
||||
use KTXC\Service\SecurityService;
|
||||
use KTXC\SessionIdentity;
|
||||
use Sabre\DAV\Auth\Backend\AbstractBasic;
|
||||
use Sabre\HTTP\RequestInterface;
|
||||
use Sabre\HTTP\ResponseInterface;
|
||||
|
||||
class DavAuthBackend extends AbstractBasic
|
||||
{
|
||||
public const PRINCIPAL_PREFIX = 'principals/';
|
||||
|
||||
public function __construct(
|
||||
private readonly SessionIdentity $identity,
|
||||
private readonly SecurityService $securityService,
|
||||
string $realm = 'KTXC DAV',
|
||||
) {
|
||||
$this->realm = $realm;
|
||||
}
|
||||
|
||||
public function check(RequestInterface $request, ResponseInterface $response): array
|
||||
{
|
||||
if ($this->identity->identity() !== null) {
|
||||
$userId = $this->identity->identifier();
|
||||
return [true, self::PRINCIPAL_PREFIX . $userId];
|
||||
}
|
||||
|
||||
return parent::check($request, $response);
|
||||
}
|
||||
|
||||
protected function validateUserPass($username, $password): bool
|
||||
{
|
||||
$user = $this->securityService->authenticatePassword($username, $password);
|
||||
if ($user === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->identity->initialize($user, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user