ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractDigest.php
Go to the documentation of this file.
1<?php
2
4
5use Sabre\DAV;
6use Sabre\HTTP;
9
21abstract class AbstractDigest implements BackendInterface {
22
31 protected $realm = 'SabreDAV';
32
38 protected $principalPrefix = 'principals/';
39
50 function setRealm($realm) {
51
52 $this->realm = $realm;
53
54 }
55
65 abstract function getDigestHash($realm, $username);
66
96
97 $digest = new HTTP\Auth\Digest(
98 $this->realm,
101 );
102 $digest->init();
103
104 $username = $digest->getUsername();
105
106 // No username was given
107 if (!$username) {
108 return [false, "No 'Authorization: Digest' header found. Either the client didn't send one, or the server is misconfigured"];
109 }
110
111 $hash = $this->getDigestHash($this->realm, $username);
112 // If this was false, the user account didn't exist
113 if ($hash === false || is_null($hash)) {
114 return [false, "Username or password was incorrect"];
115 }
116 if (!is_string($hash)) {
117 throw new DAV\Exception('The returned value from getDigestHash must be a string or null');
118 }
119
120 // If this was false, the password or part of the hash was incorrect.
121 if (!$digest->validateA1($hash)) {
122 return [false, "Username or password was incorrect"];
123 }
124
125 return [true, $this->principalPrefix . $username];
126
127 }
128
151
153 $this->realm,
154 $request,
156 );
157 $auth->init();
158
159 $oldStatus = $response->getStatus() ?: 200;
160 $auth->requireLogin();
161
162 // Preventing the digest utility from modifying the http status code,
163 // this should be handled by the main plugin.
164 $response->setStatus($oldStatus);
165
166 }
167
168}
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
HTTP Digest authentication backend class.
getDigestHash($realm, $username)
Returns a users digest hash based on the username and realm.
setRealm($realm)
Sets the authentication realm for this backend.
check(RequestInterface $request, ResponseInterface $response)
When this method is called, the backend must check if authentication was successful.
challenge(RequestInterface $request, ResponseInterface $response)
This method is called when a user could not be authenticated, and authentication was required for the...
Main Exception class.
Definition: Exception.php:18
HTTP Digest Authentication handler.
Definition: Digest.php:30
$auth
Definition: fileserver.php:48
This is the base class for any authentication object.
The RequestInterface represents a HTTP request.
This interface represents a HTTP response.
$response