问题是。
我将ADMIN_ROLE配置为模拟任何用户。但我有一个SUPER_AMIN_ROLE,我可以在其中添加新的管理员,并更改一些重要的应用程序的东西。
如何防止这些ADMIN_ROLE冒充我的帐户?
我在这一点上停了下来……
这是我的security.yml文件:
# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
encoders:
AppBundle\Entity\Cliente: bcrypt
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
our_db_provider:
entity:
class: AppBundle:Cliente
property: cpf
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
form_login:
login_path: login
check_path: login
# activate different ways to authenticate
# http_basic: ~
# http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate
# form_login: ~
# http://symfony.com/doc/current/cookbook/security/form_login_setup.html
logout:
path: /logout
target: /login
invalidate_session: true
remember_me:
secret: ~damMe~HIDDED
lifetime: ~damMe~HIDDED
path: /dashboard
switch_user: { role: ROLE_ADMIN }
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/cadastro, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/dashboard, roles: IS_AUTHENTICATED_REMEMBERED }
- { path: ^/cliente, roles: [ IS_AUTHENTICATED_FULLY, USER_ROLE ] }
- { path: ^/indicados, roles: [ IS_AUTHENTICATED_FULLY, USER_ROLE ] }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_REGIONAL, ROLE_ALLOWED_TO_SWITCH]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]发布于 2016-06-18 16:10:32
你可能会,也可能不会,模仿背后没有逻辑。
您可以做的是实现一个事件侦听器来侦听security.switch_user。您的目标用户在其中。您不知道该人员的层次结构分配的实际角色,因此您必须找到另一种方法来确定它们是否可以。就我个人而言,我不喜欢层级结构,因为角色是用来标识而不是授权的。
在这种情况下,您可以抛出异常,但我不确定这对顺序请求的效果如何。
请查看有关此次活动的the documentation。Here您可以查看事件包含的内容。
https://stackoverflow.com/questions/37892858
复制相似问题