diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-07-20 15:25:36 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-07-20 15:25:36 +0200 |
commit | bd91ee4d2289b15fa69c3712056f275cac3405ed (patch) | |
tree | bc2ad997c5565362cb7c99e61efbd1cb069fb9be /3rdparty/Sabre/HTTP/BasicAuth.php | |
parent | e4154e68324fd9af4c7ba0b9abba3e50d5b5c56e (diff) | |
download | nextcloud-server-bd91ee4d2289b15fa69c3712056f275cac3405ed.tar.gz nextcloud-server-bd91ee4d2289b15fa69c3712056f275cac3405ed.zip |
add SabreDav 1.6.3 files
Diffstat (limited to '3rdparty/Sabre/HTTP/BasicAuth.php')
-rwxr-xr-x | 3rdparty/Sabre/HTTP/BasicAuth.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/3rdparty/Sabre/HTTP/BasicAuth.php b/3rdparty/Sabre/HTTP/BasicAuth.php new file mode 100755 index 00000000000..a747cc6a31b --- /dev/null +++ b/3rdparty/Sabre/HTTP/BasicAuth.php @@ -0,0 +1,67 @@ +<?php + +/** + * HTTP Basic Authentication handler + * + * Use this class for easy http authentication setup + * + * @package Sabre + * @subpackage HTTP + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_HTTP_BasicAuth extends Sabre_HTTP_AbstractAuth { + + /** + * Returns the supplied username and password. + * + * The returned array has two values: + * * 0 - username + * * 1 - password + * + * If nothing was supplied, 'false' will be returned + * + * @return mixed + */ + public function getUserPass() { + + // Apache and mod_php + if (($user = $this->httpRequest->getRawServerValue('PHP_AUTH_USER')) && ($pass = $this->httpRequest->getRawServerValue('PHP_AUTH_PW'))) { + + return array($user,$pass); + + } + + // Most other webservers + $auth = $this->httpRequest->getHeader('Authorization'); + + // Apache could prefix environment variables with REDIRECT_ when urls + // are passed through mod_rewrite + if (!$auth) { + $auth = $this->httpRequest->getRawServerValue('REDIRECT_HTTP_AUTHORIZATION'); + } + + if (!$auth) return false; + + if (strpos(strtolower($auth),'basic')!==0) return false; + + return explode(':', base64_decode(substr($auth, 6))); + + } + + /** + * Returns an HTTP 401 header, forcing login + * + * This should be called when username and password are incorrect, or not supplied at all + * + * @return void + */ + public function requireLogin() { + + $this->httpResponse->setHeader('WWW-Authenticate','Basic realm="' . $this->realm . '"'); + $this->httpResponse->sendStatus(401); + + } + +} |