Refactor authentication handling to replace getAuthenticatedOperator with requireAuthenticatedOperator in multiple files
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions

This commit is contained in:
netkas 2025-06-06 17:59:17 -04:00
parent 885553121d
commit ae672d7d38
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
6 changed files with 7 additions and 7 deletions

View file

@ -250,6 +250,7 @@
$path === '/operators' && $requestMethod === 'GET' => Method::LIST_OPERATORS,
$path === '/operators' && $requestMethod === 'POST' => Method::CREATE_OPERATOR,
$path === '/operators/self' && $requestMethod === 'GET' => Method::GET_SELF_OPERATOR,
$path === '/operators/refresh' && $requestMethod === 'POST' => Method::REFRESH_OPERATOR_API_KEY,
preg_match('#^/operators/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'GET' => Method::GET_OPERATOR,
preg_match('#^/operators/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'DELETE' => Method::DELETE_OPERATOR,
preg_match('#^/operators/([a-fA-F0-9\-]{36,})/enable$#', $path) && $requestMethod === 'POST' => Method::ENABLE_OPERATOR,

View file

@ -3,6 +3,7 @@
namespace FederationServer;
use Exception;
use FederationServer\Classes\Enums\HttpResponseCode;
use FederationServer\Classes\Enums\Method;
use FederationServer\Classes\Logger;
use FederationServer\Classes\RequestHandler;
@ -151,7 +152,7 @@
$operator = self::getAuthenticatedOperator();
if ($operator === null)
{
throw new RequestException('Authentication required', 401);
throw new RequestException('Authentication required', HttpResponseCode::UNAUTHORIZED);
}
return $operator;

View file

@ -17,7 +17,7 @@
*/
public static function handleRequest(): void
{
$authenticatedOperator = FederationServer::getAuthenticatedOperator();
$authenticatedOperator = FederationServer::requireAuthenticatedOperator();
if(!$authenticatedOperator->canManageOperators())
{
throw new RequestException('Insufficient permissions manage permissions', 403);

View file

@ -17,7 +17,7 @@
*/
public static function handleRequest(): void
{
$authenticatedOperator = FederationServer::getAuthenticatedOperator();
$authenticatedOperator = FederationServer::requireAuthenticatedOperator();
if(!$authenticatedOperator->canManageOperators())
{
throw new RequestException('Insufficient permissions manage permissions', 403);

View file

@ -17,7 +17,7 @@
*/
public static function handleRequest(): void
{
$authenticatedOperator = FederationServer::getAuthenticatedOperator();
$authenticatedOperator = FederationServer::requireAuthenticatedOperator();
if(!$authenticatedOperator->canManageOperators())
{
throw new RequestException('Insufficient permissions manage permissions', 403);

View file

@ -16,9 +16,7 @@
*/
public static function handleRequest(): void
{
$authenticatedOperator = FederationServer::getAuthenticatedOperator();
$operatorUuid = null;
$authenticatedOperator = FederationServer::requireAuthenticatedOperator();
if(preg_match('#^/operators/([a-fA-F0-9\-]{36,})/refresh$#', FederationServer::getPath(), $matches))
{
$operatorUuid = $matches[1];