security.rst 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. Security
  2. ========
  3. The current ``AdminBundle`` implementation uses ACL and ROLES to handle permissions.
  4. If you want an easy way to handle users, please use :
  5. - https://github.com/FriendsOfSymfony/UserBundle : handle users and group stored from RDMS or MongoDB
  6. - https://github.com/sonata-project/UserBundle : integrate the ``FriendsOfSymfony/UserBundle`` with
  7. the ``AdminBundle``
  8. The security integration is a work in progress and have some knows issues :
  9. - ACL permissions are immutables
  10. - Only one PermissionMap can be defined
  11. Configuration
  12. -------------
  13. - The following configuration defines :
  14. - the ``FriendsOfSymfony/UserBundle`` as a security provider
  15. - the login form for authentification
  16. - the access control : resources with related required roles, the important part is the admin configuration
  17. - the ``acl`` option enable the ACL.
  18. .. code-block:: yaml
  19. parameters:
  20. # ... other parameters
  21. security.acl.permission.map.class: Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap
  22. security:
  23. providers:
  24. fos_userbundle:
  25. id: fos_user.user_manager
  26. firewalls:
  27. main:
  28. pattern: .*
  29. form-login:
  30. provider: fos_userbundle
  31. login_path: /login
  32. use_forward: false
  33. check_path: /login_check
  34. failure_path: null
  35. logout: true
  36. anonymous: true
  37. access_control:
  38. # The WDT has to be allowed to anonymous users to avoid requiring the login with the AJAX request
  39. - { path: ^/wdt/, role: IS_AUTHENTICATED_ANONYMOUSLY }
  40. - { path: ^/profiler/, role: IS_AUTHENTICATED_ANONYMOUSLY }
  41. # AsseticBundle paths used when using the controller for assets
  42. - { path: ^/js/, role: IS_AUTHENTICATED_ANONYMOUSLY }
  43. - { path: ^/css/, role: IS_AUTHENTICATED_ANONYMOUSLY }
  44. # URL of FOSUserBundle which need to be available to anonymous users
  45. - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  46. - { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY } # for the case of a failed login
  47. - { path: ^/user/new$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  48. - { path: ^/user/check-confirmation-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  49. - { path: ^/user/confirm/, role: IS_AUTHENTICATED_ANONYMOUSLY }
  50. - { path: ^/user/confirmed$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  51. - { path: ^/user/request-reset-password$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  52. - { path: ^/user/send-resetting-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  53. - { path: ^/user/check-resetting-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  54. - { path: ^/user/reset-password/, role: IS_AUTHENTICATED_ANONYMOUSLY }
  55. # Secured part of the site
  56. # This config requires being logged for the whole site and having the admin role for the admin part.
  57. # Change these rules to adapt them to your needs
  58. - { path: ^/admin/, role: ROLE_ADMIN }
  59. - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
  60. role_hierarchy:
  61. ROLE_ADMIN: ROLE_USER
  62. ROLE_SUPERADMIN: [ROLE_ADMIN, ROLE_SONATA_ADMIN, ROLE_ALLOWED_TO_SWITCH]
  63. acl:
  64. connection: default
  65. - Install the ACL tables ``php app/console init:acl``
  66. - Create a new user :
  67. .. code-block::
  68. # php app/console fos:user:create
  69. Please choose a username:root
  70. Please choose an email:root@domain.com
  71. Please choose a password:root
  72. Created user root
  73. - Promote an user as super admin :
  74. .. code-block::
  75. # php app/console fos:user:promote root
  76. User "root" has been promoted as a super administrator.
  77. If you have Admin classes, you can install the related CRUD ACL rules :
  78. .. code-block::
  79. # php app/console sonata:admin:setup-acl
  80. Starting ACL AdminBundle configuration
  81. > install ACL for sonata.media.admin.media
  82. - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_EDIT, ACL: ["EDIT"]
  83. - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_LIST, ACL: ["LIST"]
  84. - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_CREATE, ACL: ["CREATE"]
  85. - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_DELETE, ACL: ["DELETE"]
  86. - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_OPERATOR, ACL: ["OPERATOR"]
  87. ... skipped ...
  88. If you try to access to the admin class you should see the login form, just logon with the ``root`` user.
  89. Usage
  90. -----
  91. Everytime you create a new ``Admin`` class, you should create start the command ``php app/console sonata:admin:setup-acl``
  92. so the ACL database will be updated with the latest masks and roles informations.