Skip to content

Commit

Permalink
Use new Simple{Form,Pre}AuthenticatorInterface namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Nov 28, 2015
1 parent 3ebf2d0 commit 4036d26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
20 changes: 13 additions & 7 deletions cookbook/security/api_key_authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ passed as a query string parameter or via an HTTP header.
The API Key Authenticator
-------------------------

.. versionadded:: 2.8
The ``SimplePreAuthenticatorInterface`` interface was moved to the
``Symfony\Component\Security\Http\Authentication`` namespace in Symfony
2.8. Prior to 2.8, it was located in the
``Symfony\Component\Security\Core\Authentication`` namespace.

Authenticating a user based on the Request information should be done via a
pre-authentication mechanism. The :class:`Symfony\\Component\\Security\\Core\\Authentication\\SimplePreAuthenticatorInterface`
pre-authentication mechanism. The :class:`Symfony\\Component\\Security\\Http\\Authentication\\SimplePreAuthenticatorInterface`
allows you to implement such a scheme really easily.

Your exact situation may differ, but in this example, a token is read
Expand All @@ -27,13 +33,13 @@ value and then a User object is created::
// src/AppBundle/Security/ApiKeyAuthenticator.php
namespace AppBundle\Security;

use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface;

class ApiKeyAuthenticator implements SimplePreAuthenticatorInterface
{
Expand Down Expand Up @@ -273,9 +279,9 @@ you can use to create an error ``Response``.
// src/AppBundle/Security/ApiKeyAuthenticator.php
namespace AppBundle\Security;
use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -506,8 +512,8 @@ for security reasons. To take advantage of the session, update ``ApiKeyAuthentic
to see if the stored token has a valid User object that can be used::

// src/AppBundle/Security/ApiKeyAuthenticator.php
// ...

// ...
class ApiKeyAuthenticator implements SimplePreAuthenticatorInterface
{
// ...
Expand Down
10 changes: 8 additions & 2 deletions cookbook/security/custom_password_authenticator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@ The Password Authenticator
.. versionadded:: 2.6
The ``UserPasswordEncoderInterface`` interface was introduced in Symfony 2.6.

.. versionadded:: 2.8
The ``SimpleFormAuthenticatorInterface`` interface was moved to the
``Symfony\Component\Security\Http\Authentication`` namespace in Symfony
2.8. Prior to 2.8, it was located in the
``Symfony\Component\Security\Core\Authentication`` namespace.

First, create a new class that implements
:class:`Symfony\\Component\\Security\\Core\\Authentication\\SimpleFormAuthenticatorInterface`.
:class:`Symfony\\Component\\Security\\Http\\Authentication\\SimpleFormAuthenticatorInterface`.
Eventually, this will allow you to create custom logic for authenticating
the user::

// src/Acme/HelloBundle/Security/TimeAuthenticator.php
namespace Acme\HelloBundle\Security;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\SimpleFormAuthenticatorInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Http\Authentication\SimpleFormAuthenticatorInterface;

class TimeAuthenticator implements SimpleFormAuthenticatorInterface
{
Expand Down

0 comments on commit 4036d26

Please sign in to comment.