source: pmb4.2/trunk/fuentes/pmb/admin/connecteurs/out/webdav/lib/Sabre/HTTP/BasicAuth.php @ 815

Last change on this file since 815 was 815, checked in by jrpelegrina, 4 years ago

Initial release of pmb 4.2

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1<?php
2
3namespace Sabre\HTTP;
4
5/**
6 * HTTP Basic Authentication handler
7 *
8 * Use this class for easy http authentication setup
9 *
10 * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
11 * @author Evert Pot (http://www.rooftopsolutions.nl/)
12 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
13 */
14class BasicAuth extends AbstractAuth {
15
16    /**
17     * Returns the supplied username and password.
18     *
19     * The returned array has two values:
20     *   * 0 - username
21     *   * 1 - password
22     *
23     * If nothing was supplied, 'false' will be returned
24     *
25     * @return mixed
26     */
27    public function getUserPass() {
28
29        // Apache and mod_php
30        if (($user = $this->httpRequest->getRawServerValue('PHP_AUTH_USER')) && ($pass = $this->httpRequest->getRawServerValue('PHP_AUTH_PW'))) {
31
32            return array($user,$pass);
33
34        }
35
36        // Most other webservers
37        $auth = $this->httpRequest->getHeader('Authorization');
38
39        // Apache could prefix environment variables with REDIRECT_ when urls
40        // are passed through mod_rewrite
41        if (!$auth) {
42            $auth = $this->httpRequest->getRawServerValue('REDIRECT_HTTP_AUTHORIZATION');
43        }
44
45        if (!$auth) return false;
46
47        if (strpos(strtolower($auth),'basic')!==0) return false;
48
49        return explode(':', base64_decode(substr($auth, 6)),2);
50
51    }
52
53    /**
54     * Returns an HTTP 401 header, forcing login
55     *
56     * This should be called when username and password are incorrect, or not supplied at all
57     *
58     * @return void
59     */
60    public function requireLogin() {
61
62        $this->httpResponse->setHeader('WWW-Authenticate','Basic realm="' . $this->realm . '"');
63        $this->httpResponse->sendStatus(401);
64
65    }
66
67}
Note: See TracBrowser for help on using the repository browser.