Роль безопасности всегда на ROLE_USER
Первый пост для меня! Я надеюсь, что вы можете помочь мне:). Это моя проблема.
У меня есть база данных с пользователем, и у каждого пользователя одна роль. Я редактирую security.yaml, но когда я регистрируюсь с некоторыми пользователями, все они имеют ROLE_USER. Когда я вхожу в систему с пользователем, у которого есть ROLE_ADMIN, он получает ROLE_USER...
Кто-нибудь может мне помочь, пожалуйста!:)
Security.yaml
security:
encoders:
App\Entity\User:
algorithm: argon2i
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
guard:
authenticators:
- App\Security\LoginFormAuthenticator
# activate different ways to authenticate
# http_basic: true
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
# form_login: true
# https://symfony.com/doc/current/security/form_login_setup.html
# 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_ADMIN }
- { path: ^/forum/category/new, roles: ROLE_ADMIN }
- { path: ^/article/new, roles: ROLE_AUTHOR}
- { path: ^/article/edit/\d+$, roles: ROLE_AUTHOR}
- { path: ^/forum/post/category/\d+$/new, roles: ROLE_USER}
- { path: ^/forum/comment/post/\d+$/new, roles: ROLE_USER}
- { path: ^/deck/myDeck/\d+$, roles: ROLE_USER}
- { path: ^/deck/new, roles: ROLE_USER}
- { path: ^/home, roles: IS_AUTHENTICATED_ANONYMOUSLY }
role_hierarchy:
ROLE_USER: [ROLE_USER]
ROLE_AUTHOR: [ROLE_AUTHOR, ROLE_USER]
ROLE_ADMIN: [ROLE_AUTHOR, ROLE_ADMIN, ROLE_USER]
Пользовательский объект
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $pseudo;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $profilePicture;
/**
* @Gedmo\Slug(fields={"pseudo"})
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*/
private $slug;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ForumPost", mappedBy="User")
*/
private $forumPosts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Role", inversedBy="users")
*/
private $Role;
/**
* @ORM\OneToMany(targetEntity="App\Entity\DeckComment", mappedBy="User")
*/
private $deckComments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ArticleComment", mappedBy="user")
*/
private $articleComments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="user")
*/
private $articles;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Deck", mappedBy="user")
*/
private $decks;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ForumComment", mappedBy="user")
*/
private $forumComments;
Ролевая сущность
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $code;
/**
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="Role")
*/
private $users;
Я исключаю, что у каждого пользователя есть своя роль