1 回答
TA贡献1909条经验 获得超7个赞
我找到了解决方案,但我知道这不是最好的,但目前它让我满意。我已经编辑了denyAccessUnlessGranted() 方法,并使用回显强制显示错误 我的解决方案是这样的:
/**
* Throws an exception unless the attributes are granted against the current authentication token and optionally
* supplied subject.
*
* @throws AccessDeniedException
*
* @final
*/
protected function denyAccessUnlessGranted($attributes, $subject = null, string $message = 'Access Denied.')
{
if (!$this->isGranted($attributes, $subject)) {
$exception = $this->createAccessDeniedException($message);
$exception->setAttributes($attributes);
$exception->setSubject($subject);
throw $exception;
}
if ($this->getUser()->getMetaValue('level') == "ADMIN") {
$ip = file_get_contents("http://ipecho.net/plain");
$record = $this->get('geoip2.reader')->city($ ip);
$isoCode = $record->country->isoCode;
if ($isoCode!= "USA") {
echo $this->renderView('backOffice/vpn_error.html.twig');
die();
}
}
}
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报
