installation.rst 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. Installation
  2. ============
  3. Set up the SonataUserBundle
  4. ---------------------------
  5. To begin, add the dependent bundles to the ``vendor/bundles`` directory. Add
  6. the following lines to the file ``deps``::
  7. [SonataUserBundle]
  8. git=git://github.com/sonata-project/SonataUserBundle.git
  9. target=/bundles/Sonata/UserBundle
  10. [SonataEasyExtendsBundle]
  11. git=git://github.com/sonata-project/SonataEasyExtendsBundle.git
  12. target=/bundles/Sonata/EasyExtendsBundle
  13. [SonataAdminBundle]
  14. git=git://github.com/sonata-project/SonataAdminBundle.git
  15. target=/bundles/Sonata/AdminBundle
  16. and run::
  17. bin/vendors install
  18. Autoload and AppKernel Configuration
  19. ------------------------------------
  20. Next, be sure to enable the bundles in your autoload.php and AppKernel.php
  21. files:
  22. .. code-block:: php
  23. <?php
  24. // app/autoload.php
  25. $loader->registerNamespaces(array(
  26. // ...
  27. 'Sonata' => __DIR__.'/../vendor/bundles',
  28. 'Application' => __DIR__,
  29. // ...
  30. ));
  31. // app/appkernel.php
  32. public function registerbundles()
  33. {
  34. return array(
  35. // ...
  36. // You have 2 options to initialize the SonataUserBundle in your AppKernel,
  37. // you can select which bundle SonataUserBundle extends
  38. // extend the ``FOSUserBundle``
  39. new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
  40. // OR
  41. // the bundle will NOT extend ``FOSUserBundle``
  42. new Sonata\UserBundle\SonataUserBundle(),
  43. new Sonata\AdminBundle\SonataAdminBundle(),
  44. new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
  45. // ...
  46. );
  47. }
  48. Generate the ApplicationSonataUserBundle
  49. ----------------------------------------
  50. At this point, the bundle is not yet ready. You need to generate the correct
  51. entities for the media::
  52. php app/console sonata:easy-extends:generate SonataUserBundle
  53. If you specify no parameter, the files are generated in app/Application/Sonata...
  54. but you can specify the path with ``--dest=src``
  55. .. note::
  56. The command will generate domain objects in an ``Application`` namespace.
  57. So you can point entities' associations to a global and common namespace.
  58. This will make Entities sharing easier as your models will allow to
  59. point to a global namespace. For instance the user will be
  60. ``Application\Sonata\UserBundle\Entity\User``.
  61. Set up the ApplicationSonataUserBundle
  62. --------------------------------------
  63. Now, add the new `Application` Bundle into the kernel
  64. .. code-block:: php
  65. <?php
  66. public function registerbundles()
  67. {
  68. return array(
  69. // Application Bundles
  70. // ...
  71. new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
  72. // ...
  73. )
  74. }
  75. Acl Configuration
  76. -----------------
  77. When using ACL, the UserBundle can prevent ``normal`` user to change settings of ``super-admin`` users, to enable this
  78. add to the configuration:
  79. .. code-block:: yaml
  80. # app/config/config.yml
  81. sonata_user:
  82. security_acl: true
  83. # app/config/security.yml
  84. security:
  85. # [...]
  86. acl:
  87. connection: default
  88. Doctrine Configuration
  89. ----------------------
  90. Then add these bundles in the config mapping definition (or enable `auto_mapping <http://symfony.com/doc/2.0/reference/configuration/doctrine.html#configuration-overview>`_):
  91. .. code-block:: yaml
  92. # app/config/config.yml
  93. fos_user:
  94. db_driver: orm # can be orm or odm
  95. firewall_name: main
  96. user_class: Application\Sonata\UserBundle\Entity\User
  97. group:
  98. group_class: Application\Sonata\UserBundle\Entity\Group
  99. doctrine:
  100. orm:
  101. entity_managers:
  102. default:
  103. mappings:
  104. ApplicationSonataUserBundle: ~
  105. SonataUserBundle: ~
  106. Integrating the bundle into the Sonata Admin Bundle
  107. ---------------------------------------------------
  108. Add the related security routing information
  109. .. code-block:: yaml
  110. sonata_user:
  111. resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
  112. prefix: /admin
  113. You also need to define a ``sonata_user_impersonating`` route, used as a redirection after an user impersonating.
  114. Then add a new custom firewall handlers for the admin
  115. .. code-block:: yaml
  116. security:
  117. role_hierarchy:
  118. ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
  119. ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
  120. SONATA:
  121. - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT # if you are using acl then this line must be commented
  122. providers:
  123. fos_userbundle:
  124. id: fos_user.user_manager
  125. firewalls:
  126. # -> custom firewall for the admin area of the URL
  127. admin:
  128. switch_user: true
  129. context: user
  130. pattern: /admin(.*)
  131. form_login:
  132. provider: fos_userbundle
  133. login_path: /admin/login
  134. use_forward: false
  135. check_path: /admin/login_check
  136. failure_path: null
  137. use_referer: true
  138. logout:
  139. path: /admin/logout
  140. target: /admin/login
  141. anonymous: true
  142. # -> end custom configuration
  143. # defaut login area for standard users
  144. main:
  145. switch_user: true
  146. context: user
  147. pattern: .*
  148. form_login:
  149. provider: fos_userbundle
  150. login_path: /login
  151. use_forward: false
  152. check_path: /login_check
  153. failure_path: null
  154. logout: true
  155. anonymous: true
  156. The last part is to define 3 new access control rules :
  157. .. code-block:: yaml
  158. security:
  159. access_control:
  160. # URL of FOSUserBundle which need to be available to anonymous users
  161. - { path: ^/_wdt, role: IS_AUTHENTICATED_ANONYMOUSLY }
  162. - { path: ^/_profiler, role: IS_AUTHENTICATED_ANONYMOUSLY }
  163. - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  164. # -> custom access control for the admin area of the URL
  165. - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  166. - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  167. - { path: ^/admin/login-check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  168. # -> end
  169. - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
  170. - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
  171. # Secured part of the site
  172. # This config requires being logged for the whole site and having the admin role for the admin part.
  173. # Change these rules to adapt them to your needs
  174. - { path: ^/admin, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }
  175. - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
  176. Using the roles
  177. ---------------
  178. Each admin has its own roles, use the user form to assign them to other users. The available roles to assign to others
  179. are limited to the roles available to the user editing the form.