aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php14
-rw-r--r--lib/private/AppFramework/Http/Request.php5
-rw-r--r--lib/private/AppFramework/Middleware/OCSMiddleware.php62
-rw-r--r--lib/private/AppFramework/Routing/RouteConfig.php8
4 files changed, 80 insertions, 9 deletions
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php
index 66ca59d26e2..20351d1321c 100644
--- a/lib/private/AppFramework/DependencyInjection/DIContainer.php
+++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php
@@ -124,6 +124,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $this->getServer()->getDateTimeZone();
});
+ $this->registerService('OCP\\IDateTimeFormatter', function($c) {
+ return $this->getServer()->getDateTimeFormatter();
+ });
+
$this->registerService('OCP\\IDb', function($c) {
return $this->getServer()->getDb();
});
@@ -148,6 +152,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $this->getServer()->getMountProviderCollection();
});
+ $this->registerService('OCP\\Files\\Config\\IUserMountCache', function($c) {
+ return $this->getServer()->getUserMountCache();
+ });
+
$this->registerService('OCP\\Files\\IRootFolder', function($c) {
return $this->getServer()->getRootFolder();
});
@@ -306,6 +314,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $c->query('ServerContainer')->getWebRoot();
});
+ $this->registerService('OCP\Encryption\IManager', function ($c) {
+ return $this->getServer()->getEncryptionManager();
+ });
+
/**
* App Framework APIs
@@ -396,6 +408,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
$dispatcher = new MiddlewareDispatcher();
$dispatcher->registerMiddleware($c['CORSMiddleware']);
+ $dispatcher->registerMiddleware($c['OCSMiddleware']);
$dispatcher->registerMiddleware($c['SecurityMiddleware']);
$dispatcher->registerMiddleWare($c['TwoFactorMiddleware']);
@@ -404,7 +417,6 @@ class DIContainer extends SimpleContainer implements IAppContainer {
}
$dispatcher->registerMiddleware($c['SessionMiddleware']);
- $dispatcher->registerMiddleware($c['OCSMiddleware']);
return $dispatcher;
});
diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php
index 679ee5bc27c..ba8a48381bd 100644
--- a/lib/private/AppFramework/Http/Request.php
+++ b/lib/private/AppFramework/Http/Request.php
@@ -56,7 +56,6 @@ use OCP\Security\ISecureRandom;
class Request implements \ArrayAccess, \Countable, IRequest {
const USER_AGENT_IE = '/(MSIE)|(Trident)/';
- const USER_AGENT_IE_8 = '/MSIE 8.0/';
// Microsoft Edge User Agent from https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
const USER_AGENT_MS_EDGE = '/^Mozilla\/5\.0 \([^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\) Chrome\/[0-9.]+ (Mobile Safari|Safari)\/[0-9.]+ Edge\/[0-9.]+$/';
// Firefox User Agent from https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference
@@ -714,10 +713,6 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @return string|false Path info or false when not found
*/
public function getPathInfo() {
- if(isset($this->server['PATH_INFO'])) {
- return $this->server['PATH_INFO'];
- }
-
$pathInfo = $this->getRawPathInfo();
// following is taken from \Sabre\HTTP\URLUtil::decodePathSegment
$pathInfo = rawurldecode($pathInfo);
diff --git a/lib/private/AppFramework/Middleware/OCSMiddleware.php b/lib/private/AppFramework/Middleware/OCSMiddleware.php
index e07d100d8ac..68445bbcc51 100644
--- a/lib/private/AppFramework/Middleware/OCSMiddleware.php
+++ b/lib/private/AppFramework/Middleware/OCSMiddleware.php
@@ -23,8 +23,14 @@
namespace OC\AppFramework\Middleware;
use OC\AppFramework\Http;
+use OCP\API;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\OCSResponse;
+use OCP\AppFramework\Http\Response;
use OCP\AppFramework\OCS\OCSException;
+use OCP\AppFramework\OCS\OCSForbiddenException;
+use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
use OCP\AppFramework\Middleware;
@@ -54,12 +60,35 @@ class OCSMiddleware extends Middleware {
$code = $exception->getCode();
if ($code === 0) {
- $code = Http::STATUS_INTERNAL_SERVER_ERROR;
+ $code = API::RESPOND_UNKNOWN_ERROR;
}
+
+ // Build the response
$response = new OCSResponse($format, $code, $exception->getMessage());
+ // Forbidden always sets 401 (even on v1.php)
+ if ($exception instanceof OCSForbiddenException || $code === API::RESPOND_UNAUTHORISED) {
+ $response->setStatus(Http::STATUS_UNAUTHORIZED);
+ }
+
+ // On v2.php we set actual HTTP error codes
if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) {
- $response->setStatus($code);
+ if ($code === API::RESPOND_NOT_FOUND) {
+ $response->setStatus(Http::STATUS_NOT_FOUND);
+ } else if ($code === API::RESPOND_SERVER_ERROR) {
+ $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
+ } else if ($code === API::RESPOND_UNKNOWN_ERROR) {
+ $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
+ } else if ($code === API::RESPOND_UNAUTHORISED) {
+ // Already set
+ }
+ // 4xx and 5xx codes are forwarded as is.
+ else if ($code >= 400 && $code < 600) {
+ $response->setStatus($code);
+ } else {
+ // All other codes get a bad request
+ $response->setStatus(Http::STATUS_BAD_REQUEST);
+ }
}
return $response;
}
@@ -69,6 +98,35 @@ class OCSMiddleware extends Middleware {
/**
* @param \OCP\AppFramework\Controller $controller
+ * @param string $methodName
+ * @param Response $response
+ * @return \OCP\AppFramework\Http\Response
+ */
+ public function afterController($controller, $methodName, Response $response) {
+ /*
+ * If a different middleware has detected that a request unauthorized or forbidden
+ * we need to catch the response and convert it to a proper OCS response.
+ */
+ if ($controller instanceof OCSController && !($response instanceof OCSResponse)) {
+ if ($response->getStatus() === Http::STATUS_UNAUTHORIZED ||
+ $response->getStatus() === Http::STATUS_FORBIDDEN) {
+ $format = $this->getFormat($controller);
+
+ $message = '';
+ if ($response instanceof JSONResponse) {
+ /** @var DataResponse $response */
+ $message = $response->getData()['message'];
+ }
+ $response = new OCSResponse($format, \OCP\API::RESPOND_UNAUTHORISED, $message);
+ $response->setStatus(Http::STATUS_UNAUTHORIZED);
+ }
+ }
+
+ return $response;
+ }
+
+ /**
+ * @param \OCP\AppFramework\Controller $controller
* @return string
*/
private function getFormat($controller) {
diff --git a/lib/private/AppFramework/Routing/RouteConfig.php b/lib/private/AppFramework/Routing/RouteConfig.php
index 066c0da1138..e94f2e50c1d 100644
--- a/lib/private/AppFramework/Routing/RouteConfig.php
+++ b/lib/private/AppFramework/Routing/RouteConfig.php
@@ -86,7 +86,13 @@ class RouteConfig {
$postfix = $ocsRoute['postfix'];
}
- $url = $ocsRoute['url'];
+ if (isset($ocsRoute['root'])) {
+ $root = $ocsRoute['root'];
+ } else {
+ $root = '/apps/'.$this->appName;
+ }
+
+ $url = $root . $ocsRoute['url'];
$verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET';
$split = explode('#', $name, 2);