4 * This addon provides Authentication for a WebDAV server.
6 * It relies on a Backend object, which provides user information.
8 * Additionally, it provides support for:
9 * * {DAV:}current-user-principal property from RFC5397
10 * * {DAV:}principal-collection-set property from RFC3744
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
18 class Sabre_DAV_Auth_Plugin extends Sabre_DAV_ServerPlugin {
21 * Reference to main server object
23 * @var Sabre_DAV_Server
28 * Authentication backend
30 * @var Sabre_DAV_Auth_IBackend
35 * The authentication realm.
44 * @param Sabre_DAV_Auth_IBackend $authBackend
45 * @param string $realm
47 public function __construct(Sabre_DAV_Auth_IBackend $authBackend, $realm) {
49 $this->authBackend = $authBackend;
50 $this->realm = $realm;
55 * Initializes the addon. This function is automatically called by the server
57 * @param Sabre_DAV_Server $server
60 public function initialize(Sabre_DAV_Server $server) {
62 $this->server = $server;
63 $this->server->subscribeEvent('beforeMethod',array($this,'beforeMethod'),10);
68 * Returns a addon name.
70 * Using this name other addons will be able to access other addons
71 * using Sabre_DAV_Server::getPlugin
75 public function getPluginName() {
82 * Returns the current users' principal uri.
84 * If nobody is logged in, this will return null.
88 public function getCurrentUser() {
90 $userInfo = $this->authBackend->getCurrentUser();
91 if (!$userInfo) return null;
98 * This method is called before any HTTP method and forces users to be authenticated
100 * @param string $method
102 * @throws Sabre_DAV_Exception_NotAuthenticated
105 public function beforeMethod($method, $uri) {
107 $this->authBackend->authenticate($this->server,$this->realm);