title: After successful authentication token is not authenticated
body: <p>I'm new in Symfony 3.2. I need to implement form authentication. User fetches from database. After <code>post</code> to <code>/login</code> <code>onAuthenticationSuccess</code> event fires, but token is still unauthenticate:<a href="https://i.stack.imgur.com/qrgpS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qrgpS.jpg" alt="enter image description here"></a></p>
  
  <p><strong>What i am doing wrong?</strong></p>
  
  <hr>
  
  <p><em>security.yml</em></p>
  
  <pre><code>security:
  
      encoders:
          AppBundle\Entity\User:
              algorithm: bcrypt
              iterations: 10
  
      role_hierarchy:
          ROLE_ADMIN: ROLE_USER
          ROLE_DEVELOPER: ROLE_ADMIN
  
  
      providers:
          in_memory:
              memory: ~
          dvm_db_provider:
              entity:
                 class: AppBundle:User
  
  firewalls:        
      dev:
          pattern: ^/(_(profiler|wdt)|css|images|js)/
          security: false
  
      main:
          anonymous: true
          pattern: ^/
          guard:
              authenticators: [dvm.authenticator]
  
          form_login:
              login_path: login
              check_path: login
              csrf_token_generator: security.csrf.token_manager
  
          logout: ~
          provider: dvm_db_provider
  
  access_control:
  </code></pre>
  
  <hr>
  
  <p><em>User.php</em><br></p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\ORM\PersistentCollection; 
  use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  use Symfony\Component\Security\Core\User\EquatableInterface;
  use Symfony\Component\Security\Core\User\UserInterface;
  
  /**
   * User
   *
   * @ORM\Table(name="users")
   * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
   */
  class User implements AdvancedUserInterface, \Serializable, EquatableInterface {
  
      /**
       * @var string
       *
       * @ORM\Column(name="id", type="guid")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="UUID")
       */
      protected $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="surname", type="string", length=255)
       */
      private $surname;
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=255)
       */
      private $name;
      /**
       * @var string
       *
       * @ORM\Column(name="patronymic", type="string", length=255, nullable=true)
       */
      private $patronymic;
      /**
       * @var \DateTime
       *
       * @ORM\Column(name="birthday", type="date")
       */
      private $birthday;
  
      /**
       * @var string
       *
       * @ORM\Column(name="gender", type="string", length=1)
       */
      private $gender;
      /**
       * @var string
       *
       * @ORM\Column(name="avatar", type="string", length=255, unique=true)
       */
      private $avatar;
      /**
       * @var string
       *
       * @ORM\Column(name="email", type="string", length=255, unique=true)
       */
      private $email;
      /**
       * @var string
       */
      private $plainPass;
      /**
       * @var string
       *
       * @ORM\Column(name="pass_hash", type="string", length=255)
       */
      private $passHash;
      /**
       * @var bool
       *
       * @ORM\Column(name="is_active", type="boolean")
       */
      private $isActive;
  
      /**
       * @var PersistentCollection
       *
       * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Role")
       * @ORM\JoinTable(name="users_roles", joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
       *   inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")})
       */
      private $roles;
  
      /**
       * @return string
       */
      public function getPlainPass() {
          return $this-&gt;plainPass;
      }
  
      /**
       * @param string $plainPass
       */
      public function setPlainPass($plainPass) {
          $this-&gt;plainPass = $plainPass;
          $this-&gt;passHash = password_hash($this-&gt;plainPass, PASSWORD_BCRYPT);
      }
  
      public function eraseCredentials() {
          $this-&gt;setPlainPass('');
      }
  
      /**
       * Get id
       *
       * @return int
       */
      public function getId() {
          return $this-&gt;id;
      }
  
      /**
       * Get surname
       *
       * @return string
       */
      public function getSurname() {
          return $this-&gt;surname;
      }
  
      /**
       * Set surname
       *
       * @param string $surname
       *
       * @return User
       */
      public function setSurname($surname) {
          $this-&gt;surname = $surname;
  
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string
       */
      public function getName() {
          return $this-&gt;name;
      }
  
      /**
       * Set name
       *
       * @param string $name
       *
       * @return User
       */
      public function setName($name) {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Get patronymic
       *
       * @return string
       */
      public function getPatronymic() {
          return $this-&gt;patronymic;
      }
  
      /**
       * Set patronymic
       *
       * @param string $patronymic
       *
       * @return User
       */
      public function setPatronymic($patronymic) {
          $this-&gt;patronymic = $patronymic;
  
          return $this;
      }
  
      /**
       * Get birthday
       *
       * @return \DateTime
       */
      public function getBirthday() {
          return $this-&gt;birthday;
      }
  
      /**
       * Set birthday
       *
       * @param \DateTime $birthday
       *
       * @return User
       */
      public function setBirthday($birthday) {
          $this-&gt;birthday = $birthday;
  
          return $this;
      }
  
      /**
       * Get gender
       *
       * @return string
       */
      public function getGender() {
          return $this-&gt;gender;
      }
  
      /**
       * Set gender
       *
       * @param string $gender
       *
       * @return User
       */
      public function setGender($gender) {
          $this-&gt;gender = $gender;
  
          return $this;
      }
  
      /**
       * Get avatar
       *
       * @return string
       */
      public function getAvatar() {
          return $this-&gt;avatar;
      }
  
      /**
       * Set avatar
       *
       * @param string $avatar
       *
       * @return User
       */
      public function setAvatar($avatar) {
          $this-&gt;avatar = $avatar;
  
          return $this;
      }
  
      /**
       * Get email
       *
       * @return string
       */
      public function getEmail() {
          return $this-&gt;email;
      }
  
      /**
       * Set email
       *
       * @param string $email
       *
       * @return User
       */
      public function setEmail($email) {
          $this-&gt;email = $email;
  
          return $this;
      }
  
      /**
       * Set isActive
       *
       * @param boolean $isActive
       *
       * @return User
       */
      public function setIsBlocked($isActive) {
          $this-&gt;isActive = $isActive;
  
          return $this;
      }
  
      public function serialize() {
          return serialize([$this-&gt;id, $this-&gt;name, $this-&gt;surname, $this-&gt;patronymic, $this-&gt;getPassword(), $this-&gt;isActive, $this-&gt;email]);
      }
  
      public function getPassword() {
          return $this-&gt;getPassHash();
      }
  
      /**
       * @return string
       */
      public function getPassHash() {
          return $this-&gt;passHash;
      }
  
      public function getSalt() {
          return null;
      }
  
      public function unserialize($serialized) {
          list($this-&gt;id, $this-&gt;name, $this-&gt;surname, $this-&gt;patronymic, $this-&gt;passHash, $this-&gt;isActive, $this-&gt;email)
                  = unserialize($serialized);
      }
  
      public function isAccountNonExpired() {
          return true;
      }
  
      public function isAccountNonLocked() {
          return true;
      }
  
      public function isCredentialsNonExpired() {
          return true;
      }
  
      public function isEqualTo(UserInterface $user) {
          return $this-&gt;getUsername() === $user-&gt;getUsername()
                  &amp;&amp; $this-&gt;getPassword() === $user-&gt;getPassword();
      }
  
      public function getUsername() {
          return $this-&gt;email;
      }
  
      /**
       * @return array
       */
      public function getRoles() {
          $rolesArray = [];
          /* @var $role Role */
          foreach ($this-&gt;roles-&gt;toArray() as $role) $rolesArray[] = $role-&gt;getName();
          return $rolesArray;
      }
  
      /**
       * @param array $roles
       */
      public function setRoles($roles) {
          $this-&gt;roles = $roles;
      }
  
      public function isEnabled() {
          return $this-&gt;getIsActive();
      }
  
      /**
       * Get isActive
       *
       * @return bool
       */
      public function getIsActive() {
          return $this-&gt;isActive;
      }
  
      public function setPassword($pass) {
          $this-&gt;setPlainPass($pass);
      }
  }
  </code></pre>
  
  <hr>
  
  <p><em>Authenticator.php</em></p>
  
  <pre><code>class Authenticator extends AbstractGuardAuthenticator {
  
      public function getCredentials(Request $request) {
          if ($request-&gt;getPathInfo() != '/login' || !$request-&gt;isMethod('POST')) return null;
          return ['u' =&gt; $request-&gt;get('_username'), 'p' =&gt; $request-&gt;get('_password')];
      }
  
      public function getUser($credentials, UserProviderInterface $userProvider) {
          if (!$credentials['u']) return null;
          return $userProvider-&gt;loadUserByUsername($credentials['u']);
      }
  
      public function checkCredentials($credentials, UserInterface $user) {
          if (!password_verify($credentials['p'], $user-&gt;getPassword())) {
              dump([$credentials['p'], $user-&gt;getPassword()], password_verify($credentials['p'], $user-&gt;getPassword()));
              die;
          }
          if (!$credentials['p']) return null;
          return password_verify($credentials['p'], $user-&gt;getPassword());
      }
  
      public function onAuthenticationFailure(Request $request, AuthenticationException $exception) {
          dump(__FUNCTION__);
      }
  
      public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) {
          dump(__FUNCTION__);
          $token-&gt;setAuthenticated(true);
      }
  
      public function supportsRememberMe() {
          return false;
      }
  
      public function start(Request $request, AuthenticationException $authException = null) {
          return new RedirectResponse('/login');
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p><em>Security_log</em></p>
  
  <pre><code>[2017-05-26 09:38:03] security.DEBUG: Read existing security token from the session. {"key":"_security_main"} []
  [2017-05-26 09:38:03] security.DEBUG: User was reloaded from a user provider. {"username":"...@mail.ru","provider":"Symfony\\Bridge\\Doctrine\\Security\\User\\EntityUserProvider"} []
  [2017-05-26 09:38:03] security.DEBUG: Checking for guard authentication credentials. {"firewall_key":"main","authenticators":1} []
  [2017-05-26 09:38:03] security.DEBUG: Calling getCredentials() on guard configurator. {"firewall_key":"main","authenticator":"AppBundle\\Security\\DvmAuthenticator"} []
  [2017-05-26 09:38:03] security.DEBUG: Passing guard token information to the GuardAuthenticationProvider {"firewall_key":"main","authenticator":"AppBundle\\Security\\DvmAuthenticator"} []
  [2017-05-26 09:38:03] security.INFO: Guard authentication successful! {"token":"[object] (Symfony\\Component\\Security\\Guard\\Token\\PostAuthenticationGuardToken: PostAuthenticationGuardToken(user=\"....@mail.ru\", authenticated=true, roles=\"ROLE_DEVELOPER\"))","authenticator":"AppBundle\\Security\\DvmAuthenticator"} []
  [2017-05-26 09:38:03] security.DEBUG: Guard authenticator set success response. {"response":"[object] (Symfony\\Component\\HttpFoundation\\RedirectResponse: HTTP/1.0 302 Found\r\nCache-Control: no-cache, private\r\nDate:          Thu, 25 May 2017 23:38:03 GMT\r\nLocation:      /\r\n\r\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n    &lt;head&gt;\n        &lt;meta charset=\"UTF-8\" /&gt;\n        &lt;meta http-equiv=\"refresh\" content=\"1;url=/\" /&gt;\n\n        &lt;title&gt;Redirecting to /&lt;/title&gt;\n    &lt;/head&gt;\n    &lt;body&gt;\n        Redirecting to &lt;a href=\"/\"&gt;/&lt;/a&gt;.\n    &lt;/body&gt;\n&lt;/html&gt;)","authenticator":"AppBundle\\Security\\DvmAuthenticator"} []
  [2017-05-26 09:38:03] security.DEBUG: Remember me skipped: it is not configured for the firewall. {"authenticator":"AppBundle\\Security\\DvmAuthenticator"} []
  [2017-05-26 09:38:03] security.DEBUG: The "AppBundle\Security\DvmAuthenticator" authenticator set the response. Any later authenticator will not be called {"authenticator":"AppBundle\\Security\\DvmAuthenticator"} []
  [2017-05-26 09:38:03] security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
  [2017-05-26 09:38:04] security.DEBUG: Read existing security token from the session. {"key":"_security_main"} []
  [2017-05-26 09:38:04] security.DEBUG: User was reloaded from a user provider. {"username":"...@mail.ru","provider":"Symfony\\Bridge\\Doctrine\\Security\\User\\EntityUserProvider"} []
  [2017-05-26 09:38:04] security.DEBUG: Checking for guard authentication credentials. {"firewall_key":"main","authenticators":1} []
  [2017-05-26 09:38:04] security.DEBUG: Calling getCredentials() on guard configurator. {"firewall_key":"main","authenticator":"AppBundle\\Security\\DvmAuthenticator"} []
  [2017-05-26 09:38:04] security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
  [2017-05-26 09:41:56] security.DEBUG: Read existing security token from the session. {"key":"_security_main"} []
  </code></pre>