-
-
Couldn't load subscription status.
- Fork 5.3k
Added the documentation for the success/failure handlers #6556
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
Closed
Changes from 1 commit
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
8bb5331 Added the documentation for the success/failure handlers
javiereguiluz 7d562db Added the explanation of the last section
javiereguiluz 7dde7b1 Fixes
javiereguiluz 362a09f Added all the configuration formats
javiereguiluz c3119e7 Fixed a grammar issue
javiereguiluz ecfd34d Fixed some copy+paste errors
javiereguiluz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added all the configuration formats
- Loading branch information
commit 362a09fad2f84f034ba67fb7a509942a9b247c48
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -41,25 +41,88 @@ and add your own logic:: | |
| | ||
| Then, define a new service for this login handler: | ||
| | ||
| .. code-block:: yaml | ||
| .. configuration-block:: | ||
| | ||
| # app/config/services.yml | ||
| services: | ||
| app.security.success_login: | ||
| class: AppBundle\Security\SuccesfulLoginHandler | ||
| .. code-block:: yaml | ||
| | ||
| # app/config/services.yml | ||
| services: | ||
| app.security.success_login: | ||
| class: AppBundle\Security\SuccesfulLoginHandler | ||
| | ||
| .. code-block:: xml | ||
| | ||
| <!-- src/AppBundle/Resources/config/services.xml --> | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <container xmlns="http://symfony.com/schema/dic/services" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
| | ||
| <services> | ||
| <service id="app.security.success_login" | ||
| class="AppBundle\Security\SuccesfulLoginHandler"> | ||
| </service> | ||
| </services> | ||
| </container> | ||
| | ||
| .. code-block:: php | ||
| | ||
| // src/AppBundle/Resources/config/services.php | ||
| ||
| $container->register( | ||
| 'app.security.success_login', | ||
| 'AppBundle\Security\SuccesfulLoginHandler' | ||
| ); | ||
| | ||
| Lastly, add a new ``success_handler`` option under the configuration of the | ||
| firewalls where this handler will be enabled and pass the ``id`` of the service | ||
| as its value: | ||
| | ||
| .. code-block:: yaml | ||
| | ||
| # app/config/security.yml | ||
| firewalls: | ||
| main: | ||
| pattern: ^/ | ||
| form_login: | ||
| success_handler: app.security.successful_login | ||
| .. configuration-block:: | ||
| | ||
| .. code-block:: yaml | ||
| | ||
| # app/config/security.yml | ||
| security: | ||
| # ... | ||
| firewalls: | ||
| main: | ||
| # ... | ||
| form_login: | ||
| success_handler: app.security.successful_login | ||
| | ||
| .. code-block:: xml | ||
| | ||
| <!-- app/config/security.xml --> | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <srv:container xmlns="http://symfony.com/schema/dic/security" | ||
| xmlns:srv="http://symfony.com/schema/dic/services" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
| http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
| | ||
| <config> | ||
| <!-- ... --> | ||
| <firewall name="main"> | ||
| <!-- ... --> | ||
| <form-login success-handler="app.security.successful_login" /> | ||
| </firewall> | ||
| </config> | ||
| </srv:container> | ||
| | ||
| .. code-block:: php | ||
| | ||
| // app/config/security.php | ||
| $container->loadFromExtension('security', array( | ||
| // ... | ||
| 'firewalls' => array( | ||
| 'main' => array( | ||
| // ... | ||
| 'form_login' => array( | ||
| 'success_handler' => 'app.security.successful_login', | ||
| ), | ||
| ), | ||
| ), | ||
| )); | ||
| | ||
| Creating a Failure Login Handler | ||
| -------------------------------- | ||
| | @@ -70,14 +133,52 @@ First, define your own logic in a class that implements | |
| and create a new service for it. Then, add the ``failure_handler`` configuration | ||
| option in your firewall: | ||
| | ||
| .. code-block:: yaml | ||
| | ||
| # app/config/security.yml | ||
| firewalls: | ||
| main: | ||
| pattern: ^/ | ||
| form_login: | ||
| failure_handler: app.security.failure_login | ||
| .. configuration-block:: | ||
| | ||
| .. code-block:: yaml | ||
| | ||
| # app/config/security.yml | ||
| security: | ||
| # ... | ||
| firewalls: | ||
| main: | ||
| # ... | ||
| form_login: | ||
| failure_handler: app.security.failure_login | ||
| | ||
| .. code-block:: xml | ||
| | ||
| <!-- app/config/security.xml --> | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <srv:container xmlns="http://symfony.com/schema/dic/security" | ||
| xmlns:srv="http://symfony.com/schema/dic/services" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
| http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
| | ||
| <config> | ||
| <!-- ... --> | ||
| <firewall name="main"> | ||
| <!-- ... --> | ||
| <form-login failure-handler="app.security.failure_login" /> | ||
| </firewall> | ||
| </config> | ||
| </srv:container> | ||
| | ||
| .. code-block:: php | ||
| | ||
| // app/config/security.php | ||
| $container->loadFromExtension('security', array( | ||
| // ... | ||
| 'firewalls' => array( | ||
| 'main' => array( | ||
| // ... | ||
| 'form_login' => array( | ||
| 'failure_handler' => 'app.security.failure_login', | ||
| ), | ||
| ), | ||
| ), | ||
| )); | ||
| | ||
| When Should Login Handlers Be Used? | ||
| ----------------------------------- | ||
| | ||
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.
app/config/services.xmlThere 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.
Nice catch! Damn copy+paste :( Fixed.