installation.rst 7.4 KB

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