From 3f3c603922bc57179fef5fbedaf6f28aa58293d1 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 29 Jun 2015 12:04:41 +0200 Subject: Adding exception handling for ServerNotAvailableException - refs #17192 --- lib/private/connector/sabre/auth.php | 51 +++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'lib/private') diff --git a/lib/private/connector/sabre/auth.php b/lib/private/connector/sabre/auth.php index 5a32a9112ba..2255b2c0466 100644 --- a/lib/private/connector/sabre/auth.php +++ b/lib/private/connector/sabre/auth.php @@ -30,7 +30,13 @@ */ 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'; /** @@ -69,7 +75,7 @@ class Auth extends \Sabre\DAV\Auth\Backend\AbstractBasic { } else { \OC_Util::setUpFS(); //login hooks may need early access to the filesystem 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 $ocUser = \OC_User::getUser(); \OC_Util::setUpFS($ocUser); @@ -99,29 +105,38 @@ class Auth extends \Sabre\DAV\Auth\Backend\AbstractBasic { } /** - * Override function here. We want to cache authentication cookies - * in the syncing client to avoid HTTP-401 roundtrips. - * If the sync client supplies the cookies, then OC_User::isLoggedIn() - * will return true and we can see this WebDAV request as already authenticated, - * even if there are no HTTP Basic Auth headers. - * In other case, just fallback to the parent implementation. - * - * @param \Sabre\DAV\Server $server - * @param $realm - * @return bool - */ - public function authenticate(\Sabre\DAV\Server $server, $realm) { + * Override function here. We want to cache authentication cookies + * in the syncing client to avoid HTTP-401 roundtrips. + * If the sync client supplies the cookies, then OC_User::isLoggedIn() + * will return true and we can see this WebDAV request as already authenticated, + * even if there are no HTTP Basic Auth headers. + * In other case, just fallback to the parent implementation. + * + * @param Server $server + * @param string $realm + * @return bool + * @throws ServiceUnavailable + */ + public function authenticate(Server $server, $realm) { - $result = $this->auth($server, $realm); - return $result; + try { + $result = $this->auth($server, $realm); + 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 * @return bool */ - private function auth(\Sabre\DAV\Server $server, $realm) { + private function auth(Server $server, $realm) { if (\OC_User::handleApacheAuth() || (\OC_User::isLoggedIn() && is_null(\OC::$server->getSession()->get(self::DAV_AUTHENTICATED))) ) { -- cgit v1.2.3 From 134dc136e66f7ead2e4ffc7d74711e1d9a8dc58d Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 30 Jun 2015 15:07:48 +0200 Subject: Avoid namespace clash --- lib/private/connector/sabre/auth.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/private') diff --git a/lib/private/connector/sabre/auth.php b/lib/private/connector/sabre/auth.php index 2255b2c0466..8a6eaab5bf8 100644 --- a/lib/private/connector/sabre/auth.php +++ b/lib/private/connector/sabre/auth.php @@ -34,7 +34,6 @@ 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'; @@ -112,12 +111,12 @@ class Auth extends AbstractBasic { * even if there are no HTTP Basic Auth headers. * In other case, just fallback to the parent implementation. * - * @param Server $server + * @param \Sabre\DAV\Server $server * @param string $realm * @return bool * @throws ServiceUnavailable */ - public function authenticate(Server $server, $realm) { + public function authenticate(\Sabre\DAV\Server $server, $realm) { try { $result = $this->auth($server, $realm); @@ -132,11 +131,11 @@ class Auth extends AbstractBasic { } /** - * @param Server $server + * @param \Sabre\DAV\Server $server * @param $realm * @return bool */ - private function auth(Server $server, $realm) { + private function auth(\Sabre\DAV\Server $server, $realm) { if (\OC_User::handleApacheAuth() || (\OC_User::isLoggedIn() && is_null(\OC::$server->getSession()->get(self::DAV_AUTHENTICATED))) ) { -- cgit v1.2.3