3 * HTTP Basic authentication backend class
5 * This class can be used by authentication objects wishing to use HTTP Basic
6 * Most of the digest logic is handled, implementors just need to worry about
7 * the validateUserPass method.
11 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12 * @author James David Low (http://jameslow.com/)
13 * @author Evert Pot (http://www.rooftopsolutions.nl/)
14 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
16 abstract class Sabre_DAV_Auth_Backend_AbstractBasic implements Sabre_DAV_Auth_IBackend {
19 * This variable holds the currently logged in username.
23 protected $currentUser;
26 * Validates a username and password
28 * This method should return true or false depending on if login
31 * @param string $username
32 * @param string $password
35 abstract protected function validateUserPass($username, $password);
38 * Returns information about the currently logged in username.
40 * If nobody is currently logged in, this method should return null.
44 public function getCurrentUser() {
45 return $this->currentUser;
50 * Authenticates the user based on the current request.
52 * If authentication is successful, true must be returned.
53 * If authentication fails, an exception must be thrown.
55 * @param Sabre_DAV_Server $server
56 * @param string $realm
57 * @throws Sabre_DAV_Exception_NotAuthenticated
60 public function authenticate(Sabre_DAV_Server $server, $realm) {
62 $auth = new Sabre_HTTP_BasicAuth();
63 $auth->setHTTPRequest($server->httpRequest);
64 $auth->setHTTPResponse($server->httpResponse);
65 $auth->setRealm($realm);
66 $userpass = $auth->getUserPass();
68 $auth->requireLogin();
69 throw new Sabre_DAV_Exception_NotAuthenticated('No basic authentication headers were found');
72 // Authenticates the user
73 if (!$this->validateUserPass($userpass[0],$userpass[1])) {
74 $auth->requireLogin();
75 throw new Sabre_DAV_Exception_NotAuthenticated('Username or password does not match');
77 $this->currentUser = $userpass[0];