Skip to content

Add documentation about access denied handler #7105

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 6 commits into from

Conversation

nykopol
Copy link
Contributor

@nykopol nykopol commented Oct 31, 2016

Fix #5139

custom_handler.service.id:
class: AppBundle\Security\AccessDeniedHandler

That's it, now on the ``foo`` firewall, all ``AccessDeniedException`` will be notified to you service.
Copy link
Contributor

Choose a reason for hiding this comment

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

- to you service.
+ to your service.

How to Create a Custom Access Denied Handler
============================================

When your application throw an ``AccessDeniedException`` you can catch this exception
Copy link
Member

Choose a reason for hiding this comment

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

throws

Copy link
Member

Choose a reason for hiding this comment

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

missing comma before "you"

'access_denied_handler' => 'custom_handler.service.id',
),
),
));
Copy link
Member

Choose a reason for hiding this comment

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

Can you please also add an XML config example?

));


Your handler must implement the interface
Copy link
Member

Choose a reason for hiding this comment

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

we can omit "interface" here


Your handler must implement the interface
:class:`Symfony\\Component\\Security\\Http\\Authorization\\AccessDeniedHandlerInterface`.
This interface define one method called ``handle()`` that can do whatever you want.
Copy link
Member

Choose a reason for hiding this comment

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

defines

Copy link
Member

Choose a reason for hiding this comment

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

I would reword this a bit:

[...] that implements the logic you want to execute when access is denied to the current user.

Your handler must implement the interface
:class:`Symfony\\Component\\Security\\Http\\Authorization\\AccessDeniedHandlerInterface`.
This interface define one method called ``handle()`` that can do whatever you want.
You can use it to send a mail, log a message, or generally return a custom Response.
Copy link
Member

Choose a reason for hiding this comment

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

This could then be enclosed with parentheses after the previous sentence.

This interface define one method called ``handle()`` that can do whatever you want.
You can use it to send a mail, log a message, or generally return a custom Response.


Copy link
Member

Choose a reason for hiding this comment

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

Please remove one blank line.


.. code-block:: php

namespace AppBundle\Security;
Copy link
Member

Choose a reason for hiding this comment

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

We should better not use AppBundle in this 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.

What would be a good place for this class ? For me AppBundle\Security look like a perfect default place for a Foo project.

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry, I was confused. Of course let's keep it as is.

use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
Copy link
Member

Choose a reason for hiding this comment

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

Can you please sort the use statements alphabetically?

@nykopol
Copy link
Contributor Author

nykopol commented Nov 3, 2016

@xabbuh thanks for your review.

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

👍 another missing feature documented! Thanks a lot @nykopol.

I've made some minor rewords in your original article. If you don't agree with something, please tell us. Thanks!

@nykopol
Copy link
Contributor Author

nykopol commented Nov 21, 2016

@javiereguiluz LGTM, thanks

xabbuh added a commit that referenced this pull request Nov 28, 2016
… javiereguiluz)

This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #7105).

Discussion
----------

Add documentation about access denied handler

Fix #5139

Commits
-------

ea4b7f8 Minor rewordings
dff303c When talking about generic responses, don't spell it as Response (which is a Symfony class)
a9f815a xabbuh review
66c0e76 fix typo
db65dd8 fix yml marker to yaml
a17965e add documentation about access denied handler
xabbuh added a commit that referenced this pull request Nov 28, 2016
@xabbuh
Copy link
Member

xabbuh commented Nov 28, 2016

Thank you @nykopol for your great work on this PR. I have merged your changes and made some minor tweaks in c698051.

@xabbuh xabbuh closed this Nov 28, 2016
xabbuh added a commit that referenced this pull request Dec 1, 2016
* 2.7: (31 commits)
  fix a typo
  [#7115] fix headlines
  Better explain the most common problems when testing emails
  Clarify the mappings that require no method prefix.
  Make some long lines shorter to fit our soft limit of 80 chars per line
  Microsoft Azure update step by step article and screenshots for the new Microsoft Azure Portal
  Minor rewords in the text and the code example
  Update questionhelper.rst
  Add docs about console question answer normalizing.
  [#7105] add XML and PHP service config examples
  Minor rewordings
  When talking about generic responses, don't spell it as Response (which is a Symfony class)
  xabbuh review
  fix typo
  fix yml marker to yaml
  add documentation about access denied handler
  Update outdated link to AWS ELB security groups
  Added missing comma
  Reworded the caution about open redirects
  Warn user about open redirects
  ...
xabbuh added a commit that referenced this pull request Dec 2, 2016
* 2.8: (37 commits)
  fix a typo
  [#7115] fix headlines
  Better explain the most common problems when testing emails
  Clarify the mappings that require no method prefix.
  Make some long lines shorter to fit our soft limit of 80 chars per line
  Microsoft Azure update step by step article and screenshots for the new Microsoft Azure Portal
  Minor rewords in the text and the code example
  Update questionhelper.rst
  Add docs about console question answer normalizing.
  [#7105] add XML and PHP service config examples
  Minor rewordings
  When talking about generic responses, don't spell it as Response (which is a Symfony class)
  xabbuh review
  fix typo
  fix yml marker to yaml
  add documentation about access denied handler
  Update outdated link to AWS ELB security groups
  Added missing comma
  Reworded the caution about open redirects
  Warn user about open redirects
  ...
xabbuh added a commit that referenced this pull request Dec 2, 2016
* 3.1: (41 commits)
  fix a typo
  [#7115] fix headlines
  Better explain the most common problems when testing emails
  Clarify the mappings that require no method prefix.
  Make some long lines shorter to fit our soft limit of 80 chars per line
  Microsoft Azure update step by step article and screenshots for the new Microsoft Azure Portal
  Minor rewords in the text and the code example
  Update questionhelper.rst
  Add docs about console question answer normalizing.
  [#7105] add XML and PHP service config examples
  Minor rewordings
  When talking about generic responses, don't spell it as Response (which is a Symfony class)
  xabbuh review
  fix typo
  fix yml marker to yaml
  add documentation about access denied handler
  Update outdated link to AWS ELB security groups
  Added missing comma
  Reworded the caution about open redirects
  Warn user about open redirects
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants