Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
teebbstudios
teebblog
提交
d0455e01
T
teebblog
项目概览
teebbstudios
/
teebblog
通知
0
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
teebblog
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d0455e01
编写于
7月 21, 2021
作者:
T
teebbstudios
提交者:
伟伟权
7月 21, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
85. @IsGranted() and isGranted() and denyAccessUnlessGranted() for controller function
上级
5b9e4cca
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
1 deletion
+13
-1
config/packages/security.yaml
config/packages/security.yaml
+1
-1
src/Controller/Admin/DashboardController.php
src/Controller/Admin/DashboardController.php
+6
-0
src/DataFixtures/AppFixtures.php
src/DataFixtures/AppFixtures.php
+6
-0
未找到文件。
config/packages/security.yaml
浏览文件 @
d0455e01
...
...
@@ -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 }
src/Controller/Admin/DashboardController.php
浏览文件 @
d0455e01
...
...
@@ -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
();
}
...
...
src/DataFixtures/AppFixtures.php
浏览文件 @
d0455e01
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录