I was wondering how the security works in Symfony. I have in security.yaml
this line of code:
# Admins can go to /account-management
- { path: '^/account-managent', roles: [ROLE_ADMIN] }
This deny's access to everyone except users with admin roles going to /account-management and anything after.
Now I have a account management controller. But I am wondering if I ever need to use a deny access function like $this->denyAccessUnlessGranted('ROLE_ADMIN');
or $this->isGranted('ROLE_ADMIN')
.
Controller with inline comments:
/**
* @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...
}
}
So how does the security.yaml work? And when should the deny access functions be used?