[英]Symfony 4: cannot access as ROLE_ADMIN
My Roles column value: ["ROLE_ADMIN"]
我的角色列值: ["ROLE_ADMIN"]
My Entity/User: 我的实体/用户:
/**
* @ORM\Column(type="json", nullable=true)
*/
private $roles = [];
public function getRoles() : ?array {
$roles = $this->roles;
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
The $currentUser->getRoles();
$currentUser->getRoles();
gives me this in var_dump
: 在var_dump
给我这个:
array(2) { [0]=> string(10) "ROLE_ADMIN" [1]=> string(9) "ROLE_USER" }
My security.yaml: 我的security.yaml:
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
The Profiler Toolbar tells me that I'm logged in. Profiler工具栏告诉我我已登录。
But still I see the message: 但我仍然看到了这样的信息:
Symfony\Component\HttpKernel\Exception\
AccessDeniedHttpException
But when I change my security.yaml to: 但是当我将security.yaml更改为:
access_control:
- { path: ^/admin, roles: ROLE_USER }
Then the Exception disappears. 然后Exception消失了。
Did I miss something? 我错过了什么?
Try to logout and login, symfony keeps roles in remember me token, you can check your currently assigned roles in profiler, security tab. 尝试注销并登录,symfony将角色保留在记住我的令牌中,您可以在profiler,security选项卡中检查当前分配的角色。 Most probably role is not in remember me cookie, that's why it doesnt let you access. 最有可能的角色不是记住我的cookie,这就是为什么它不会让你访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.