Skip to content

Commit

Permalink
Updating BaseControllerProvider for merging
Browse files Browse the repository at this point in the history
- Updated the authenticate and authorize functions to use framework exceptions
  and not the homegrown ones. This was also done in
  ubccr#87
  • Loading branch information
ryanrath committed Apr 14, 2017
1 parent 434284d commit bd80e24
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions classes/NewRest/Controllers/BaseControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use DataWarehouse\Query\Exceptions\AccessDeniedException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
use User\Acl;

Expand Down Expand Up @@ -224,7 +223,7 @@ protected function _parseRestArguments(Request $request, $requiredParams = array
* missing.
* @return \Symfony\Component\HttpFoundation\JsonResponse if and only if
* the user is missing a token or an ip.
* @throws AccessDeniedException
* @throws Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
*/
public static function authenticate(Request $request, Application $app)
{
Expand All @@ -235,7 +234,7 @@ public static function authenticate(Request $request, Application $app)

$user = Authentication::authenticateUser($request);
if ($user === null) {
throw new AccessDeniedException('You must be logged in to access this endpoint.', 401);
throw new UnathorizedHttpException('xdmod', 'You must be logged in to access this endpoint.');
} else {
$request->attributes->set(BaseControllerProvider::_USER, $user);
}
Expand All @@ -261,7 +260,7 @@ public static function authenticate(Request $request, Application $app)
* is false.
* @return \XDUser The user that was checked and is authorized according to
* the given parameters.
* @throws AccessDeniedException
* @throws Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
*/
public function authorize(Request $request, array $requirements = array(), $blacklist = false)
{
Expand All @@ -284,9 +283,9 @@ public function authorize(Request $request, array $requirements = array(), $blac
// limits with their current permissions.
if (!$success) {
if ($user->isPublicUser()) {
throw new AccessDeniedException($message, 401);
throw new UnauthorizedHttpException('xdmod', $message);
} else {
throw new AccessDeniedHttpException($message, null, 403);
throw new AccessDeniedHttpException($message);
}
}

Expand Down

0 comments on commit bd80e24

Please sign in to comment.