/**
  * Perform authentication and authorization.
  *
  * @throws \Magento\Framework\Exception\AuthorizationException
  * @return void
  */
 private function checkPermissions()
 {
     $route = $this->router->match($this->request);
     if (!$this->authorization->isAllowed($route->getAclResources())) {
         $params = ['resources' => implode(', ', $route->getAclResources())];
         throw new AuthorizationException(__(AuthorizationException::NOT_AUTHORIZED, $params));
     }
 }
Example #2
0
 /**
  * Retrieve current route.
  *
  * @return Route
  */
 protected function getCurrentRoute()
 {
     if (!$this->_route) {
         $this->_route = $this->_router->match($this->_request);
     }
     return $this->_route;
 }
 /**
  * Retrieve current route.
  *
  * @return Route
  */
 public function getRoute()
 {
     if (!$this->route) {
         $this->route = $this->router->match($this->request);
     }
     return $this->route;
 }
Example #4
0
 protected function setUp()
 {
     $this->mockArguments();
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->disableOriginalConstructor()->getMock();
     $errorProcessorMock = $this->getMock('Magento\\Webapi\\Controller\\ErrorProcessor', [], [], '', false);
     $errorProcessorMock->expects($this->any())->method('maskException')->will($this->returnArgument(0));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->serializerMock = $this->getMockBuilder('\\Magento\\Webapi\\Controller\\ServiceArgsSerializer')->disableOriginalConstructor()->setMethods(['getInputData'])->getMock();
     $this->areaListMock = $this->getMock('\\Magento\\Framework\\App\\AreaList', [], [], '', false);
     $this->areaMock = $this->getMock('Magento\\Framework\\App\\AreaInterface');
     $this->areaListMock->expects($this->any())->method('getArea')->will($this->returnValue($this->areaMock));
     /** Init SUT. */
     $this->_restController = $objectManager->getObject('Magento\\Webapi\\Controller\\Rest', ['request' => $this->_requestMock, 'response' => $this->_responseMock, 'router' => $this->_routerMock, 'objectManager' => $this->_objectManagerMock, 'appState' => $this->_appStateMock, 'layout' => $layoutMock, 'oauthService' => $this->_oauthServiceMock, 'authorization' => $this->_authorizationMock, 'serializer' => $this->serializerMock, 'errorProcessor' => $errorProcessorMock, 'areaList' => $this->areaListMock, 'userContext' => $this->userContextMock]);
     // Set default expectations used by all tests
     $this->_routeMock->expects($this->any())->method('getServiceClass')->will($this->returnValue(self::SERVICE_ID));
     $this->_routeMock->expects($this->any())->method('getServiceMethod')->will($this->returnValue(self::SERVICE_METHOD));
     $this->_routerMock->expects($this->any())->method('match')->will($this->returnValue($this->_routeMock));
     $this->_objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($this->_serviceMock));
     $this->_responseMock->expects($this->any())->method('prepareResponse')->will($this->returnValue([]));
     $this->_serviceMock->expects($this->any())->method(self::SERVICE_METHOD)->will($this->returnValue(null));
     parent::setUp();
 }
Example #5
0
 /**
  * @expectedException \Magento\Framework\Webapi\Exception
  */
 public function testNotMatch()
 {
     $this->_apiConfigMock->expects($this->once())->method('getRestRoutes')->will($this->returnValue([$this->_routeMock]));
     $this->_routeMock->expects($this->once())->method('match')->with($this->_request)->will($this->returnValue(false));
     $this->_router->match($this->_request);
 }