From 918ce84b1bc8de2f27a658bb3003c4eda2320982 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 2 Jul 2020 22:17:03 +0300 Subject: [PATCH] fixes --- application/Espo/Core/Api/Auth.php | 1 - application/Espo/Core/Application.php | 56 +++++++++++++-------------- application/Espo/Core/Utils/Auth.php | 4 +- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/application/Espo/Core/Api/Auth.php b/application/Espo/Core/Api/Auth.php index e9d0b0f5b0..ee6a749bef 100644 --- a/application/Espo/Core/Api/Auth.php +++ b/application/Espo/Core/Api/Auth.php @@ -78,7 +78,6 @@ class Auth public function process(Request $request, Response $response) : Response { - $uri = $request->getUri(); $httpMethod = $request->getMethod(); $username = null; diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index b21d7b429c..0d6391b9a3 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -360,26 +360,27 @@ class Application $method( $route['route'], function (Request $request, Response $response, $args) use ($route) { - $authRequired = true; - - $conditions = $route['conditions'] ?? []; - if (($conditions['auth'] ?? true) === false) { - $authRequired = false; - } - - $auth = $this->createAuth($request); - $apiAuth = new ApiAuth($auth, $authRequired); - - $response = $apiAuth->process($request, $response); - - if (!$apiAuth->isResolved()) { - return $response; - } - if ($apiAuth->isResolvedUseNoAuth()) { - $this->setupSystemUser(); - } - try { + $authRequired = true; + + $conditions = $route['conditions'] ?? []; + if (($conditions['auth'] ?? true) === false) { + $authRequired = false; + } + + $auth = $this->createAuth($request); + $apiAuth = new ApiAuth($auth, $authRequired); + + $response = $apiAuth->process($request, $response); + + + if (!$apiAuth->isResolved()) { + return $response; + } + if ($apiAuth->isResolvedUseNoAuth()) { + $this->setupSystemUser(); + } + $response = $this->processRoute($route, $request, $response, $args); } catch (\Throwable $e) { $output = new ApiOutput($request); @@ -450,19 +451,14 @@ class Application $output = new ApiOutput($request); - try { - $controllerManager = $this->container->get('controllerManager'); - $result = $controllerManager->process( - $controllerName, $actionName, $params, $data, $requestWrapped, $responseWrapped - ); + $controllerManager = $this->container->get('controllerManager'); + $result = $controllerManager->process( + $controllerName, $actionName, $params, $data, $requestWrapped, $responseWrapped + ); - $response = $responseWrapped->getResponse(); + $response = $responseWrapped->getResponse(); - $response = $output->render($response, $result); - - } catch (\Exception $e) { - $response = $output->processError($response, $e, false, $route, $args); - } + $response = $output->render($response, $result); return $response; } diff --git a/application/Espo/Core/Utils/Auth.php b/application/Espo/Core/Utils/Auth.php index ef44824d9b..63d3e9ee12 100644 --- a/application/Espo/Core/Utils/Auth.php +++ b/application/Espo/Core/Utils/Auth.php @@ -444,12 +444,14 @@ class Auth $authLogRecord = $this->getEntityManager()->getEntity('AuthLogRecord'); + $requestUrl = $request->getUri()->getScheme() . '://' . $request->getUri()->getHost() . $request->getUri()->getPath(); + $authLogRecord->set([ 'username' => $username, 'ipAddress' => $_SERVER['REMOTE_ADDR'] ?? null, 'requestTime' => $_SERVER['REQUEST_TIME_FLOAT'], 'requestMethod' => $this->request->getMethod(), - 'requestUrl' => $this->request->getUri() . $this->request->getPath(), + 'requestUrl' => $requestUrl, 'authenticationMethod' => $authenticationMethod ]);