Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 Entity Authentication doesn't work for me
    primarykey
    data
    text
    <p>I am learning how to use Authentication in Symfony2, with usernames comming from an Entity (MySQL database). I've created a simple table in PhpMyAdmin :</p> <pre><code>INSERT INTO `user` (`id`, `username`, `password`, `salt`, `roles`) VALUES (1, 'bobby4078', 'test', '', ''), (2, 'damien', 'test', '', ''), (3, 'thomas', 'test', '', ''); </code></pre> <p>As you can see, there is juste 3 users, with the same password "test", no salt and roles.</p> <p>Then I've edited my security.yml :</p> <pre><code>jms_security_extra: secure_all_services: false expressions: true security: encoders: Symfony\Component\Security\Core\User\User: plaintext Rtf\UserBundle\Entity\User: plaintext role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] providers: in_memory: memory: users: user: { password: userpass, roles: [ 'ROLE_USER' ] } admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] } main: entity: { class: RtfUserBundle:User, property: username } firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: pattern: ^/ anonymous: true provider: main form_login: login_path: login check_path: login_check logout: path: logout target: / access_control: #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https } #- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 } </code></pre> <p>To finish, here is my entity (I hope this is not too long) :</p> <p> <pre><code>namespace Rtf\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; /** * User * * @ORM\Table() * @ORM\Entity(repositoryClass="Rtf\UserBundle\Entity\UserRepository") */ class User implements UserInterface { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="username", type="string", length=255, unique=true) */ private $username; /** * @var string * * @ORM\Column(name="password", type="string", length=255) */ private $password; /** * @var string * * @ORM\Column(name="salt", type="string", length=255) */ private $salt; /** * @var array * * @ORM\Column(name="roles", type="array") */ private $roles; public function _construct(){ $this-&gt;roles = array(); } /** * Get id * * @return integer */ public function getId() { return $this-&gt;id; } /** * Set nom * * @param string $nom * @return User */ public function setUsername($username) { $this-&gt;username = $username; return $this; } /** * Get nom * * @return string */ public function getUsername() { return $this-&gt;username; } /** * Set password * * @param string $password * @return User */ public function setPassword($password) { $this-&gt;password = $password; return $this; } /** * Get password * * @return string */ public function getPassword() { return $this-&gt;password; } /** * Set salt * * @param string $salt * @return User */ public function setSalt($salt) { $this-&gt;salt = $salt; return $this; } /** * Get salt * * @return string */ public function getSalt() { return $this-&gt;salt; } /** * Set roles * * @param array $roles * @return User */ public function setRoles($roles) { $this-&gt;roles = $roles; return $this; } /** * Get roles * * @return array */ public function getRoles() { return $this-&gt;roles; } public function eraseCredentials(){ } } </code></pre> <p>The problem is that when I entered a login and a password in my form, then in my symfony toolbar I can see that the user is still "anon". So It didn't read properly in my database...</p> <p>I really don't know where this could comes from, and I don't know where to start searching for errors in my code...</p> <p>Any help ?</p> <p>Thanks, and sorry for my bad english.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload