Validate subuser grants before resolving customer user
This commit is contained in:
@@ -6,6 +6,7 @@ use classes\totp;
|
||||
use Exception;
|
||||
use interfaces\authentication_i;
|
||||
use objects\plate_scanners_o;
|
||||
use objects\subuser_grants_o;
|
||||
use objects\tokens_o;
|
||||
use objects\users_o;
|
||||
use objects\subusers_o;
|
||||
@@ -140,6 +141,15 @@ class authentication implements authentication_i
|
||||
return false;
|
||||
}
|
||||
$customer_number = (int)$headers['X-Customer-Number'];
|
||||
// Resolve and validate subuser grant for the requested customer context
|
||||
$subuser = (new subusers_o())->getSubuserBySessionToken($token->token->value());
|
||||
if ($subuser === null) {
|
||||
return false;
|
||||
}
|
||||
$grants = (new subuser_grants_o())->getGrantsForSubuserAndCustomer((int)$subuser->id, $customer_number);
|
||||
if (count($grants) === 0) {
|
||||
return false;
|
||||
}
|
||||
// Get the user by the customer number
|
||||
return (new users_o())->getUserByCustomerNumber($customer_number);
|
||||
}
|
||||
@@ -232,4 +242,4 @@ class authentication implements authentication_i
|
||||
}
|
||||
return (int)$headers['X-Customer-Number'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user