<commit_before>@Security & @IsGranted
======================

Usage
-----

The ``@Security`` and ``@IsGranted`` annotations restrict access on controllers:

.. configuration-block::

    .. code-block:: php-annotations

        use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
        use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;

        class PostController extends Controller
        {
            /**
             * @IsGranted("ROLE_ADMIN")
             *
             * or use @Security for more flexibility:
             *
             * @Security("is_granted('ROLE_ADMIN') and is_granted('ROLE_FRIENDLY_USER')")
             */
            public function index()
            {
                // ...
            }
        }

    .. code-block:: php-attributes

        use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
        use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;

        class PostController extends Controller
        {
            #[IsGranted('ROLE_ADMIN']
            /** or use Security attribute */
            #[Security("is_granted('ROLE_ADMIN') and is_granted('ROLE_FRIENDLY_USER')")]
            public function index()
            {
                // ...
            }
        }


@IsGranted
----------

The ``@IsGranted()`` annotation is the simplest way to restrict access.
Use it to restrict by roles, or use custom voters to restrict access based
on variables passed to the controller:

.. configuration-block::

    .. code-block:: php-annotations

        /**
         * @Route("/posts/{id}")
         *
         * @IsGranted("ROLE_ADMIN")
         * @IsGranted("POST_SHOW", subject="post")
         */
        public function show(Post $post)
        {
        }

    .. code-block:: php-attributes

        #[Route('/posts/{id}')]
        #[IsGranted('ROLE_ADMIN']
        #[IsGranted('POST_SHOW', subject: 'post')]
        public function show(Post $post)
        {
        }

Each ``IsGranted()`` must grant access for the user to have access to the controller.

.. tip::<commit_msg>[Security] Fixed missing closing parenthesis in attributes examples<commit_after>@Security & @IsGranted
======================

Usage
-----

The ``@Security`` and ``@IsGranted`` annotations restrict access on controllers:

.. configuration-block::

    .. code-block:: php-annotations

        use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
        use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;

        class PostController extends Controller
        {
            /**
             * @IsGranted("ROLE_ADMIN")
             *
             * or use @Security for more flexibility:
             *
             * @Security("is_granted('ROLE_ADMIN') and is_granted('ROLE_FRIENDLY_USER')")
             */
            public function index()
            {
                // ...
            }
        }

    .. code-block:: php-attributes

        use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
        use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;

        class PostController extends Controller
        {
            #[IsGranted('ROLE_ADMIN')]
            /** or use Security attribute */
            #[Security("is_granted('ROLE_ADMIN') and is_granted('ROLE_FRIENDLY_USER')")]
            public function index()
            {
                // ...
            }
        }


@IsGranted
----------

The ``@IsGranted()`` annotation is the simplest way to restrict access.
Use it to restrict by roles, or use custom voters to restrict access based
on variables passed to the controller:

.. configuration-block::

    .. code-block:: php-annotations

        /**
         * @Route("/posts/{id}")
         *
         * @IsGranted("ROLE_ADMIN")
         * @IsGranted("POST_SHOW", subject="post")
         */
        public function show(Post $post)
        {
        }

    .. code-block:: php-attributes

        #[Route('/posts/{id}')]
        #[IsGranted('ROLE_ADMIN')]
        #[IsGranted('POST_SHOW', subject: 'post')]
        public function show(Post $post)
        {
        }

Each ``IsGranted()`` must grant access for the user to have access to the controller.

.. tip::
{'fraction_non_alphanumeric': 0.13238770685579196, 'fraction_numerical': 0.0, 'mean_word_length': 1.9504881450488145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7648389', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1133, 'n_words': 256}