提交 d0455e01 编写于 作者: T teebbstudios 提交者: 伟伟权

85. @IsGranted() and isGranted() and denyAccessUnlessGranted() for controller function

上级 5b9e4cca
......@@ -40,5 +40,5 @@ security:
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/admin, roles: ROLE_SUPER_ADMIN }
# - { path: ^/admin, roles: ROLE_SUPER_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
......@@ -7,8 +7,10 @@ use App\Entity\Post;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class DashboardController extends AbstractDashboardController
{
......@@ -17,6 +19,10 @@ class DashboardController extends AbstractDashboardController
*/
public function index(): Response
{
// if (!$this->isGranted('ROLE_SUPER_ADMIN')){
// throw new AccessDeniedException();
// }
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN ');
return parent::index();
}
......
......@@ -38,9 +38,15 @@ class AppFixtures extends Fixture
$expiredUser->setExpiredAt(new \DateTime('-1 day'));
$expiredUser->setPassword($this->userPasswordHasher->hashPassword($expiredUser, '123'));
$tom = new User();
$tom->setUsername('tom');
$tom->setPassword($this->userPasswordHasher->hashPassword($tom, 'tom'));
$manager->persist($admin);
$manager->persist($deletedUser);
$manager->persist($expiredUser);
$manager->persist($tom);
$manager->flush();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册