Thanks fabbot!
This commit is contained in:
parent
6c180c78da
commit
c73c32e674
@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Configures the "guard" authentication provider key under a firewall
|
||||
* Configures the "guard" authentication provider key under a firewall.
|
||||
*
|
||||
* @author Ryan Weaver <weaverryan@gmail.com>
|
||||
*/
|
||||
|
@ -59,13 +59,13 @@ class GuardAuthenticationFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
array(
|
||||
'authenticators' => array('authenticator1', 'authenticator2'),
|
||||
'provider' => 'some_provider',
|
||||
'entry_point' => 'the_entry_point'
|
||||
'entry_point' => 'the_entry_point',
|
||||
),
|
||||
array(
|
||||
'authenticators' => array('authenticator1', 'authenticator2'),
|
||||
'provider' => 'some_provider',
|
||||
'entry_point' => 'the_entry_point'
|
||||
)
|
||||
'entry_point' => 'the_entry_point',
|
||||
),
|
||||
);
|
||||
|
||||
// testing xml config fix: authenticator -> authenticators
|
||||
@ -76,7 +76,7 @@ class GuardAuthenticationFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
array(
|
||||
'authenticators' => array('authenticator1', 'authenticator2'),
|
||||
'entry_point' => null,
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
return $tests;
|
||||
@ -88,7 +88,7 @@ class GuardAuthenticationFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// testing not empty
|
||||
$tests[] = array(
|
||||
array('authenticators' => array())
|
||||
array('authenticators' => array()),
|
||||
);
|
||||
|
||||
return $tests;
|
||||
@ -108,7 +108,7 @@ class GuardAuthenticationFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array(
|
||||
'index_0' => array(new Reference('authenticator123')),
|
||||
'index_1' => new Reference('my_user_provider'),
|
||||
'index_2' => 'my_firewall'
|
||||
'index_2' => 'my_firewall',
|
||||
), $providerDefinition->getArguments());
|
||||
|
||||
$listenerDefinition = $container->getDefinition('security.authentication.listener.guard.my_firewall');
|
||||
@ -153,7 +153,6 @@ class GuardAuthenticationFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$this->executeCreate($config, null);
|
||||
}
|
||||
|
||||
|
||||
public function testCreateWithEntryPoint()
|
||||
{
|
||||
// any existing default entry point is used
|
||||
|
@ -6,7 +6,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
|
||||
|
||||
/**
|
||||
* An optional base class that creates a PostAuthenticationGuardToken for you
|
||||
* An optional base class that creates a PostAuthenticationGuardToken for you.
|
||||
*
|
||||
* @author Ryan Weaver <weaverryan@gmail.com>
|
||||
*/
|
||||
@ -14,10 +14,11 @@ abstract class AbstractGuardAuthenticator implements GuardAuthenticatorInterface
|
||||
{
|
||||
/**
|
||||
* Shortcut to create a PostAuthenticationGuardToken for you, if you don't really
|
||||
* care about which authenticated token you're using
|
||||
* care about which authenticated token you're using.
|
||||
*
|
||||
* @param UserInterface $user
|
||||
* @param string $providerKey
|
||||
* @param string $providerKey
|
||||
*
|
||||
* @return PostAuthenticationGuardToken
|
||||
*/
|
||||
public function createAuthenticatedToken(UserInterface $user, $providerKey)
|
||||
|
@ -16,7 +16,7 @@ use Symfony\Component\Security\Http\Firewall\ListenerInterface;
|
||||
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
|
||||
|
||||
/**
|
||||
* Authentication listener for the "guard" system
|
||||
* Authentication listener for the "guard" system.
|
||||
*
|
||||
* @author Ryan Weaver <weaverryan@gmail.com>
|
||||
*/
|
||||
@ -30,11 +30,11 @@ class GuardAuthenticationListener implements ListenerInterface
|
||||
private $rememberMeServices;
|
||||
|
||||
/**
|
||||
* @param GuardAuthenticatorHandler $guardHandler The Guard handler
|
||||
* @param AuthenticationManagerInterface $authenticationManager An AuthenticationManagerInterface instance
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
* @param GuardAuthenticatorInterface[] $guardAuthenticators The authenticators, with keys that match what's passed to GuardAuthenticationProvider
|
||||
* @param LoggerInterface $logger A LoggerInterface instance
|
||||
* @param GuardAuthenticatorHandler $guardHandler The Guard handler
|
||||
* @param AuthenticationManagerInterface $authenticationManager An AuthenticationManagerInterface instance
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
* @param GuardAuthenticatorInterface[] $guardAuthenticators The authenticators, with keys that match what's passed to GuardAuthenticationProvider
|
||||
* @param LoggerInterface $logger A LoggerInterface instance
|
||||
*/
|
||||
public function __construct(GuardAuthenticatorHandler $guardHandler, AuthenticationManagerInterface $authenticationManager, $providerKey, $guardAuthenticators, LoggerInterface $logger = null)
|
||||
{
|
||||
@ -50,7 +50,7 @@ class GuardAuthenticationListener implements ListenerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over each authenticator to see if each wants to authenticate the request
|
||||
* Iterates over each authenticator to see if each wants to authenticate the request.
|
||||
*
|
||||
* @param GetResponseEvent $event
|
||||
*/
|
||||
@ -147,12 +147,12 @@ class GuardAuthenticationListener implements ListenerInterface
|
||||
|
||||
/**
|
||||
* Checks to see if remember me is supported in the authenticator and
|
||||
* on the firewall. If it is, the RememberMeServicesInterface is notified
|
||||
* on the firewall. If it is, the RememberMeServicesInterface is notified.
|
||||
*
|
||||
* @param GuardAuthenticatorInterface $guardAuthenticator
|
||||
* @param Request $request
|
||||
* @param TokenInterface $token
|
||||
* @param Response $response
|
||||
* @param Request $request
|
||||
* @param TokenInterface $token
|
||||
* @param Response $response
|
||||
*/
|
||||
private function triggerRememberMe(GuardAuthenticatorInterface $guardAuthenticator, Request $request, TokenInterface $token, Response $response = null)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
|
||||
use Symfony\Component\Security\Http\SecurityEvents;
|
||||
|
||||
/**
|
||||
* A utility class that does much of the *work* during the guard authentication process
|
||||
* A utility class that does much of the *work* during the guard authentication process.
|
||||
*
|
||||
* By having the logic here instead of the listener, more of the process
|
||||
* can be called directly (e.g. for manual authentication) or overridden.
|
||||
@ -33,10 +33,10 @@ class GuardAuthenticatorHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticates the given token in the system
|
||||
* Authenticates the given token in the system.
|
||||
*
|
||||
* @param TokenInterface $token
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
*/
|
||||
public function authenticateWithToken(TokenInterface $token, Request $request)
|
||||
{
|
||||
@ -49,12 +49,13 @@ class GuardAuthenticatorHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "on success" response for the given GuardAuthenticator
|
||||
* Returns the "on success" response for the given GuardAuthenticator.
|
||||
*
|
||||
* @param TokenInterface $token
|
||||
* @param Request $request
|
||||
* @param TokenInterface $token
|
||||
* @param Request $request
|
||||
* @param GuardAuthenticatorInterface $guardAuthenticator
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
*
|
||||
* @return null|Response
|
||||
*/
|
||||
public function handleAuthenticationSuccess(TokenInterface $token, Request $request, GuardAuthenticatorInterface $guardAuthenticator, $providerKey)
|
||||
@ -75,12 +76,13 @@ class GuardAuthenticatorHandler
|
||||
|
||||
/**
|
||||
* Convenience method for authenticating the user and returning the
|
||||
* Response *if any* for success
|
||||
* Response *if any* for success.
|
||||
*
|
||||
* @param UserInterface $user
|
||||
* @param Request $request
|
||||
* @param UserInterface $user
|
||||
* @param Request $request
|
||||
* @param GuardAuthenticatorInterface $authenticator
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
*
|
||||
* @return Response|null
|
||||
*/
|
||||
public function authenticateUserAndHandleSuccess(UserInterface $user, Request $request, GuardAuthenticatorInterface $authenticator, $providerKey)
|
||||
@ -96,11 +98,12 @@ class GuardAuthenticatorHandler
|
||||
|
||||
/**
|
||||
* Handles an authentication failure and returns the Response for the
|
||||
* GuardAuthenticator
|
||||
* GuardAuthenticator.
|
||||
*
|
||||
* @param AuthenticationException $authenticationException
|
||||
* @param Request $request
|
||||
* @param AuthenticationException $authenticationException
|
||||
* @param Request $request
|
||||
* @param GuardAuthenticatorInterface $guardAuthenticator
|
||||
*
|
||||
* @return null|Response
|
||||
*/
|
||||
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, GuardAuthenticatorInterface $guardAuthenticator)
|
||||
|
@ -12,7 +12,7 @@ use Symfony\Component\Security\Guard\Token\GuardTokenInterface;
|
||||
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
||||
|
||||
/**
|
||||
* The interface for all "guard" authenticators
|
||||
* The interface for all "guard" authenticators.
|
||||
*
|
||||
* 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
|
||||
@ -41,39 +41,44 @@ interface GuardAuthenticatorInterface extends AuthenticationEntryPointInterface
|
||||
* return array('api_key' => $request->headers->get('X-API-TOKEN'));
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getCredentialsFromRequest(Request $request);
|
||||
|
||||
/**
|
||||
* Return a UserInterface object based on the credentials OR throw
|
||||
* an AuthenticationException
|
||||
* an AuthenticationException.
|
||||
*
|
||||
* The *credentials* are the return value from getCredentialsFromRequest()
|
||||
*
|
||||
* @param mixed $credentials
|
||||
* @param mixed $credentials
|
||||
* @param UserProviderInterface $userProvider
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
*
|
||||
* @return UserInterface
|
||||
*/
|
||||
public function authenticate($credentials, UserProviderInterface $userProvider);
|
||||
|
||||
/**
|
||||
* Create an authenticated token for the given user
|
||||
* Create an authenticated token for the given user.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @param UserInterface $user
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
*
|
||||
* @return GuardTokenInterface
|
||||
*/
|
||||
public function createAuthenticatedToken(UserInterface $user, $providerKey);
|
||||
|
||||
/**
|
||||
* Called when authentication executed, but failed (e.g. wrong username password)
|
||||
* Called when authentication executed, but failed (e.g. wrong username password).
|
||||
*
|
||||
* This should return the Response sent back to the user, like a
|
||||
* RedirectResponse to the login page or a 403 response.
|
||||
@ -81,8 +86,9 @@ interface GuardAuthenticatorInterface extends AuthenticationEntryPointInterface
|
||||
* If you return null, the request will continue, but the user will
|
||||
* not be authenticated. This is probably not what you want to do.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param AuthenticationException $exception
|
||||
*
|
||||
* @return Response|null
|
||||
*/
|
||||
public function onAuthenticationFailure(Request $request, AuthenticationException $exception);
|
||||
@ -96,9 +102,10 @@ interface GuardAuthenticatorInterface extends AuthenticationEntryPointInterface
|
||||
* If you return null, the current request will continue, and the user
|
||||
* will be authenticated. This makes sense, for example, with an API.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param TokenInterface $token
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
*
|
||||
* @return Response|null
|
||||
*/
|
||||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey);
|
||||
|
@ -4,7 +4,6 @@ namespace Symfony\Component\Security\Guard\Provider;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Guard\GuardAuthenticatorInterface;
|
||||
use Symfony\Component\Security\Guard\Token\GuardTokenInterface;
|
||||
use Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken;
|
||||
@ -15,7 +14,7 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
|
||||
/**
|
||||
* Responsible for accepting the PreAuthenticationGuardToken and calling
|
||||
* the correct authenticator to retrieve the authenticated token
|
||||
* the correct authenticator to retrieve the authenticated token.
|
||||
*
|
||||
* @author Ryan Weaver <weaverryan@gmail.com>
|
||||
*/
|
||||
@ -30,10 +29,10 @@ class GuardAuthenticationProvider implements AuthenticationProviderInterface
|
||||
private $userChecker;
|
||||
|
||||
/**
|
||||
* @param GuardAuthenticatorInterface[] $guardAuthenticators The authenticators, with keys that match what's passed to GuardAuthenticationListener
|
||||
* @param UserProviderInterface $userProvider The user provider
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
* @param UserCheckerInterface $userChecker
|
||||
* @param GuardAuthenticatorInterface[] $guardAuthenticators The authenticators, with keys that match what's passed to GuardAuthenticationListener
|
||||
* @param UserProviderInterface $userProvider The user provider
|
||||
* @param string $providerKey The provider (i.e. firewall) key
|
||||
* @param UserCheckerInterface $userChecker
|
||||
*/
|
||||
public function __construct(array $guardAuthenticators, UserProviderInterface $userProvider, $providerKey, UserCheckerInterface $userChecker)
|
||||
{
|
||||
@ -44,9 +43,10 @@ class GuardAuthenticationProvider implements AuthenticationProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the correct authenticator for the token and calls it
|
||||
* Finds the correct authenticator for the token and calls it.
|
||||
*
|
||||
* @param GuardTokenInterface $token
|
||||
*
|
||||
* @return TokenInterface
|
||||
*/
|
||||
public function authenticate(TokenInterface $token)
|
||||
@ -66,7 +66,7 @@ class GuardAuthenticationProvider implements AuthenticationProviderInterface
|
||||
*/
|
||||
|
||||
// this should never happen - but technically, the token is
|
||||
// authenticated... so it could jsut be returned
|
||||
// authenticated... so it could just be returned
|
||||
if ($token->isAuthenticated()) {
|
||||
return $token;
|
||||
}
|
||||
@ -106,7 +106,7 @@ class GuardAuthenticationProvider implements AuthenticationProviderInterface
|
||||
}
|
||||
|
||||
// check the AdvancedUserInterface methods!
|
||||
$this->userChecker->checkPreAuth($user);;
|
||||
$this->userChecker->checkPreAuth($user);
|
||||
$this->userChecker->checkPostAuth($user);
|
||||
|
||||
// turn the UserInterface into a TokenInterface
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace Symfony\Component\Security\Guard\Token;
|
||||
|
||||
/**
|
||||
* An empty interface that both guard tokens implement
|
||||
* An empty interface that both guard tokens implement.
|
||||
*
|
||||
* This interface is used by the GuardAuthenticationProvider to know
|
||||
* that a token belongs to its system.
|
||||
|
@ -5,7 +5,7 @@ namespace Symfony\Component\Security\Guard\Token;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
|
||||
|
||||
/**
|
||||
* The token used by the guard auth system before authentication
|
||||
* The token used by the guard auth system before authentication.
|
||||
*
|
||||
* The GuardAuthenticationListener creates this, which is then consumed
|
||||
* immediately by the GuardAuthenticationProvider. If authentication is
|
||||
|
@ -24,7 +24,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
interface AuthenticationEntryPointInterface
|
||||
{
|
||||
/**
|
||||
* Returns a response that directs the user to authenticate
|
||||
* Returns a response that directs the user to authenticate.
|
||||
*
|
||||
* This is called when an anonymous request accesses a resource that
|
||||
* requires authentication. The job of this method is to return some
|
||||
|
Reference in New Issue
Block a user