PageRenderTime 183ms CodeModel.GetById 61ms app.highlight 1ms RepoModel.GetById 119ms app.codeStats 1ms

/lib/Sabre/DAV/Auth/Backend/Apache.php

https://github.com/KOLANICH/SabreDAV
PHP | 63 lines | 17 code | 12 blank | 34 comment | 1 complexity | 85b36701e3da74eac3a3150f48bbc904 MD5 | raw file
 1<?php
 2
 3namespace Sabre\DAV\Auth\Backend;
 4use Sabre\DAV;
 5
 6/**
 7 * Apache authenticator
 8 *
 9 * This authentication backend assumes that authentication has been
10 * configured in apache, rather than within SabreDAV.
11 *
12 * Make sure apache is properly configured for this to work.
13 *
14 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
15 * @author Evert Pot (http://evertpot.com/)
16 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
17 */
18class Apache implements BackendInterface {
19
20    /**
21     * Current apache user
22     *
23     * @var string
24     */
25    protected $remoteUser;
26
27    /**
28     * Authenticates the user based on the current request.
29     *
30     * If authentication is successful, true must be returned.
31     * If authentication fails, an exception must be thrown.
32     *
33     * @param DAV\Server $server
34     * @param string $realm
35     * @return bool
36     */
37    public function authenticate(DAV\Server $server, $realm) {
38
39        $remoteUser = $server->httpRequest->getRawServerValue('REMOTE_USER');
40        if (is_null($remoteUser)) {
41            throw new DAV\Exception('We did not receive the $_SERVER[REMOTE_USER] property. This means that apache might have been misconfigured');
42        }
43
44        $this->remoteUser = $remoteUser;
45        return true;
46
47    }
48
49    /**
50     * Returns information about the currently logged in user.
51     *
52     * If nobody is currently logged in, this method should return null.
53     *
54     * @return array|null
55     */
56    public function getCurrentUser() {
57
58        return $this->remoteUser;
59
60    }
61
62}
63