123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace OCA\DAV\DAV;
- use Sabre\DAV\Auth\Backend\BackendInterface;
- use Sabre\HTTP\RequestInterface;
- use Sabre\HTTP\ResponseInterface;
- class PublicAuth implements BackendInterface {
-
- private $publicURLs;
- public function __construct() {
- $this->publicURLs = [
- 'public-calendars',
- 'principals/system/public'
- ];
- }
-
- public function check(RequestInterface $request, ResponseInterface $response) {
- if ($this->isRequestPublic($request)) {
- return [true, 'principals/system/public'];
- }
- return [false, 'No public access to this resource.'];
- }
-
- public function challenge(RequestInterface $request, ResponseInterface $response) {
- }
-
- private function isRequestPublic(RequestInterface $request) {
- $url = $request->getPath();
- $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) {
- return str_starts_with($url, $publicUrl);
- });
- return !empty($matchingUrls);
- }
- }
|