Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] Expose the required roles in AccessDeniedException#19473

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromNicofuma:exp_role_ad
Aug 9, 2016

Conversation

@Nicofuma
Copy link
Contributor

@NicofumaNicofuma commentedJul 29, 2016
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
LicenseMIT

Nowadays it is more and more common to protect some sensitive actions and part of a website using 2FA or some re-authentication mechanism (per example, on Github you have to enter your password again when you add an ssh key). But currently, in Symfony, it is really hard to implement without having to duplicate the logic, provide an explicit list of URLs to protect or hack into the security component.

A good way to achieve that would be to add a special role (like IS_AUTHENTICATED_FULLY) and use it in the access map. But it requires us to be able to have a custom logic in an ExceptionListener depending on the roles behind an AccessDeniedException.

With this patch we could write an ExceptionListener of this kind (a similar logic could also be used in an AccessDeniedHandler):

publicfunctiononKernelException(GetResponseForExceptionEvent$event)    {$exception =$event->getException();do {if ($exceptioninstanceof AccessDeniedException) {foreach ($exception->getAttributes()as$role) {if ($role ==='IS_AUTHENTICATED_2FA' && !$this->accessDecisionManager->decide($this->tokenStorage->getToken(),$role,$exception->getObject())) {// Start 2FA                    }                }            }        }while (null !==$exception =$exception->getPrevious());    }

Replaces#18661

mickaelandrieu reacted with thumbs up emoji
@HeahDude
Copy link
Contributor

Tests are failing

Status: Needs Work

@HeahDude
Copy link
Contributor

👍 Thanks Tristan!

Status: Reviewed

@fabpot
Copy link
Member

👍

@stof
Copy link
Member

👍

Would be great to open a PR on SensioFrameworkExtraBundle making use of these setters when they are available, for its checks on the@Security annotation

throw$this->createAccessDeniedException($message);
$exception =$this->createAccessDeniedException($message);
$exception->setAttributes($attributes);
$exception->setObject($object);
Copy link
Contributor

Choose a reason for hiding this comment

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

The object doesn't have to be an object as far as I know. Since a recent version scalars are also supported I believe. Not sure if setObject is still correct in that case.

jvasseur reacted with thumbs up emojiHeahDude reacted with thumbs down emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

object is the name already used by the security component

Copy link
Contributor

Choose a reason for hiding this comment

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

The VoterInterface use subjet instead of object.

ogizanagi and lyrixx reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Indeed, I would call itSubject

@nicolas-grekas
Copy link
Member

👍

@fabpot
Copy link
Member

Thank you@Nicofuma.

@fabpotfabpot merged commit6618c18 intosymfony:masterAug 9, 2016
fabpot added a commit that referenced this pull requestAug 9, 2016
…ception (Nicofuma)This PR was merged into the 3.2-dev branch.Discussion----------[Security] Expose the required roles in AccessDeniedException| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| License       | MITNowadays it is more and more common to protect some sensitive actions and part of a website using 2FA or some re-authentication mechanism (per example, on Github you have to enter your password again when you add an ssh key). But currently, in Symfony, it is really hard to implement without having to duplicate the logic, provide an explicit list of URLs to protect or hack into the security component.A good way to achieve that would be to add a special role (like IS_AUTHENTICATED_FULLY) and use it in the access map. But it requires us to be able to have a custom logic in an ExceptionListener depending on the roles behind an AccessDeniedException.With this patch we could write an ExceptionListener of this kind (a similar logic could also be used in an AccessDeniedHandler):```php    public function onKernelException(GetResponseForExceptionEvent $event)    {        $exception = $event->getException();        do {            if ($exception instanceof AccessDeniedException) {                foreach ($exception->getAttributes() as $role) {                    if ($role === 'IS_AUTHENTICATED_2FA' && !$this->accessDecisionManager->decide($this->tokenStorage->getToken(), $role, $exception->getObject())) {                        // Start 2FA                    }                }            }        } while (null !== $exception = $exception->getPrevious());    }```Replaces#18661Commits-------6618c18 [Security] Expose the required roles in AccessDeniedException
fabpot added a commit that referenced this pull requestSep 19, 2016
…ct (xabbuh)This PR was merged into the 3.2-dev branch.Discussion----------[Security] AccessDeniedException: rename object to subject| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#19473 (comment)| License       | MIT| Doc PR        |With this change the name is inline with what we use in the base voterinterface.Commits-------9603ffa AccessDeniedException: rename object to subject
@fabpotfabpot mentioned this pull requestOct 27, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

9 participants

@Nicofuma@HeahDude@fabpot@stof@nicolas-grekas@lyrixx@jvasseur@linaori@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp