1<?php
2
3namespace Sabre\DAV\Auth\Backend;
4
5use
6    Sabre\DAV,
7    Sabre\HTTP\RequestInterface,
8    Sabre\HTTP\ResponseInterface;
9
10class Mock implements BackendInterface {
11
12    public $fail = false;
13
14    public $invalidCheckResponse = false;
15
16    public $principal = 'principals/admin';
17
18    function setPrincipal($principal) {
19
20        $this->principal = $principal;
21
22    }
23
24    /**
25     * When this method is called, the backend must check if authentication was
26     * successful.
27     *
28     * The returned value must be one of the following
29     *
30     * [true, "principals/username"]
31     * [false, "reason for failure"]
32     *
33     * If authentication was successful, it's expected that the authentication
34     * backend returns a so-called principal url.
35     *
36     * Examples of a principal url:
37     *
38     * principals/admin
39     * principals/user1
40     * principals/users/joe
41     * principals/uid/123457
42     *
43     * If you don't use WebDAV ACL (RFC3744) we recommend that you simply
44     * return a string such as:
45     *
46     * principals/users/[username]
47     *
48     * @param RequestInterface $request
49     * @param ResponseInterface $response
50     * @return array
51     */
52    function check(RequestInterface $request, ResponseInterface $response) {
53
54        if ($this->invalidCheckResponse) {
55            return 'incorrect!';
56        }
57        if ($this->fail) {
58            return [false, "fail!"];
59        }
60        return [true, $this->principal];
61
62    }
63
64    /**
65     * This method is called when a user could not be authenticated, and
66     * authentication was required for the current request.
67     *
68     * This gives you the oppurtunity to set authentication headers. The 401
69     * status code will already be set.
70     *
71     * In this case of Basic Auth, this would for example mean that the
72     * following header needs to be set:
73     *
74     * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV');
75     *
76     * Keep in mind that in the case of multiple authentication backends, other
77     * WWW-Authenticate headers may already have been set, and you'll want to
78     * append your own WWW-Authenticate header instead of overwriting the
79     * existing one.
80     *
81     * @return void
82     */
83    function challenge(RequestInterface $request, ResponseInterface $response) {
84
85    }
86
87}
88