]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/Auth/Plugin.php
55a4e3916741c9a7d728a2c54ae0d5ba4f127eba
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / Auth / Plugin.php
1 <?php
2
3 /**
4  * This plugin provides Authentication for a WebDAV server.
5  *
6  * It relies on a Backend object, which provides user information.
7  *
8  * Additionally, it provides support for:
9  *  * {DAV:}current-user-principal property from RFC5397
10  *  * {DAV:}principal-collection-set property from RFC3744
11  *
12  * @package Sabre
13  * @subpackage DAV
14  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
15  * @author Evert Pot (http://www.rooftopsolutions.nl/)
16  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
17  */
18 class Sabre_DAV_Auth_Plugin extends Sabre_DAV_ServerPlugin {
19
20     /**
21      * Reference to main server object
22      *
23      * @var Sabre_DAV_Server
24      */
25     private $server;
26
27     /**
28      * Authentication backend
29      *
30      * @var Sabre_DAV_Auth_IBackend
31      */
32     private $authBackend;
33
34     /**
35      * The authentication realm.
36      *
37      * @var string
38      */
39     private $realm;
40
41     /**
42      * __construct
43      *
44      * @param Sabre_DAV_Auth_IBackend $authBackend
45      * @param string $realm
46      */
47     public function __construct(Sabre_DAV_Auth_IBackend $authBackend, $realm) {
48
49         $this->authBackend = $authBackend;
50         $this->realm = $realm;
51
52     }
53
54     /**
55      * Initializes the plugin. This function is automatically called by the server
56      *
57      * @param Sabre_DAV_Server $server
58      * @return void
59      */
60     public function initialize(Sabre_DAV_Server $server) {
61
62         $this->server = $server;
63         $this->server->subscribeEvent('beforeMethod',array($this,'beforeMethod'),10);
64
65     }
66
67     /**
68      * Returns a plugin name.
69      *
70      * Using this name other plugins will be able to access other plugins
71      * using Sabre_DAV_Server::getPlugin
72      *
73      * @return string
74      */
75     public function getPluginName() {
76
77         return 'auth';
78
79     }
80
81     /**
82      * Returns the current users' principal uri.
83      *
84      * If nobody is logged in, this will return null.
85      *
86      * @return string|null
87      */
88     public function getCurrentUser() {
89
90         $userInfo = $this->authBackend->getCurrentUser();
91         if (!$userInfo) return null;
92
93         return $userInfo;
94
95     }
96
97     /**
98      * This method is called before any HTTP method and forces users to be authenticated
99      *
100      * @param string $method
101      * @param string $uri
102      * @throws Sabre_DAV_Exception_NotAuthenticated
103      * @return bool
104      */
105     public function beforeMethod($method, $uri) {
106
107         $this->authBackend->authenticate($this->server,$this->realm);
108
109     }
110
111 }