B
B
BonBon Slick2018-04-26 19:57:04
symfony
BonBon Slick, 2018-04-26 19:57:04

Why do exceptions come from DaoAuthenticationProvider and not from custom auth provider?

class FormAuthenticator implements SimpleFormAuthenticatorInterface
{
    public function authenticateToken(
        TokenInterface $unAuthenticatedToken,
        UserProviderInterface $userProvider,
        $providerKey) : UsernamePasswordToken
    {
        throw new CustomUserMessageAuthenticationException('User not found22222222');

The handler responsible for authorization errors should receive an exception CustomUserMessageAuthenticationExceptionwith the message User not found22222222.
public function onAuthenticationFailure(Request $request, AuthenticationException $exception) : Response
    {
        dump($exception instanceof  AuthenticationServiceException ); // true
        exit;

Exception throws out this class
class DaoAuthenticationProvider extends UserAuthenticationProvider
{
...

Выкидывает ексепшены отсюда
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
    {       
...
            if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) {
                throw new BadCredentialsException('The presented password is invalid.');
            }
        }
    }

// И отсюда
 protected function retrieveUser($username, UsernamePasswordToken $token)
    {
   ...
        } catch (UsernameNotFoundException $e) {
            $e->setUsername($username);
            throw $e;
        } catch (\Exception $e) {
// ТУТ
            $e = new AuthenticationServiceException($e->getMessage(), 0, $e);
            $e->setToken($token);
            throw $e;
        }
    }

Here is the class.
https :
//github.com/symfony/security-core/blob/mast
...
custom, accepts Dao, or somehow works out even before the custom authenticator, and throws its actions. And I would like to get control over the errors that the user sees during authentication.
How to throw your eksepsheny? Why does Dao work?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question