Skip to content
This repository has been archived by the owner on May 14, 2018. It is now read-only.

Commit

Permalink
Merge pull request #163 from ftdebugger/master
Browse files Browse the repository at this point in the history
Show exception details in console
  • Loading branch information
Ocramius committed Jul 5, 2013
2 parents cb47569 + deebca8 commit 02723bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/BjyAuthorize/Guard/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace BjyAuthorize\Guard;

use BjyAuthorize\Exception\UnAuthorizedException;
use BjyAuthorize\Provider\Rule\ProviderInterface as RuleProviderInterface;
use BjyAuthorize\Provider\Resource\ProviderInterface as ResourceProviderInterface;

Expand Down Expand Up @@ -164,6 +165,9 @@ public function onDispatch(MvcEvent $event)
$event->setParam('controller', $controller);
$event->setParam('action', $action);

$errorMessage = sprintf("You are not authorized to access %s:%s", $controller, $action);
$event->setParam('exception', new UnAuthorizedException($errorMessage));

/* @var $app \Zend\Mvc\ApplicationInterface */
$app = $event->getTarget();
$app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
Expand Down
2 changes: 2 additions & 0 deletions src/BjyAuthorize/Guard/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace BjyAuthorize\Guard;

use BjyAuthorize\Exception\UnAuthorizedException;
use BjyAuthorize\Provider\Rule\ProviderInterface as RuleProviderInterface;
use BjyAuthorize\Provider\Resource\ProviderInterface as ResourceProviderInterface;

Expand Down Expand Up @@ -129,6 +130,7 @@ public function onRoute(MvcEvent $event)
$event->setError(static::ERROR);
$event->setParam('route', $routeName);
$event->setParam('identity', $service->getIdentity());
$event->setParam('exception', new UnAuthorizedException('You are not authorized to access ' . $routeName));

/* @var $app \Zend\Mvc\Application */
$app = $event->getTarget();
Expand Down
11 changes: 8 additions & 3 deletions tests/BjyAuthorizeTest/Guard/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,15 @@ public function testOnDispatchWithInvalidResource()
->method('isAllowed')
->will($this->returnValue(false));
$event->expects($this->once())->method('setError')->with(Controller::ERROR);
$event->expects($this->exactly(3))->method('setParam')->with(
$this->logicalOr('identity', 'controller', 'action'),
$this->logicalOr('admin', 'test-controller', 'test-action')

$event->expects($this->at(4))->method('setParam')->with('identity', 'admin');
$event->expects($this->at(5))->method('setParam')->with('controller', 'test-controller');
$event->expects($this->at(6))->method('setParam')->with('action', 'test-action');
$event->expects($this->at(7))->method('setParam')->with(
'exception',
$this->isInstanceOf('BjyAuthorize\Exception\UnAuthorizedException')
);

$event
->getTarget()
->getEventManager()
Expand Down
10 changes: 7 additions & 3 deletions tests/BjyAuthorizeTest/Guard/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ public function testOnRouteWithInvalidResource()
->method('isAllowed')
->will($this->returnValue(false));
$event->expects($this->once())->method('setError')->with(Route::ERROR);
$event->expects($this->exactly(2))->method('setParam')->with(
$this->logicalOr('identity', 'route'),
$this->logicalOr('admin', 'test-route')

$event->expects($this->at(3))->method('setParam')->with('route', 'test-route');
$event->expects($this->at(4))->method('setParam')->with('identity', 'admin');
$event->expects($this->at(5))->method('setParam')->with(
'exception',
$this->isInstanceOf('BjyAuthorize\Exception\UnAuthorizedException')
);

$event
->getTarget()
->getEventManager()
Expand Down

0 comments on commit 02723bd

Please sign in to comment.