Witam. Mam problem z uwierzytelnieniem użytkowników znajdujących się w bazie danych. Po zalogowaniu jest oczywiści 403 Access denied i na pasku do debbugowania pojawia się not authenticated. Co robię źle?

Firewall
  1. firewalls:
  2. dev:
  3. pattern: ^/(_(profiler|wdt)|css|images|js)/
  4. security: false
  5.  
  6. secured:
  7. pattern: ^/
  8. anonymous: ~
  9. form_login:
  10. check_path: /login_check
  11. login_path: /login
  12. username_parameter: _username
  13. password_parameter: _password
  14.  
  15.  
  16. logout:
  17. path: /logout
  18.  
  19. access_control:
  20. - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  21. - { path: ^/admin, roles: ROLE_ADMIN }
  22. - { path: ^/mod, roles: ROLE_MOD }
  23.  
  24. role_hierarchy:
  25. ROLE_MOD: [ROLE_CZ, ROLE_TRP, ROLE_TRD, ROLE_TRR, ROLE_TRX, ROLE_MC, ROLE_U]
  26. ROLE_ADMIN: ROLE_MOD
  27. ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]


W bazie danych każdy użytkownik posiad jedną lub więcej z ról (ROLE_CZ, ROLE_TRP, ROLE_TRD, ROLE_TRR, ROLE_TRX, ROLE_MC, ROLE_U)

Klasa użytkownika
  1. <?php
  2.  
  3. namespace Mns\PytaniaBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8.  
  9. /**
  10.  * @ORM\MappedSuperclass
  11.  */
  12. abstract class Person implements UserInterface
  13. {
  14. /**
  15.   * @ORM\Column(type="string", length=32, unique=true)
  16.   */
  17. protected $login;
  18.  
  19. /**
  20.   * @ORM\Column(type="string", length=100)
  21.   */
  22. protected $password;
  23.  
  24.  
  25. /**
  26.   * @ORM\Column(type="string", length=32)
  27.   */
  28. protected $salt;
  29.  
  30. /**
  31.   * @ORM\ManyToMany(targetEntity="Group", inversedBy="users")
  32.   */
  33. protected $group;
  34.  
  35. public function __construct($login, $password)
  36. {
  37. $this->salt = md5(uniqid(null, true));
  38. $this->login = $login;
  39. $this->password = $password;
  40. $this->group = new ArrayCollection();
  41. }
  42.  
  43. /**
  44.   * Get id
  45.   *
  46.   * @return integer
  47.   */
  48. public function getId()
  49. {
  50. return $this->id;
  51. }
  52.  
  53. /**
  54.   * Set login
  55.   *
  56.   * @param string $login
  57.   */
  58. public function setLogin($login)
  59. {
  60. $this->login = $login;
  61. }
  62.  
  63. /**
  64.   * Get login
  65.   *
  66.   * @return string
  67.   */
  68. public function getLogin()
  69. {
  70. return $this->login;
  71. }
  72.  
  73. /**
  74.   * Set password
  75.   *
  76.   * @param string $password
  77.   */
  78. public function setPassword($password)
  79. {
  80. $this->password = $password;
  81. }
  82.  
  83. /**
  84.   * Get password
  85.   *
  86.   * @return string
  87.   */
  88. public function getPassword()
  89. {
  90. return $this->password;
  91. }
  92.  
  93. public function equals(UserInterface $user)
  94. {
  95. if($this->login !== $user->getUsername())
  96. return false;
  97.  
  98. if ($this->password !== $user->getPassword())
  99. return false;
  100.  
  101. if ($this->salt !== $user->getSalt())
  102. return false;
  103.  
  104. return true;
  105. }
  106.  
  107. public function eraseCredentials()
  108. {
  109.  
  110. }
  111.  
  112. public function getRoles()
  113. {
  114. return $this->group->toArray();
  115. }
  116.  
  117. public function getSalt()
  118. {
  119. return $this->salt;
  120. }
  121.  
  122. public function getUsername()
  123. {
  124. $this->getLogin();
  125. }
  126.  
  127. public function getName()
  128. {
  129. $this->getLogin();
  130. }
  131.  
  132. /**
  133.   * Add group
  134.   *
  135.   * @param Mns\PytaniaBundle\Entity\Group $group
  136.   */
  137. public function addGroup(\Mns\PytaniaBundle\Entity\User $group)
  138. {
  139. $this->group[] = $group;
  140. }
  141.  
  142. /**
  143.   * Get group
  144.   *
  145.   * @return Doctrine\Common\Collections\Collection
  146.   */
  147. public function getGroup()
  148. {
  149. return $this->group;
  150. }
  151.  
  152. public function setGroup(\Doctrine\Common\Collections\ArrayCollection $group)
  153. {
  154. $this->group = $group;
  155. }
  156.  
  157. }



Klasa ról
  1. <?php
  2.  
  3. namespace Mns\PytaniaBundle\Entity;
  4.  
  5. use Symfony\Component\Security\Core\Role\RoleInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\ORM\Mapping as ORM;
  8.  
  9. /**
  10.  * @ORM\Table(name="roles")
  11.  * @ORM\Entity()
  12.  */
  13. class Group implements RoleInterface
  14. {
  15. /**
  16.   * @ORM\Column(name="id", type="integer")
  17.   * @ORM\Id()
  18.   * @ORM\GeneratedValue(strategy="AUTO")
  19.   */
  20. protected $id;
  21.  
  22. /**
  23.   * @ORM\Column(name="name", type="string", length=30)
  24.   */
  25. protected $name;
  26.  
  27. /**
  28.   * @ORM\Column(name="role", type="string", length=20, unique=true)
  29.   */
  30. protected $role;
  31.  
  32. /**
  33.   * @ORM\ManyToMany(targetEntity="Person", mappedBy="group")
  34.   */
  35. protected $users;
  36.  
  37. public function __construct()
  38. {
  39. $this->users = new ArrayCollection();
  40. }
  41.  
  42. public function __toString()
  43. {
  44. return $this->getName();
  45. }
  46.  
  47. public function getRole()
  48. {
  49. return $this->role;
  50. }
  51.  
  52.  
  53. /**
  54.   * Get id
  55.   *
  56.   * @return integer
  57.   */
  58. public function getId()
  59. {
  60. return $this->id;
  61. }
  62.  
  63. /**
  64.   * Set name
  65.   *
  66.   * @param string $name
  67.   */
  68. public function setName($name)
  69. {
  70. $this->name = $name;
  71. }
  72.  
  73. /**
  74.   * Get name
  75.   *
  76.   * @return string
  77.   */
  78. public function getName()
  79. {
  80. return $this->name;
  81. }
  82.  
  83. /**
  84.   * Set role
  85.   *
  86.   * @param string $role
  87.   */
  88. public function setRole($role)
  89. {
  90. $this->role = $role;
  91. }
  92.  
  93. /**
  94.   * Add users
  95.   *
  96.   * @param Mns\PytaniaBundle\Entity\User $users
  97.   */
  98. public function addUser(\Mns\PytaniaBundle\Entity\User $users)
  99. {
  100. $this->users[] = $users;
  101. }
  102.  
  103. /**
  104.   * Get users
  105.   *
  106.   * @return Doctrine\Common\Collections\Collection
  107.   */
  108. public function getUsers()
  109. {
  110. return $this->users;
  111. }
  112. }