Denied

@param string $route
@param array  $routeParameters
@param string $message

@return Response
543640
public function denied($route, $routeParameters = [], $message = 'flash_bag.error.default')
    {
        $this->addSessionFlashBagMessage(self::SESSION_FLASH_BAG_ERROR, $message);

        return $this->redirect($this->generateUrl($route, $routeParameters));
    }
1357003
private function extractPermissionFrom(Route $route)
    {
        $parameters = $route->getAction();

        if (isset($parameters['permission']))
        {
            return $parameters['permission'];
        }

        return null;
    }
186198
public function getSavedRedirect($route, $message = 'flash_bag.success.default', $routeParameters = [], $routeFragment = null, $translationDomain = null)
    {
        $this->addSessionFlashBagMessage($message, Bootstrap4::STATE_SUCCESS, $translationDomain);

        return $this->getRedirectToRoute($route, $routeParameters, UrlGeneratorInterface::ABSOLUTE_PATH, Response::HTTP_FOUND, $routeFragment);
    }
903882
public function authenticate(Request $request, Route $route)
    {
        $this->validateAuthorizationHeader($request);

        try {
            if (! $user = $this->auth->parseToken()->authenticate()) {
                throw new UnauthorizedHttpException('JWTAuth', 'Unable to authenticate with invalid token.');
            }
        } catch (JWTException $exception) {
            throw new UnauthorizedHttpException('JWTAuth', $exception->getMessage(), $exception);
        }

        return $user;
    }
243219
public function amOnRoute($routeName, array $params = [])
    {
        $router = $this->client->grabServiceFromContainer('router');
        $url = $router->assemble($params, ['name' => $routeName]);
        $this->amOnPage($url);
    }
739603
public function saved($route, $routeParameters = [], $message = 'flash_bag.success.default', $fragment = null)
    {
        $this->addSessionFlashBagMessage(self::SESSION_FLASH_BAG_SUCCESS, $message);

        $url = $this->generateUrl($route, $routeParameters);
        if (null !== $fragment) {
            $url = sprintf('%s#%s', $url, $fragment);
        }

        return $this->redirect($url);
    }
1026893
protected function getRouteDomain($route, &$parameters)
    {
        return $route->domain() ? $this->formatDomain($route, $parameters) : null;
    }
129154
protected function created(Response $response, $route, array $params = [])
    {
        return $this->redirect($response, $route, $params)->withStatus(201);
    }
1256582
private function buildValidRoute(Route $route): void
    {
        //add to route array the passed uri for param check when call
        $matches = $this->routeMatches;

        //route match and there is a subpattern with action
        if (\count($matches) > 1) {
            //assume that subpattern rapresent action
            $route->action = $matches[1];

            //url clean
            $route->url = \preg_replace('`\([0-9A-Za-z\|]++\)`', $matches[1], $route->url);
        }

        $route->param = $this->buildParam($route);

        $this->route = $route;
    }
393440
protected function methodNotAllowed(string $message = "Method not allowed."): Response
    {
        return $this->getResponse()
            ->setContent($message)
            ->setStatusCode(Response::HTTP_METHOD_NOT_ALLOWED);
    }
415727
private function getRouteParam($route, $param)
    {
        $route = (array) $route;
        $prefix = chr(0).'*'.chr(0);
        
        return $this->arrayGet(
            $route, 
            $prefix.$param, 
            $this->arrayGet($route, $param)
        );
    }
709349
protected function replaceRouteParameters($route, &$parameters = [])
    {
        return \preg_replace_callback('/\{(.*?)(:.*?)?(\{[0-9,]+\})?\}/', function ($m) use (&$parameters) {
            return isset($parameters[$m[1]]) ? Arr::pull($parameters, $m[1]) : $m[0];
        }, $route);
    }
1085080
protected function assertArgumentRequirement($key, $regex, $arguments)
    {
        if (substr($regex, -1) === '+' && !array_key_exists($key, $arguments)) {
            throw new RouteException(sprintf('Missing value for argument "%s" in route "%s"', $key, $this->pattern));
        }
    }
853727
public function handleViolation(Route $route)
    {

        if(in_array($route, $this->violatingRoutes)) {
            throw new ApplicationException('Circular redirects detected; aborting.');
        }

        // to avoid circular references all redirects are logged

        $this->violatingRoutes[] = $route;

        Session::getSessionDataBag()->set('authViolatingRequest', Request::createFromGlobals());

        if($redirect = $route->getRedirect()) {
            return Application::getInstance()->getRouter()->getRoute($redirect);
        }

        else {
            throw new \RuntimeException(sprintf("No redirect configured for route '%s', which cannot be authenticated.", $route->getRouteId()));
        }

    }
1062724
protected function unauthorizedException(Request $request, Response $response, $message = 'Unauthorized.')
    {
        return new UnauthorizedException($request, $response, $message);
    }
229656
protected function methodNotAllowed(
        Request $request,
        Response $response,
        Route $route
    ) {
        $request;
        $response = $response->withStatus(405)
            ->withHeader('Allow', implode(', ', $route->allows))
            ->withHeader('Content-Type', 'application/json');
        $response->getBody()->write(json_encode($route->allows));
        return $response;
    }
1312613
protected function _execute($route) {
		Permit::$executed = $this->executed = $route;

		if (empty($route['rules'])) {
			return false;
		}

		if (isset($route['rules']['deny'])) {
			return $route['rules']['deny'] == true;
		}

		if (!isset($route['rules']['auth'])) {
			return false;
		}

		if (is_bool($route['rules']['auth'])) {
			$isAuthed = $this->Session->read("{$this->settings['path']}.{$this->settings['check']}");

			if ($route['rules']['auth'] == true && !$isAuthed) {
				return true;
			}

			if ($route['rules']['auth'] == false && $isAuthed) {
				return true;
			}

			return false;
		} elseif (!is_array($route['rules']['auth'])) {
			return false;
		}

		if ($this->user == false) {
			return true;
		}

		$fieldsBehavior = 'and';
		if (!empty($route['rules']['fields_behavior'])) {
			$fieldsBehavior = strtolower($route['rules']['fields_behavior']);
		}

		if (!in_array($fieldsBehavior, array('and', 'or'))) {
			$fieldsBehavior = 'and';
		}

		$count = count(Set::flatten($route['rules']['auth']));
		foreach ($route['rules']['auth'] as $path => $condition) {
			$path = '/' . str_replace('.', '/', $path);
			$path = preg_replace('/^([\/]+)/', '/', $path);

			$check = $condition;
			$continue = false;
			$decrement = 1;
			$values = Set::extract($path, $this->user);

			// Support for OR Model-syntax
			foreach (array('or', 'OR') as $anOr) {
				if (is_array($condition) && array_key_exists($anOr, $condition)) {
					$check = $condition[$anOr];
					$continue = true;
					$decrement = count($check);
				}
			}

			if ($fieldsBehavior == 'or') {
				$check = $condition;
				$continue = true;
				$decrement = count($check);
			}

			foreach ((array)$check as $cond) {
				if (in_array($cond, (array)$values)) {
					$count -= $decrement;
					if ($continue) {
						continue 2;
					}
				}
			}
		}

		return $count !== 0;
	}