Skip to content

Commit b22637c

Browse files
committed
feature #5303 [WIP] 4373 - document security events (kevintweber)
This PR was merged into the 2.3 branch. Discussion ---------- [WIP] 4373 - document security events This is documentation for #4373. This pull request has two parts: * The component/security/authentication additions * The new cookbook security cookbook page. The new cookbook page is designed to give an example of how to use authentication events in an application. I have given example code for two of the four classes needed to throttle failed login attempts. The other two classes are a doctrine entity, and a class containing throttle domain logic, both of which are outside the scope of this documentation. I would welcome any comments and suggestions. Thank you. Commits ------- 0dbabfe Security - Cookbook - removed bad example. 69c0089 Merge branch '4373_Document_Security_Events' of github.com:kevintweber/symfony-docs into 4373_Document_Security_Events a14bd07 Security - Authentication - removed inaccurate tip. f15bea4 Added new cookbook page to security index. 5bdfd71 Better formatting for authentication tip. 9b2e9d8 Better section titles for security events on authentication page. 286f00c Added security event descriptions to security component authentication page.
2 parents 5a38269 + 0dbabfe commit b22637c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

components/security/authentication.rst

+46
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,51 @@ in) is correct, you can use::
268268
$user->getSalt()
269269
);
270270

271+
Authentication Events
272+
---------------------
273+
274+
The security component provides 4 related authentication events:
275+
276+
=============================== ================================================ =========================================================================
277+
Name Event Constant Argument Passed to the Listener
278+
=============================== ================================================ =========================================================================
279+
security.authentication.success ``AuthenticationEvents::AUTHENTICATION_SUCCESS`` :class:`Symfony\Component\Security\Core\Event\AuthenticationEvent`
280+
security.authentication.failure ``AuthenticationEvents::AUTHENTICATION_FAILURE`` :class:`Symfony\Component\Security\Core\Event\AuthenticationFailureEvent`
281+
security.interactive_login ``SecurityEvents::INTERACTIVE_LOGIN`` :class:`Symfony\Component\Security\Http\Event\InteractiveLoginEvent`
282+
security.switch_user ``SecurityEvents::SWITCH_USER`` :class:`Symfony\Component\Security\Http\Event\SwitchUserEvent`
283+
=============================== ================================================ =========================================================================
284+
285+
Authentication Success and Failure Events
286+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287+
288+
When a provider authenticates the user, a ``security.authentication.success``
289+
event is dispatched. Likewise, when a provider attempts authentication but
290+
fails (i.e. throws an ``AuthenticationException``), a
291+
``security.authentication.failure`` event is dispatched. You could listen on
292+
the ``security.authentication.failure`` event, for example, in order to log
293+
failed login attempts.
294+
295+
Security Events
296+
~~~~~~~~~~~~~~~
297+
298+
The ``security.interactive_login`` event is triggered after a user has actively
299+
logged into your website. It is important to distinguish this action from
300+
non-interactive authentication methods, such as:
301+
302+
* authentication based on a "remember me" cookie.
303+
* authentication based on your session.
304+
* authentication using a HTTP basic or HTTP digest header.
305+
306+
You could listen on the ``security.interactive_login`` event, for example, in
307+
order to give your user a welcome flash message every time they log in.
308+
309+
The ``security.switch_user`` event is triggered every time you activate
310+
the ``switch_user`` firewall listener.
311+
312+
.. seealso::
313+
314+
For more information on switching users, see
315+
:doc:`/cookbook/security/impersonating_user`.
316+
271317
.. _`CVE-2013-5750`: https://symfony.com/blog/cve-2013-5750-security-issue-in-fosuserbundle-login-form
272318
.. _`BasePasswordEncoder::checkPasswordLength`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php

0 commit comments

Comments
 (0)