Skip to content

Refactor REST API token authentication code to allow for use of existing role-based authorization code. #1743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: xdmod10.5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions classes/Rest/Controllers/BaseControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ public function setupAssertions(Application $app, ControllerCollection $controll
* @param Application $app that will be used to facilitate returning a
* json response if information is found to be
* missing.
* @return \Symfony\Component\HttpFoundation\JsonResponse if and only if
* the user is missing a token or an ip.
*
* @throws Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
*/
Expand Down Expand Up @@ -744,7 +742,6 @@ protected function getTimestamp($date, $paramName = 'date', $format = 'Y-m-d')

/**
* @param Request $request
* @return \XDUser
* @throws BadRequestHttpException if the provided token is empty, or there is not a provided token.
* @throws \Exception if the user's token from the db does not validate against the provided token.
*/
Expand Down Expand Up @@ -778,6 +775,7 @@ protected function authenticateToken($request)
$userId = substr($rawToken, 0, $delimPosition);
$token = substr($rawToken, $delimPosition + 1);

return Tokens::authenticate($userId, $token);
$user = Tokens::authenticate($userId, $token);
$request->attributes->set(BaseControllerProvider::_USER, $user);
}
}
3 changes: 2 additions & 1 deletion classes/Rest/Controllers/WarehouseControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,8 @@ private function getUserStore(\XDUser $user, $realm)
*/
public function getRawData(Request $request, Application $app)
{
$user = parent::authenticateToken($request);
parent::authenticateToken($request);
$user = parent::getUserFromRequest($request);
$params = $this->validateRawDataParams($request, $user);
$query = $this->getRawDataQuery($params);
$logger = $this->getRawDataLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ public function getRealms(Request $request, Application $app)
// NOOP
}

if ($user === null) {
$user = $this->authorize($request);
}

$user = $this->authorize($request);

$config = RawStatisticsConfiguration::factory();

Expand Down