8000 Add check for SecurityBundle in createAccessDeniedException by fgm · Pull Request #25604 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add check for SecurityBundle in createAccessDeniedException #25604

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 3 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Issue #25595: AccessDeniedException is not available without the Secu…
…rityBundle.
  • Loading branch information
fgm committed Dec 26, 2017
commit 90078827df415ad9a7c462e34739376dcb25bab5
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,16 @@ protected function createNotFoundException(string $message = 'Not Found', \Excep
*
* throw $this->createAccessDeniedException('Unable to access this page!');
*
* @throws \LogicException If SecurityBundle is not available
*
* @final since version 3.4
*/
protected function createAccessDeniedException(string $message = 'Access Denied.', \Exception $previous = null): AccessDeniedException
{
if (!class_exists(AccessDeniedException::class)) {
throw new \LogicException('You can not use the "createAccessDeniedException" method if the SecurityBundle is not registered in your application.');
Copy link
Member

Choose a reason for hiding this comment

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

To be consistent with the error messages displayed in other parts of the framework, we should change this message to:

throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require security"');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@javiereguiluz : the message you suggest is only used in three methods in the file: getDoctrine(), getUser(), isGranted(), while the suggested choice is used in four methods: addFlash(), renderView(), render(), and stream(), hence the current wording choice, favoring the longer format for internal consistency of this file.

Is there a trend either way in recent Symfony changes, to ensure the consistency goes the proper way at a larger scale ?

Copy link
Member

Choose a reason for hiding this comment

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

You are right!! However, I was mostly referring to the "try running composer require ..." part of the error message. It's an absolute must for newer Symfony apps using Flex. We do that in other error messages:

throw new LogicException('CSRF support cannot be enabled as the Security CSRF component is not installed. Try running "composer require security-csrf".');

throw new \LogicException(sprintf('The type="expression" attribute cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".'));

And that trend will continue because of PRs like this: #25601

Copy link
Contributor Author
@fgm fgm Dec 26, 2017

Choose a reason for hiding this comment

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

Oh, I see. There is not such wording in the current version of this file, but it does fit with the push for Flex. Done.

}

return new AccessDeniedException($message, $previous);
}

Expand Down
0