我想知道 Symfony 中的安全性是如何工作的。我在security.yaml
这行代码中有:
# Admins can go to /account-management
- { path: '^/account-managent', roles: [ROLE_ADMIN] }
除了具有管理员角色的用户进入 /account-management 和之后的任何内容之外,此拒绝对所有人的访问。
现在我有一个帐户管理控制器。但我想知道我是否需要使用拒绝访问功能,如$this->denyAccessUnlessGranted('ROLE_ADMIN');
or $this->isGranted('ROLE_ADMIN')
。
带有内联注释的控制器:
/**
* @Route("/account-management") // Is this class completely protected by security.yaml? Or does it work function specific?
*/
class AccountManagementController extends AbstractController
{
/**
* @Route("/{id}", name="account_management_delete", methods={"POST"})
*/
public function deleteUser()
{
// I should not need this here right? Since I already have this configured in my security.yaml.
// $this->denyAccessUnlessGranted('ROLE_ADMIN');
# code...
}
public function handleUserData()
{
// Do I need this here? Since there is no route thing connected with this?
$this->denyAccessUnlessGranted('ROLE_ADMIN');
# code...
}
}
那么 security.yaml 是如何工作的呢?什么时候应该使用拒绝访问功能?