2015-05-17 19:39:26 +01:00
|
|
|
<?php
|
|
|
|
|
2015-09-21 00:37:42 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-05-17 19:39:26 +01:00
|
|
|
namespace Symfony\Component\Security\Guard;
|
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
2015-05-17 22:35:08 +01:00
|
|
|
use Symfony\Component\Security\Guard\Token\GuardTokenInterface;
|
2015-05-17 19:39:26 +01:00
|
|
|
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
|
|
|
|
|
|
|
/**
|
2015-05-17 23:16:06 +01:00
|
|
|
* The interface for all "guard" authenticators.
|
2015-05-17 19:39:26 +01:00
|
|
|
*
|
|
|
|
* The methods on this interface are called throughout the guard authentication
|
|
|
|
* process to give you the power to control most parts of the process from
|
|
|
|
* one location.
|
|
|
|
*
|
2015-09-21 00:37:42 +01:00
|
|
|
* @author Ryan Weaver <ryan@knpuniversity.com>
|
2015-05-17 19:39:26 +01:00
|
|
|
*/
|
|
|
|
interface GuardAuthenticatorInterface extends AuthenticationEntryPointInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get the authentication credentials from the request and return them
|
|
|
|
* as any type (e.g. an associate array). If you return null, authentication
|
|
|
|
* will be skipped.
|
|
|
|
*
|
2015-05-18 14:14:21 +01:00
|
|
|
* Whatever value you return here will be passed to getUser() and checkCredentials()
|
2015-05-17 19:39:26 +01:00
|
|
|
*
|
|
|
|
* For example, for a form login, you might:
|
|
|
|
*
|
|
|
|
* return array(
|
|
|
|
* 'username' => $request->request->get('_username'),
|
|
|
|
* 'password' => $request->request->get('_password'),
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* Or for an API token that's on a header, you might use:
|
|
|
|
*
|
|
|
|
* return array('api_key' => $request->headers->get('X-API-TOKEN'));
|
|
|
|
*
|
|
|
|
* @param Request $request
|
2015-05-17 23:16:06 +01:00
|
|
|
*
|
2015-05-17 19:39:26 +01:00
|
|
|
* @return mixed|null
|
|
|
|
*/
|
2015-05-18 13:48:41 +01:00
|
|
|
public function getCredentials(Request $request);
|
2015-05-17 19:39:26 +01:00
|
|
|
|
|
|
|
/**
|
2015-05-18 14:45:17 +01:00
|
|
|
* Return a UserInterface object based on the credentials.
|
2015-05-17 19:39:26 +01:00
|
|
|
*
|
2015-05-18 13:48:41 +01:00
|
|
|
* The *credentials* are the return value from getCredentials()
|
2015-05-17 19:39:26 +01:00
|
|
|
*
|
2015-05-18 14:14:21 +01:00
|
|
|
* You may throw an AuthenticationException if you wish. If you return
|
|
|
|
* null, then a UsernameNotFoundException is thrown for you.
|
|
|
|
*
|
2015-05-17 23:16:06 +01:00
|
|
|
* @param mixed $credentials
|
2015-05-17 19:39:26 +01:00
|
|
|
* @param UserProviderInterface $userProvider
|
2015-05-17 23:16:06 +01:00
|
|
|
*
|
2015-05-17 19:39:26 +01:00
|
|
|
* @throws AuthenticationException
|
2015-05-17 23:16:06 +01:00
|
|
|
*
|
2015-05-18 14:14:21 +01:00
|
|
|
* @return UserInterface|null
|
|
|
|
*/
|
|
|
|
public function getUser($credentials, UserProviderInterface $userProvider);
|
|
|
|
|
|
|
|
/**
|
2015-10-30 19:12:11 +00:00
|
|
|
* Returns true if the credentials are valid.
|
|
|
|
*
|
|
|
|
* If any value other than true is returned, authentication will
|
|
|
|
* fail. You may also throw an AuthenticationException if you wish
|
|
|
|
* to cause authentication to fail.
|
2015-05-18 14:14:21 +01:00
|
|
|
*
|
|
|
|
* The *credentials* are the return value from getCredentials()
|
|
|
|
*
|
2015-05-18 14:45:17 +01:00
|
|
|
* @param mixed $credentials
|
2015-05-18 14:14:21 +01:00
|
|
|
* @param UserInterface $user
|
2015-05-18 14:45:17 +01:00
|
|
|
*
|
2015-05-18 14:14:21 +01:00
|
|
|
* @throws AuthenticationException
|
2015-05-17 19:39:26 +01:00
|
|
|
*/
|
2015-05-18 14:14:21 +01:00
|
|
|
public function checkCredentials($credentials, UserInterface $user);
|
2015-05-17 19:39:26 +01:00
|
|
|
|
|
|
|
/**
|
2015-05-17 23:16:06 +01:00
|
|
|
* Create an authenticated token for the given user.
|
2015-05-17 19:39:26 +01:00
|
|
|
*
|
|
|
|
* If you don't care about which token class is used or don't really
|
|
|
|
* understand what a "token" is, you can skip this method by extending
|
|
|
|
* the AbstractGuardAuthenticator class from your authenticator.
|
|
|
|
*
|
|
|
|
* @see AbstractGuardAuthenticator
|
2015-05-17 23:16:06 +01:00
|
|
|
*
|
2015-05-17 19:39:26 +01:00
|
|
|
* @param UserInterface $user
|
2015-05-17 23:16:06 +01:00
|
|
|
* @param string $providerKey The provider (i.e. firewall) key
|
|
|
|
*
|
2015-05-17 22:35:08 +01:00
|
|
|
* @return GuardTokenInterface
|
2015-05-17 19:39:26 +01:00
|
|
|
*/
|
|
|
|
public function createAuthenticatedToken(UserInterface $user, $providerKey);
|
|
|
|
|
|
|
|
/**
|
2015-05-17 23:16:06 +01:00
|
|
|
* Called when authentication executed, but failed (e.g. wrong username password).
|
2015-05-17 19:39:26 +01:00
|
|
|
*
|
|
|
|
* This should return the Response sent back to the user, like a
|
|
|
|
* RedirectResponse to the login page or a 403 response.
|
|
|
|
*
|
|
|
|
* If you return null, the request will continue, but the user will
|
|
|
|
* not be authenticated. This is probably not what you want to do.
|
|
|
|
*
|
2015-05-17 23:16:06 +01:00
|
|
|
* @param Request $request
|
2015-05-17 19:39:26 +01:00
|
|
|
* @param AuthenticationException $exception
|
2015-05-17 23:16:06 +01:00
|
|
|
*
|
2015-05-17 19:39:26 +01:00
|
|
|
* @return Response|null
|
|
|
|
*/
|
|
|
|
public function onAuthenticationFailure(Request $request, AuthenticationException $exception);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when authentication executed and was successful!
|
|
|
|
*
|
|
|
|
* This should return the Response sent back to the user, like a
|
|
|
|
* RedirectResponse to the last page they visited.
|
|
|
|
*
|
|
|
|
* If you return null, the current request will continue, and the user
|
|
|
|
* will be authenticated. This makes sense, for example, with an API.
|
|
|
|
*
|
2015-05-17 23:16:06 +01:00
|
|
|
* @param Request $request
|
2015-05-17 19:39:26 +01:00
|
|
|
* @param TokenInterface $token
|
2015-05-17 23:16:06 +01:00
|
|
|
* @param string $providerKey The provider (i.e. firewall) key
|
|
|
|
*
|
2015-05-17 19:39:26 +01:00
|
|
|
* @return Response|null
|
|
|
|
*/
|
|
|
|
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does this method support remember me cookies?
|
|
|
|
*
|
|
|
|
* Remember me cookie will be set if *all* of the following are met:
|
|
|
|
* A) This method returns true
|
|
|
|
* B) The remember_me key under your firewall is configured
|
|
|
|
* C) The "remember me" functionality is activated. This is usually
|
|
|
|
* done by having a _remember_me checkbox in your form, but
|
|
|
|
* can be configured by the "always_remember_me" and "remember_me_parameter"
|
|
|
|
* parameters under the "remember_me" firewall key
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function supportsRememberMe();
|
|
|
|
}
|