-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Added a helper method to create AccessDeniedException #9405
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…oller
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
use Symfony\Component\DependencyInjection\ContainerAware; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
use Symfony\Component\Form\FormTypeInterface; | ||
use Symfony\Component\Form\Form; | ||
use Symfony\Component\Form\FormBuilder; | ||
|
@@ -139,7 +140,7 @@ public function stream($view, array $parameters = array(), StreamedResponse $res | |
* | ||
* throw $this->createNotFoundException('Page not found!'); | ||
* | ||
* @param string $message A message | ||
* @param string $message A message | ||
* @param \Exception $previous The previous exception | ||
* | ||
* @return NotFoundHttpException | ||
|
@@ -149,6 +150,23 @@ public function createNotFoundException($message = 'Not Found', \Exception $prev | |
return new NotFoundHttpException($message, $previous); | ||
} | ||
|
||
/** | ||
* Returns a AccessDeniedException. | ||
* | ||
* This will result in a 403 response code. Usage example: | ||
* | ||
* throw $this->createAccessDeniedException('Unable to access this page!'); | ||
* | ||
* @param string $message A message | ||
* @param \Exception $previous The previous exception | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* | ||
* @return AccessDeniedException | ||
*/ | ||
public function createAccessDeniedException($message = 'Access Denied', \Exception $previous = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wonder why these methods on the base controller are public? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but we can change that now, can't we? It would not break backwards compatibility as nobody should execute controller methods from outside the controller. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But what if someone overrode the method in a controller? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, yes. It would be a BC break. You guys always surprise me when discovering it's a BC break... :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fabpot overwriting a protected method by making it public is allowed. The forbidden case is the opposite There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so shouldn't this new method be protected then at least? changing the other can still be decided later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, changing this method to protected and all other one should definitely by done. |
||
{ | ||
return new AccessDeniedException($message, $previous); | ||
} | ||
|
||
/** | ||
* Creates and returns a Form instance from the type of the form. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
an
here.