我是symfony的新手,而且很难理解有关安全性的文档。所以我在这里希望有人可以帮我一下。我一直在研究教师(profesores)和学生(alumnos),然后每个人都可以访问各自的区域(/profesores/.*和/alumnos/.*)。但是,当我访问这些URL时,会显示浏览器登录名,但是它们没有从各自的实体中获取创建的用户。
我的安全性设置如下: 安全性:
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
area_profesores:
pattern: /profesores/.*
provider: profesores_desde_bd
switch_user:
role: ROLE_PROFESOR
anonymous: ~
form_login:
check_path: /profesores/login_check
login_path: /profesores/login
logout:
path: /profesores/logout
target: /portada/
area_alumnos:
pattern: /alumnos/.*
provider: alumnos_desde_bd
switch_user:
role: ROLE_ALUMNO
anonymous: ~
form_login:
check_path: /alumnos/login_check
login_path: /alumnos/login
logout:
path: /alumnos/logout
target: /portada/
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
http_basic: ~
access_control:
- { path: ^/profesores, roles: ROLE_PROFESOR}
- { path: ^/alumnos, roles: ROLE_ALUMNO }
- { path: /login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
profesores_desde_bd:
entity:
class: AppBundle\Entity\Profesores
property: username
alumnos_desde_bd:
entity:
class: AppBundle\Entity\Alumnos
property: username
encoders:
AppBundle\Entity\Profesores:
algorithm: bcrypt
cost: 12
iterations: 0
AppBundle\Entity\Alumnos:
algorithm: bcrypt
cost: 12
iterations: 0
Symfony\Component\Security\Core\User\User:
algorithm: bcrypt
cost: 12
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
#http_basic: ~
# https://symfony.com/doc/current/security/form_login_setup.html
#form_login: ~
答案 0 :(得分:0)
答案是:
我需要删除 主要: 匿名:〜 http_basic:〜 因为该身份验证无法登录。