私は少し問題があります... Symfony2のハンドブックをフォローしましたが、今は自分自身にログインすることで立ち往生しています:s
この初心者にとって、どんな助けも大歓迎です。これは私のユーザーエンティティです:
<?php
namespace SocialGeo\BackendBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\Common\Collections\ArrayCollection;
/**
* SocialGeo\BackendBundle\Entity\Users
*/
class Users implements AdvancedUserInterface
{
/**
* @var integer $userId
*/
private $userId;
/**
* @var string $username
*/
private $username;
/**
* @ORM\Column(type="string", length=60)
*/
private $salt;
/**
* @var string $userPassword
*/
private $userPassword;
/**
* @var string $userEmail
*/
private $userEmail;
/**
* @var boolean $userActive
*/
private $userActive;
/**
* @var string $userFavourites
*/
private $userFavourites;
/**
* @var integer $userScore
*/
private $userScore;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*/
private $rolesRole;
/**
* Constructor
*/
public function __construct()
{
$this->rolesRole = new ArrayCollection();
$this->salt = md5(uniqid(null, true));
}
/**
* Get userId
*
* @return integer
*/
public function getUserId()
{
return $this->userId;
}
/**
* Set username
*
* @param string $username
* @return Users
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set userPassword
*
* @param string $userPassword
* @return Users
*/
public function setUserPassword($userPassword)
{
$this->userPassword = $userPassword;
return $this;
}
/**
* Get userPassword
*
* @return string
*/
public function getUserPassword()
{
return $this->userPassword;
}
/**
* Set userEmail
*
* @param string $userEmail
* @return Users
*/
public function setUserEmail($userEmail)
{
$this->userEmail = $userEmail;
return $this;
}
/**
* Get userEmail
*
* @return string
*/
public function getUserEmail()
{
return $this->userEmail;
}
/**
* Set userActive
*
* @param boolean $userActive
* @return Users
*/
public function setUserActive($userActive)
{
$this->userActive = $userActive;
return $this;
}
/**
* Get userActive
*
* @return boolean
*/
public function getUserActive()
{
return $this->userActive;
}
/**
* Set userFavourites
*
* @param string $userFavourites
* @return Users
*/
public function setUserFavourites($userFavourites)
{
$this->userFavourites = $userFavourites;
return $this;
}
/**
* Get userFavourites
*
* @return string
*/
public function getUserFavourites()
{
return $this->userFavourites;
}
/**
* Set userScore
*
* @param integer $userScore
* @return Users
*/
public function setUserScore($userScore)
{
$this->userScore = $userScore;
return $this;
}
/**
* Get userScore
*
* @return integer
*/
public function getUserScore()
{
return $this->userScore;
}
/**
* Add rolesRole
*
* @param SocialGeo\BackendBundle\Entity\Roles $rolesRole
* @return Users
*/
public function addRolesRole(\SocialGeo\BackendBundle\Entity\Roles $rolesRole)
{
$this->rolesRole[] = $rolesRole;
return $this;
}
/**
* Remove rolesRole
*
* @param SocialGeo\BackendBundle\Entity\Roles $rolesRole
*/
public function removeRolesRole(\SocialGeo\BackendBundle\Entity\Roles $rolesRole)
{
$this->rolesRole->removeElement($rolesRole);
}
/**
* Get rolesRole
*
* @return Doctrine\Common\Collections\Collection
*/
public function getRolesRole()
{
return $this->rolesRole->toArray();
}
public function eraseCredentials()
{
}
public function getPassword()
{
return $this->userPassword;
}
public function getRoles()
{
//return $this->groups->toArray();
return $this->getRolesRole();
}
public function getSalt()
{
return $this->salt;
}
public function isEqualTo(UserInterface $users)
{
return $this->username === $users->getUsername();
}
public function isAccountNonExpired() {
return true;
}
public function isAccountNonLocked() {
return true;
}
public function isCredentialsNonExpired() {
return true;
}
public function isEnabled() {
return $this->userActive;
}
}
私の役割エンティティ:
<?php
namespace SocialGeo\BackendBundle\Entity;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* SocialGeo\BackendBundle\Entity\Roles
*/
class Roles implements RoleInterface
{
/**
* @var integer $roleId
*/
private $roleId;
/**
* @var string $roleName
*/
private $roleName;
/**
* @ORM\Column(name="role", type="string", length=20, unique=true)
*/
private $role;
/**
* @var string $roleDescription
*/
private $roleDescription;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*/
private $usersUser;
/**
* Constructor
*/
public function __construct()
{
$this->usersUser = new ArrayCollection();
}
/**
* Get roleId
*
* @return integer
*/
public function getRoleId()
{
return $this->roleId;
}
/**
* Set roleName
*
* @param string $roleName
* @return Roles
*/
public function setRoleName($roleName)
{
$this->roleName = $roleName;
return $this;
}
/**
* Get roleName
*
* @return string
*/
public function getRoleName()
{
return $this->roleName;
}
/**
* Set roleDescription
*
* @param string $roleDescription
* @return Roles
*/
public function setRoleDescription($roleDescription)
{
$this->roleDescription = $roleDescription;
return $this;
}
/**
* Get roleDescription
*
* @return string
*/
public function getRoleDescription()
{
return $this->roleDescription;
}
/**
* Add usersUser
*
* @param SocialGeo\BackendBundle\Entity\Users $usersUser
* @return Roles
*/
public function addUsersUser(\SocialGeo\BackendBundle\Entity\Users $usersUser)
{
$this->usersUser[] = $usersUser;
return $this;
}
/**
* Remove usersUser
*
* @param SocialGeo\BackendBundle\Entity\Users $usersUser
*/
public function removeUsersUser(\SocialGeo\BackendBundle\Entity\Users $usersUser)
{
$this->usersUser->removeElement($usersUser);
}
/**
* Get usersUser
*
* @return Doctrine\Common\Collections\Collection
*/
public function getUsersUser()
{
return $this->usersUser;
}
public function getRole() {
return $this->role;
}
}
ユーザーリポジトリエンティティ:
<?php
namespace SocialGeo\BackendBundle\Entity;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* SocialGeo\BackendBundle\Entity\Roles
*/
class Roles implements RoleInterface
{
/**
* @var integer $roleId
*/
private $roleId;
/**
* @var string $roleName
*/
private $roleName;
/**
* @ORM\Column(name="role", type="string", length=20, unique=true)
*/
private $role;
/**
* @var string $roleDescription
*/
private $roleDescription;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*/
private $usersUser;
/**
* Constructor
*/
public function __construct()
{
$this->usersUser = new ArrayCollection();
}
/**
* Get roleId
*
* @return integer
*/
public function getRoleId()
{
return $this->roleId;
}
/**
* Set roleName
*
* @param string $roleName
* @return Roles
*/
public function setRoleName($roleName)
{
$this->roleName = $roleName;
return $this;
}
/**
* Get roleName
*
* @return string
*/
public function getRoleName()
{
return $this->roleName;
}
/**
* Set roleDescription
*
* @param string $roleDescription
* @return Roles
*/
public function setRoleDescription($roleDescription)
{
$this->roleDescription = $roleDescription;
return $this;
}
/**
* Get roleDescription
*
* @return string
*/
public function getRoleDescription()
{
return $this->roleDescription;
}
/**
* Add usersUser
*
* @param SocialGeo\BackendBundle\Entity\Users $usersUser
* @return Roles
*/
public function addUsersUser(\SocialGeo\BackendBundle\Entity\Users $usersUser)
{
$this->usersUser[] = $usersUser;
return $this;
}
/**
* Remove usersUser
*
* @param SocialGeo\BackendBundle\Entity\Users $usersUser
*/
public function removeUsersUser(\SocialGeo\BackendBundle\Entity\Users $usersUser)
{
$this->usersUser->removeElement($usersUser);
}
/**
* Get usersUser
*
* @return Doctrine\Common\Collections\Collection
*/
public function getUsersUser()
{
return $this->usersUser;
}
public function getRole() {
return $this->role;
}
}
そして最後のもの: security.yml:
security:
encoders:
SocialGeo\BackendBundle\Entity\Users:
algorithm: sha1
encode_as_base64: false
iterations: 1
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
providers:
users:
entity: { class: SocialGeoBackendBundle:Users }
firewalls:
admin_area:
pattern: ^/users
http_basic: ~
access_control:
- { path: ^/login, roles: ROLE_ADMIN }
問題は、アプリが毎回ログインするように要求し続けることですが、ログインできません (毎回 /users ページに移動します)。ホームはアクセス可能です。
したがって、/users に移動すると、基本的な http: がブラウザーからポップアップ表示され、資格情報を尋ねられます。資格情報を入力して Enter キーを押すと、同じブラウザーのポップアップが表示され、ログインするように求められます...
編集: evey ユーザーのデータベース内の私のソルトは: 7308e59b97f6957fb42d66f894793079 で、everyuser のパスワードは sha1 で 'pass' ハッシュされています: 9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684