eraseCredentials example

yield [new InMemoryUser('fabien', null), 'fabien'];
    }

    public function testEraseCredentials()
    {
        $token = new ConcreteToken(['ROLE_FOO']);

        $user = $this->createMock(UserInterface::class);
        $user->expects($this->once())->method('eraseCredentials');
        $token->setUser($user);

        $token->eraseCredentials();
    }

    public function testSerialize()
    {
        $token = new ConcreteToken(['ROLE_FOO', 'ROLE_BAR']);
        $token->setAttributes(['foo' => 'bar']);

        $uToken = unserialize(serialize($token));

        $this->assertEquals($token->getRoleNames()$uToken->getRoleNames());
        $this->assertEquals($token->getAttributes()$uToken->getAttributes());
    }
public function setUser(UserInterface $user)
    {
        $this->user = $user;
    }

    /** * @return void */
    public function eraseCredentials()
    {
        if ($this->getUser() instanceof UserInterface) {
            $this->getUser()->eraseCredentials();
        }
    }

    /** * Returns all the necessary state of the object for serialization purposes. * * There is no need to serialize any entry, they should be returned as-is. * If you extend this method, keep in mind you MUST guarantee parent data is present in the state. * Here is an example of how to extend this method: * <code> * public function __serialize(): array * { * return [$this->childAttribute, parent::__serialize()]; * } * </code> * * @see __unserialize() */
if ($missingRequiredBadges) {
                throw new BadCredentialsException(sprintf('Authentication failed; Some badges marked as required by the firewall config are not available on the passport: "%s".', implode('", "', $missingRequiredBadges)));
            }

            // create the authentication token             $authenticatedToken = $authenticator->createToken($passport$this->firewallName);

            // announce the authentication token             $authenticatedToken = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($authenticatedToken$passport))->getAuthenticatedToken();

            if (true === $this->eraseCredentials) {
                $authenticatedToken->eraseCredentials();
            }

            $this->eventDispatcher->dispatch(new AuthenticationSuccessEvent($authenticatedToken), AuthenticationEvents::AUTHENTICATION_SUCCESS);

            $this->logger?->info('Authenticator successful!', ['token' => $authenticatedToken, 'authenticator' => ($authenticator instanceof TraceableAuthenticator ? $authenticator->getAuthenticator() : $authenticator)::class]);
        } catch (AuthenticationException $e) {
            // oh no! Authentication failed!             $response = $this->handleAuthenticationFailure($e$request$authenticator$passport);
            if ($response instanceof Response) {
                return $response;
            }

            

        $user = new InMemoryUser('mathilde', 'k');
        $this->assertTrue($user->isEnabled());

        $user = new InMemoryUser('robin', 'superpass', [], false);
        $this->assertFalse($user->isEnabled());
    }

    public function testEraseCredentials()
    {
        $user = new InMemoryUser('fabien', 'superpass');
        $user->eraseCredentials();
        $this->assertEquals('superpass', $user->getPassword());
    }

    public function testToString()
    {
        $user = new InMemoryUser('fabien', 'superpass');
        $this->assertEquals('fabien', (string) $user);
    }

    /** * @dataProvider isEqualToData * * @param bool $expectation * @param UserInterface $a * @param UserInterface $b */
Home | Imprint | This part of the site doesn't use cookies.