Skip to content

Commit

Permalink
added base class method to enable checking by derived classes for aut…
Browse files Browse the repository at this point in the history
…hentication
  • Loading branch information
blacknell committed Jan 13, 2019
1 parent b6a14f2 commit 4b3d0f0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/RestAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 4b3d0f0

Please sign in to comment.