Security ======== Users management ---------------- By default, the SonataAdminBundle does not come with any user management, however it is most likely the application requires such feature. The Sonata Project includes a ``SonataUserBundle`` which integrates the ``FOSUserBundle``. The ``FOSUserBundle`` adds support for a database-backed user system in Symfony2. It provides a flexible framework for user management that aims to handle common tasks such as user login, registration and password retrieval. The ``SonataUserBundle`` is just a thin wrapper to include the ``FOSUserBundle`` into the ``AdminBundle``. The ``SonataUserBundle`` includes : * A default login area * A default ``user_block`` template which is used to display the current user and the logout link * 2 Admin classes : User and Group * A default class for User and Group. There is a little magic in the ``SonataAdminBundle`` if the bundle detects the ``SonataUserBundle`` class, then the default ``user_block`` template will be changed to use the one provided by the ``SonataUserBundle``. The install process is available on the dedicated `SonataUserBundle's documentation area `_ Security handlers ----------------- The security part is managed by a ``SecurityHandler``, the bundle has 2 handlers - ``sonata.admin.security.handler.acl`` : ACL and ROLES to handle permissions - ``sonata.admin.security.handler.noop`` : always returns true, can be used with the Symfony2 firewall The default value is ``sonata.admin.security.handler.noop``, if you want to change the default value you can set the ``security_handler`` to ``sonata.admin.security.handler.acl``. .. code-block:: yaml # app/config/config.yml sonata_admin: security_handler: sonata.admin.security.handler.acl The following section explains how to set up ACL with the ``FriendsOfSymfony/UserBundle``. ACL and FriendsOfSymfony/UserBundle ----------------------------------- If you want an easy way to handle users, please use : - https://github.com/FriendsOfSymfony/FOSUserBundle : handle users and groups stored in RDMS or MongoDB - https://github.com/sonata-project/SonataUserBundle : integrates the ``FriendsOfSymfony/UserBundle`` with the ``AdminBundle`` The security integration is a work in progress and has some known issues : - ACL permissions are immutables - Only one PermissionMap can be defined Configuration ~~~~~~~~~~~~~ Before you can use ``FriendsOfSymfony/FOSUserBundle`` you need to set it up as described in the documentation of the bundle. In step 4 you need to create a User class (in a custom UserBundle). Do it as follows: .. code-block:: php install ACL for sonata.media.admin.media - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_EDIT, ACL: ["EDIT"] - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_LIST, ACL: ["LIST"] - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_CREATE, ACL: ["CREATE"] - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_DELETE, ACL: ["DELETE"] - add role: ROLE_SONATA_MEDIA_ADMIN_MEDIA_OPERATOR, ACL: ["OPERATOR"] ... skipped ... If you try to access the admin class you should see the login form, just logon with the ``root`` user. Usage ~~~~~ Everytime you create a new ``Admin`` class, you should create ACL by using the command ``php app/console sonata:admin:setup-acl`` so the ACL database will be updated with the latest masks and roles informations.