Skip to content

Minor update #10878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ Users with the ``ROLE_ADMIN`` role will also have the
``ROLE_USER`` role. And users with ``ROLE_SUPER_ADMIN``, will automatically have
``ROLE_ADMIN``, ``ROLE_ALLOWED_TO_SWITCH`` and ``ROLE_USER`` (inherited from ``ROLE_ADMIN``).

For role hierarchy to work, do not try to call ``$user->getRoles()`` manually::
For role hierarchy to work, do not try to call ``$user->getRoles()`` manually in a controller::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in your code in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, don't understand what you mean :-(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry,

I mean :

For role hierarchy to work, do not try to call $user->getRoles() manually in a controller or any other part of your code, prefer using the role hierarchy service

thing like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aspect I wanted to emphasize is that the recommended way ($this->isGranted) is not working where I would have expected it to work, namely in the Authenticator. So I figured it only works in a controller ;-) So the real question is: What's the recommended way to do it in an Authenticator?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean calling isGranted() did not work because the method is not defined in the authenticator context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Cause I would have assumed it works there.


// BAD - $user->getRoles() will not know about the role hierarchy
$hasAccess = in_array('ROLE_ADMIN', $user->getRoles());
Expand All @@ -926,8 +926,8 @@ For role hierarchy to work, do not try to call ``$user->getRoles()`` manually::
:doc:`security voter </security/voters>` that looks for the user roles
in the database.

Checking for Security Vulnerabilities in your Dependences
---------------------------------------------------------
Checking for Security Vulnerabilities in your Dependencies
----------------------------------------------------------

See :doc:`/security/security_checker`.

Expand Down