/**
  * Hands authorization over to the AnnAuthorize class.
  * @param array $user
  *         An array containing information about the user to authorize.
  * @param Request $request
  *         Describes the request to authorize.
  */
 public function authorize($user, Request $request)
 {
     $controller = $this->_registry->getController();
     $action = $request->param('action');
     $pass = $request->param('pass');
     Log::debug(sprintf('Trying to authorize user %s for request %s/%s and parameters %s.', $user['username'], $controller->name, $action, json_encode($pass)));
     $annAuthorization = AnnAuthorization::getInstance();
     $authorized = $annAuthorization->authorizeRequest($user['id'], $controller, $action, $pass, $request);
     Log::debug(sprintf('Authorization %s', $authorized ? 'was successful.' : 'failed.'));
     return $authorized;
 }
 /**
  * This method provides conditional output of the desired link only if the current user has access to the controller action referenced by the
  * link.
  * @return Returns the constructed link if the current user has access to the controller action referenced by the link or false, if not.
  * @see \Cake\View\Helper\HtmlHelper::link() for additional information on the parameters.
  */
 public function link($title, $url = null, array $options = [])
 {
     $parsedRoute = Router::parse(Router::url($url !== null ? $url : $title));
     $annAuthorization = AnnAuthorization::getInstance();
     $userId = $this->request->session()->read('Auth.User.id');
     $controller = $parsedRoute['controller'];
     $action = $parsedRoute['action'];
     $pass = $parsedRoute['pass'];
     $requestAuthorized = $annAuthorization->authorizeRequest($userId, $controller, $action, $pass, $this->request);
     if ($requestAuthorized) {
         return $this->Html->link($title, $url, $options);
     }
     return false;
 }
 public function testGetAllowedActions()
 {
     $allowedActions = $this->AnnAuthorization->getAllowedActions($this->controller);
     $this->assertEquals(['allowedAction'], $allowedActions);
 }