Adding exception handling for ServerNotAvailableException - refs #17192
This commit is contained in:
parent
0118bf04dc
commit
3f3c603922
|
@ -30,7 +30,13 @@
|
||||||
*/
|
*/
|
||||||
namespace OC\Connector\Sabre;
|
namespace OC\Connector\Sabre;
|
||||||
|
|
||||||
class Auth extends \Sabre\DAV\Auth\Backend\AbstractBasic {
|
use Exception;
|
||||||
|
use Sabre\DAV\Auth\Backend\AbstractBasic;
|
||||||
|
use Sabre\DAV\Exception\NotAuthenticated;
|
||||||
|
use Sabre\DAV\Exception\ServiceUnavailable;
|
||||||
|
use Sabre\DAV\Server;
|
||||||
|
|
||||||
|
class Auth extends AbstractBasic {
|
||||||
const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
|
const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +75,7 @@ class Auth extends \Sabre\DAV\Auth\Backend\AbstractBasic {
|
||||||
} else {
|
} else {
|
||||||
\OC_Util::setUpFS(); //login hooks may need early access to the filesystem
|
\OC_Util::setUpFS(); //login hooks may need early access to the filesystem
|
||||||
if(\OC_User::login($username, $password)) {
|
if(\OC_User::login($username, $password)) {
|
||||||
// make sure we use owncloud's internal username here
|
// make sure we use ownCloud's internal username here
|
||||||
// and not the HTTP auth supplied one, see issue #14048
|
// and not the HTTP auth supplied one, see issue #14048
|
||||||
$ocUser = \OC_User::getUser();
|
$ocUser = \OC_User::getUser();
|
||||||
\OC_Util::setUpFS($ocUser);
|
\OC_Util::setUpFS($ocUser);
|
||||||
|
@ -106,22 +112,31 @@ class Auth extends \Sabre\DAV\Auth\Backend\AbstractBasic {
|
||||||
* even if there are no HTTP Basic Auth headers.
|
* even if there are no HTTP Basic Auth headers.
|
||||||
* In other case, just fallback to the parent implementation.
|
* In other case, just fallback to the parent implementation.
|
||||||
*
|
*
|
||||||
* @param \Sabre\DAV\Server $server
|
* @param Server $server
|
||||||
* @param $realm
|
* @param string $realm
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws ServiceUnavailable
|
||||||
*/
|
*/
|
||||||
public function authenticate(\Sabre\DAV\Server $server, $realm) {
|
public function authenticate(Server $server, $realm) {
|
||||||
|
|
||||||
|
try {
|
||||||
$result = $this->auth($server, $realm);
|
$result = $this->auth($server, $realm);
|
||||||
return $result;
|
return $result;
|
||||||
|
} catch (NotAuthenticated $e) {
|
||||||
|
throw $e;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$class = get_class($e);
|
||||||
|
$msg = $e->getMessage();
|
||||||
|
throw new ServiceUnavailable("$class: $msg");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Sabre\DAV\Server $server
|
* @param Server $server
|
||||||
* @param $realm
|
* @param $realm
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function auth(\Sabre\DAV\Server $server, $realm) {
|
private function auth(Server $server, $realm) {
|
||||||
if (\OC_User::handleApacheAuth() ||
|
if (\OC_User::handleApacheAuth() ||
|
||||||
(\OC_User::isLoggedIn() && is_null(\OC::$server->getSession()->get(self::DAV_AUTHENTICATED)))
|
(\OC_User::isLoggedIn() && is_null(\OC::$server->getSession()->get(self::DAV_AUTHENTICATED)))
|
||||||
) {
|
) {
|
||||||
|
|
Loading…
Reference in New Issue