diff --git a/src/RestAPI.php b/src/RestAPI.php index 37b183b..373a015 100644 --- a/src/RestAPI.php +++ b/src/RestAPI.php @@ -86,6 +86,7 @@ public function __construct($request, \Monolog\Logger $logger = null) $this->method = 'PUT'; } else { + $this->logger->notice("Unexpected Header", $this->toObject()); throw new RuntimeException("Unexpected Header", 400); } } @@ -103,10 +104,25 @@ public function __construct($request, \Monolog\Logger $logger = null) $this->file = file_get_contents("php://input"); break; default: - $this->logger->error("Method Not Allowed", $this->toObject()); + $this->logger->notice("Method Not Allowed", $this->toObject()); throw new RuntimeException("Method Not Allowed", 405); break; } + + if( !$this->isAuthenticated()) { + $this->logger->warning("Unauthorized", $this->toObject()); + throw new RuntimeException("Unauthorized", 401); + } + } + + /** + * Overide this method to consider whether the request is authenticated + * + * @return bool true if authenticated + */ + protected function isAuthenticated() + { + return true; } /** @@ -186,6 +202,7 @@ private function requestStatus($code) $status = array( 200 => 'OK', 400 => 'Bad Request', + 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed',