title: Symfony Security AdvancedUserInterface
body: <p>Welcome,
  I have some problem with user Authentication. My security.yml file:</p>
  
  <pre><code>security:
      firewalls:
            default:
               anonymous: ~
               http_basic: ~
               provider: our_db_provider
               logout:
                    path:   /logout
  
       providers:
            our_db_provider:
                entity:
                    class: CmsUserBundle:User
                    property: username
  
       encoders:
           Cms\UserBundle\Entity\User: plaintext
  </code></pre>
  
  <p>My user entity: </p>
  
  <pre><code>&lt;?php
    namespace Cms\UserBundle\Entity;
  
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Security\Core\User\AdvancedUserInterface;
    use Symfony\Component\Validator\Constraints as Assert;
  
   /**
   * @ORM\HasLifecycleCallbacks()
   * @ORM\Entity(repositoryClass="Cms\UserBundle\Entity\UserRepository")
   */
   class User implements AdvancedUserInterface, \Serializable
   {
    /**
   * @ORM\Id
   * @ORM\Column(type="integer")
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @ORM\Column(type="string", length=64)
   */
  private $username;
  
  /**
   * @ORM\Column(type="string", length= 64)
   */
  private $email;
  
  /**
   * @ORM\Column(type="string", length=64)
   */
  private $password;
  
  /**
   * @ORM\Column(type="date", length=128)
   */
  private $dateOfBirthday;
  
  /**
   * @ORM\Column(type="text")
   */
  private $about;
  
  /**
   * @ORM\Column(type="string", length=64)
   */
  private $salt;
  
  /**
   * @ORM\ManyToOne(targetEntity="Cms\UserBundle\Entity\Role")
   * @ORM\JoinColumn(name="role_id", referencedColumnName="id", onDelete="CASCADE")
   */
  private $roles;
  
  /**
   * @ORM\Column(type="string", length=255)
   */
  private $eraseCredentials;
  
  /**
   * @ORM\Column(name="is_active", type="boolean",  options={"default": 0})
   */
  private $isActive;
  
  /**
   * @ORM\Column(type="string", nullable=true)
   * @Assert\Image()
   */
  private $profilePicturePath;
  
  /**
   * @ORM\Column(type="string", nullable=true)
   */
  private $activatedHash;
  
  
  public function __construct()
  {
      $this-&gt;setActivatedHash(bin2hex(random_bytes(36)));
  }
  
  public function getSalt()
  {
      return $this-&gt;salt;
  }
  
  public function getPassword()
  {
      return $this-&gt;password;
  }
  
  public function getRoles()
  {
      return array($this-&gt;roles);
  }
  
  public function eraseCredentials()
  {
  
  }
  
  public function getUsername()
  {
      return $this-&gt;username;
  }
  
  /**
   * Get eraseCredentials
   *
   * @return string
   */
  public function getEraseCredentials()
  {
      return $this-&gt;eraseCredentials;
  }
  
  /**
   * Set isActive
   *
   * @param boolean $isActive
   * @return User
   */
  public function setIsActive($isActive)
  {
      $this-&gt;isActive = $isActive;
  
      return $this;
  }
  
  /**
   * Get isActive
   *
   * @return boolean
   */
  public function getIsActive()
  {
      return $this-&gt;isActive;
  }
  
  
  /**
   * Set email
   *
   * @param string $email
   *
   * @return User
   */
  public function setEmail($email)
  {
      $this-&gt;email = $email;
  
      return $this;
  }
  
  /**
   * Get email
   *
   * @return string
   */
  public function getEmail()
  {
      return $this-&gt;email;
  }
  
  
  /**
   * Get id
   *
   * @return integer
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set username
   *
   * @param string $username
   *
   * @return User
   */
  public function setUsername($username)
  {
      $this-&gt;username = $username;
  
      return $this;
  }
  
  /**
   * Set password
   *
   * @param string $password
   *
   * @return User
   */
  public function setPassword($password)
  {
      $this-&gt;password = $password;
  
      return $this;
  }
  
  /**
   * Set dateOfBirthday
   *
   * @param \DateTime $dateOfBirthday
   *
   * @return User
   */
  public function setDateOfBirthday($dateOfBirthday)
  {
      $this-&gt;dateOfBirthday = $dateOfBirthday;
  
      return $this;
  }
  
  /**
   * Get dateOfBirthday
   *
   * @return \DateTime
   */
  public function getDateOfBirthday()
  {
      return $this-&gt;dateOfBirthday;
  }
  
  /**
   * Set about
   *
   * @param string $about
   *
   * @return User
   */
  public function setAbout($about)
  {
      $this-&gt;about = $about;
  
      return $this;
  }
  
  /**
   * Get about
   *
   * @return string
   */
  public function getAbout()
  {
      return $this-&gt;about;
  }
  
  /**
   * Set salt
   *
   * @param string $salt
   *
   * @return User
   */
  public function setSalt($salt)
  {
      $this-&gt;salt = $salt;
  
      return $this;
  }
  
  
  /**
   * Set eraseCredentials
   *
   * @param string $eraseCredentials
   *
   * @return User
   */
  public function setEraseCredentials($eraseCredentials)
  {
      $this-&gt;eraseCredentials = $eraseCredentials;
  
      return $this;
  }
  
  
  /**
   * Set roles
   *
   * @param \Cms\UserBundle\Entity\Role $roles
   *
   * @return User
   */
  public function setRoles(\Cms\UserBundle\Entity\Role $roles = null)
  {
      $this-&gt;roles = $roles;
  
      return $this;
  }
  
  /**
   * Set profilePicturePath
   *
   * @param string $profilePicturePath
   *
   * @return User
   */
  public function setProfilePicturePath($profilePicturePath)
  {
      $this-&gt;profilePicturePath = $profilePicturePath;
  
      return $this;
  }
  
  /**
   * Get profilePicturePath
   *
   * @return string
   */
  public function getProfilePicturePath()
  {
      return $this-&gt;profilePicturePath;
  }
  
  /**
   * Serialization is required to FileUploader
   * @return string
   */
  public function serialize()
  {
      return serialize(array(
          $this-&gt;id,
          $this-&gt;username,
          $this-&gt;salt,
          $this-&gt;password,
          $this-&gt;roles,
          $this-&gt;isActive
      ));
  }
  
  /**
   * @param string $serialized
   */
  public function unserialize($serialized)
  {
      list (
          $this-&gt;id,
          $this-&gt;username,
          $this-&gt;salt,
          $this-&gt;password,
          $this-&gt;roles,
          $this-&gt;isActive
          ) = unserialize($serialized);
  }
  
  /**
   * Set activatedHash
   *
   * @param string $activatedHash
   *
   * @return User
   */
  public function setActivatedHash($activatedHash)
  {
      $this-&gt;activatedHash = $activatedHash;
  
      return $this;
  }
  
  /**
   * Get activatedHash
   *
   * @return string
   */
  public function getActivatedHash()
  {
      return $this-&gt;activatedHash;
  }
  
  
  public function isAccountNonExpired()
  {
      return true;
  }
  
  public function isAccountNonLocked()
  {
        return true;
  }
  
  
  public function isCredentialsNonExpired()
  {
     return true;
  }
  
  public function isEnabled()
  {
     return $this-&gt;getIsActive();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And in my Controller:</p>
  
  <pre><code>  $token = new UsernamePasswordToken($foundUser, $foundUser-&gt;getPassword(), 'default', array($role-&gt;getRole()) );
                      $this-&gt;get('security.token_storage')-&gt;setToken($token);
  </code></pre>
  
  <p>My problem is that every time user is success Authenticated, even if my <code>isEnabled()</code> function return false. Thanks for help.</p>